Array for logs implementation

This commit is contained in:
David Petric
2023-02-13 15:06:07 +01:00
parent 629e3c1631
commit bc0480689d
3 changed files with 68 additions and 52 deletions

108
main.sh
View File

@@ -46,15 +46,15 @@ function system {
function makedir {
timestamp=$(date +%Y%m%d_%H%M)
mkdir -p $backup_path/backify-$timestamp
mkdir -p "$backup_path/backify-$timestamp"
tmpdir="$backup_path/backify-$timestamp"
}
function wwwbackup {
if [ "$www_backup" = true ]; then
echo "Backing up wwwroot..." >&2
mkdir -p $tmpdir/wwwdata
cp -r $www_dir/ $tmpdir/wwwdata/
mkdir -p "$tmpdir/wwwdata"
cp -r "$www_dir/" "$tmpdir/wwwdata/"
echo "Finished" >&2
fi
}
@@ -62,8 +62,8 @@ function wwwbackup {
function vhostbackup {
if [ "$vhost_backup" = true ]; then
echo "Backing up vhosts..." >&2
mkdir -p $tmpdir/vhosts
cp -r $vhost_dir/ $tmpdir/vhosts/
mkdir -p "$tmpdir/vhosts"
cp -r "$vhost_dir/" "$tmpdir/vhosts/"
echo "Finished" >&2
fi
}
@@ -71,78 +71,102 @@ function vhostbackup {
function logbackup {
if [ "$log_backup" = true ]; then
echo "Backing up system logs..." >&2
mkdir -p $tmpdir/syslogs
mkdir -p "$tmpdir/syslogs"
case $system in
"rhel")
cp /var/log/syslog $tmpdir/syslogs/
cp /var/log/message $tmpdir/syslogs/
if [ "$fail2ban_log" = true ]; then
cp /var/log/fail2ban.log $tmpdir/syslogs/
if [[ " ${log_to_backup[*]} " =~ " ${system} " ]];
then
cp /var/log/syslog "$tmpdir/syslogs/"
cp /var/log/message "$tmpdir/syslogs/"
fi
if [ "$log_backup_web" = true ]; then
if [ "$apache" = true ]; then
mkdir -p $tmpdir/apachelogs
cp -r /var/log/httpd $tmpdir/apachelogs
fi
if [ "$nginx" = true ]; then
mkdir -p $tmpdir/nginxlogs
cp -r /var/log/nginx $tmpdir/nginxlogs
fi
if [[ " ${log_to_backup[*]} " =~ " ${fail2ban} " ]];
then
cp /var/log/fail2ban.log "$tmpdir/syslogs/"
fi
if [ "$log_purge" = true ]; then
if [[ " ${log_to_backup[*]} " =~ " ${apache} " ]];
then
mkdir -p "$tmpdir/apachelogs"
cp -r /var/log/httpd "$tmpdir/apachelogs"
fi
if [[ " ${log_to_backup[*]} " =~ " ${nginx} " ]];
then
mkdir -p "$tmpdir/nginxlogs"
cp -r /var/log/nginx "$tmpdir/nginxlogs"
fi
if [[ " ${log_to_backup[*]} " =~ " ${purge} " ]];
then
echo "Purging logs..." >&2
truncate -s 0 /var/log/syslog
truncate -s 0 /var/log/message
if [ "$apache" = true ]; then
if [[ " ${log_to_backup[*]} " =~ " ${apache} " ]];
then
truncate -s 0 /var/log/httpd/*
rm /var/log/httpd/*.gz
fi
if [ "$nginx" = true ]; then
if [[ " ${log_to_backup[*]} " =~ " ${nginx} " ]];
then
truncate -s 0 /var/log/nginx/*
rm /var/log/nginx/*.gz
fi
if [ "$fail2ban_log" = true ]; then
if [[ " ${log_to_backup[*]} " =~ " ${fail2ban} " ]];
then
truncate -s 0 /var/log/fail2ban.log
fi
fi
;;
"ubuntu")
cp /var/log/syslog $tmpdir/syslogs/
cp /var/log/message $tmpdir/syslogs/
if [[ " ${log_to_backup[*]} " =~ " ${system} " ]];
then
cp /var/log/syslog "$tmpdir/syslogs/"
cp /var/log/message "$tmpdir/syslogs/"
fi
if [ "$fail2ban_log" = true ]; then
cp /var/log/fail2ban.log $tmpdir/syslogs/
cp /var/log/fail2ban.log "$tmpdir/syslogs/"
fi
if [ "$log_backup_web" = true ]; then
if [ "$apache" = true ]; then
mkdir -p $tmpdir/apachelogs
cp -r /var/log/apache2 $tmpdir/apachelogs
fi
if [ "$nginx" = true ]; then
mkdir -p $tmpdir/nginxlogs
cp -r /var/log/nginx $tmpdir/nginxlogs
fi
if [[ " ${log_to_backup[*]} " =~ " ${fail2ban} " ]];
then
cp /var/log/fail2ban.log "$tmpdir/syslogs/"
fi
if [ "$log_purge" = true ]; then
if [[ " ${log_to_backup[*]} " =~ " ${apache} " ]];
then
mkdir -p "$tmpdir/apachelogs"
cp -r /var/log/apache2 "$tmpdir/apachelogs"
fi
if [[ " ${log_to_backup[*]} " =~ " ${nginx} " ]];
then
mkdir -p "$tmpdir/nginxlogs"
cp -r /var/log/nginx "$tmpdir/nginxlogs"
fi
if [[ " ${log_to_backup[*]} " =~ " ${purge} " ]];
then
echo "Purging logs..." >&2
truncate -s 0 /var/log/syslog
truncate -s 0 /var/log/message
if [ "$apache" = true ]; then
if [[ " ${log_to_backup[*]} " =~ " ${apache} " ]];
then
truncate -s 0 /var/log/apache2/*
rm /var/log/apache2/*.gz
fi
if [ "$nginx" = true ]; then
if [[ " ${log_to_backup[*]} " =~ " ${nginx} " ]];
then
truncate -s 0 /var/log/nginx/*
rm /var/log/nginx/*.gz
fi
if [ "$fail2ban_log" = true ]; then
if [[ " ${log_to_backup[*]} " =~ " ${fail2ban} " ]];
then
truncate -s 0 /var/log/fail2ban.log
fi
fi
@@ -157,14 +181,14 @@ function push {
rsync -avz -e "ssh -i $target_key" $backup_path/backify-$timestamp.tar.gz $target_user@$target_host:$target_dir
if [ "$push_clean" = true ]; then
echo "Removing archive..." >&2
rm $backup_path/backify-$timestamp.tar.gz
rm "$backup_path/backify-$timestamp.tar.gz"
fi
fi
}
function dockerbackup {
if [ "$docker_enabled" = true]; then
if [ "$docker_images" = true]; then
if [ "$docker_enabled" = true ]; then
if [ "$docker_images" = true ]; then
echo "Backing up Docker images..." >&2
for i in $(docker inspect --format='{{.Name}}' $(docker ps -q) | cut -f2 -d\/); do
container_name=$i