Bug fixes / Git ignore for parsed backup.cfg

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

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