Bug fixes / Git ignore for parsed backup.cfg

This commit is contained in:
gospodar 2023-02-10 21:44:40 +01:00
parent c4cf0729b6
commit 8f72e7ff98
3 changed files with 41 additions and 28 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
sbackup.cfg

View File

@ -1,30 +1,23 @@
#!/bin/bash
# --------------------------------------------------------
# Please double check Your settings
# --------------------------------------------------------
enabled=false #enable main function
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
fail2ban_log=false # fail2ban log backup
log_purge=false # purge logs after backup
rsync_push=false # enable push to remote server
push_clean=false # clean backup file after push
target_host="127.0.0.1" # rsync target host
target_user="backup" # rsync target user
target_key='/home/xyz/.ssh/rsync' # rsync key
docker_enabled=false # will you use docker backup
docker_images=false # backup docker images
docker_volumes=false #backup docker volumes

61
main.sh
View File

@ -5,16 +5,17 @@ echo "Backify is starting, looking for configuration file..." >&2
config='backup.cfg'
config_secured='sbackup.cfg'
if config -f "$config"; then
if [ -f "$config" ]
then
echo "Configuration found." >&2
else
echo "Configuration not found" >&2
exit
fi
if egrep -q -v '^#|^[^ ]*=[^;]*' "$config"; then
if grep -E -q -v '^#|^[^ ]*=[^;]*' "$config"; then
echo "Config file is unclean, cleaning it..." >&2
egrep '^#|^[^ ]*=[^;&]*' "$config" > "$config_secured"
grep -E '^#|^[^ ]*=[^;&]*' "$config" > "$config_secured"
config="$config_secured"
fi
@ -34,7 +35,8 @@ tmpdir="/tmp/backify-$timestamp"
}
function wwwbackup {
if [ "$www_backup" = true ] then
if [ "$www_backup" = true ]
then
echo "Backing up wwwroot..." >&2
mkdir -p $tmpdir/wwwdata
cp -r $www_dir/ $tmpdir/wwwdata/
@ -43,7 +45,8 @@ fi
}
function vhostbackup {
if [ "$vhost_backup" = true ] then
if [ "$vhost_backup" = true ]
then
echo "Backing up vhosts..." >&2
mkdir -p $tmpdir/vhosts
cp -r $vhost_dir/ $tmpdir/vhosts/
@ -52,40 +55,49 @@ fi
}
function logbackup {
if [ "$log_backup" = true ] then
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 [ "$fail2ban_log" = true ] then
if [ "$fail2ban_log" = true ]
then
cp /var/log/fail2ban.log $tmpdir/syslogs/
fi
if [ "$log_backup_web" = true] then
if [ "$apache" = true ] then
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
if [ "$nginx" = true ]
then
mkdir -p $tmpdir/nginxlogs
cp -r /var/log/nginx $tmpdir/nginxlogs
fi
fi
if [ "$log_purge" = true] then
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
if [ "$apache" = true ]
then
# TODO: removal for .1.2.3 logs
truncate -s 0 /var/log/httpd/*
fi
if [ "$nginx" = true ] then
if [ "$nginx" = true ]
then
# TODO: removal for .1.2.3 logs
truncate -s 0 /var/log/nginx/*
fi
if [ "$fail2ban_log" = true ] then
if [ "$fail2ban_log" = true ]
then
truncate -s 0 /var/log/fail2ban.log
fi
fi
@ -94,17 +106,21 @@ fi
}
function push {
if [ "rsync_push" = true ] then
if [ "rsync_push" = true ]
then
#Push - Dockerized
if [ "push_clean" = true ] then
if [ "push_clean" = true ]
then
rm /opt/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
@ -116,7 +132,8 @@ function dockerbackup {
echo "Finished" >&2
done
fi
if [ "docker_volumes" = true ] then
if [ "docker_volumes" = true ]
then
echo "Backing up Docker volumes..." >&2
for i in `docker inspect --format='{{.Name}}' $(docker ps -q) | cut -f2 -d\/`
do container_name=$i
@ -131,7 +148,8 @@ function dockerbackup {
echo "Finished" >&2
done
fi
if [ "docker_data" = true ] then
if [ "docker_data" = true ]
then
echo "Backing up container information..." >&2
for i in `docker inspect --format='{{.Name}}' $(docker ps -q) | cut -f2 -d\/`
do container_name=$i
@ -146,7 +164,8 @@ function dockerbackup {
}
function runbackup {
if [ "enabled" = true] then
if [ "enabled" = true]
then
# step 1 : create directory
makedir
# step 2 : www backup