WIP: Functions and log backups

This commit is contained in:
David Petric 2023-02-10 15:43:57 +01:00
parent ebee9f5ffb
commit 6ffbc54ea0
2 changed files with 76 additions and 10 deletions

View File

@ -1,12 +1,25 @@
#Backup wwwroot ?
www_backup=false
#wwwroot location
www_dir='xyz'
#Backup vhost config ?
vhost_backup=false
#Vhost location
vhost_dir='/etc/httpd/sites-enabled'
#!/bin/bash
# --------------------------------------------------------
# Please double check Your settings
# --------------------------------------------------------
www_backup=false # backup wwwroot
www_dir='xyz' # wwwroot location
vhost_backup=false # backup vhost config
vhost_dir='/etc/httpd/sites-enabled' # vhost location
log_backup=false # backup logs
log_backup_web=false # backup webapp logs
apache=false # apache log backup
nginx=false # nginx log backup
log_purge=false # purge logs after backup
#Docker
#Docker volumes
#Syslogs
#Rsync
#Rsync
#Daily cron
#Mysql dbs

55
main.sh
View File

@ -8,6 +8,7 @@ config_secured='sbackup.cfg'
if config -f "$config"; then
echo "Configuration found." >&2
else
echo "Configuration not found" >&2
exit
fi
@ -21,19 +22,71 @@ source "$config"
echo "Configuration file loaded" >&2
function makedir {
mkdir /tmp/backify-$(date +%Y%m%d_%H%M)
tmpdir='/tmp/backify-$(date +%Y%m%d_%H%M)'
}
function wwwbackup {
if [ "$www_backup" = true ] then
echo "Backing up wwwroot..." >&2
mkdir -p $tmpdir/wwwdata
cp -r $www_dir/ $tmpdir/wwwdata/
echo "Finished" >&2
fi
}
function vhostbackup {
if [ "$vhost_backup" = true ] then
echo "Backing up vhosts..." >&2
mkdir -p $tmpdir/vhosts
cp -r $vhost_dir/ $tmpdir/vhosts/
echo "Finished" >&2
fi
fi
}
function logbackup {
if [ "$log_backup" = true ] then
echo "Backing up system logs..." >&2
mkdir -p $tmpdir/syslogs
cp /var/log/syslog $tmpdir/syslogs/
cp /var/log/message $tmpdir/syslogs/
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
fi
if [ "$log_purge" = true] then
echo "Purging logs..." >&2
truncate -s 0 /var/log/syslog
truncate -s 0 /var/log/message
if [ "$apache" = true ] then
# TODO: removal for .1.2.3 logs
truncate -s 0 /var/log/httpd/*
fi
if [ "$nginx" = true ] then
# TODO: removal for .1.2.3 logs
truncate -s 0 /var/log/nginx/*
fi
fi
echo "Finished" >&2
fi
}
function runbackup {
# step 1 : create directory
makedir
# step 2 : wwwbackup
wwwbackup
# step 3 : vhostbackup
vhostbackup
# step 4: logbackup
logbackup
}
runbackup