Log backup refactoring

This commit is contained in:
gospodar 2023-02-11 16:21:46 +01:00
parent 5183b9bc7d
commit 0478ce746a
2 changed files with 63 additions and 68 deletions

View File

@ -47,5 +47,4 @@ To-Do List
- [ ] Rsync implementation via shell
- [ ] Rsync implementation via Docker
- [ ] Cron scheduler
- [ ] PostgreSQL backups
- [ ] Cover more system logs
- [ ] Refactor system logs

128
main.sh
View File

@ -4,7 +4,7 @@ function init {
echo "Backify is starting, looking for configuration file..." >&2
config='backup.cfg'
config_secured='sbackup.cfg'
secured_config='sbackup.cfg'
if [ ! -f "$config" ]
then
@ -15,8 +15,8 @@ fi
if grep -E -q -v '^#|^[^ ]*=[^;]*' "$config"; then
echo "Config file is unclean, cleaning it..." >&2
grep -E '^#|^[^ ]*=[^;&]*' "$config" > "$config_secured"
config="$config_secured"
grep -E '^#|^[^ ]*=[^;&]*' "$config" > "$secured_config"
config="$secured_config"
fi
source "$config"
@ -73,106 +73,102 @@ then
fi
}
function logbackupcentos {
if [ "$log_backup" = true ]
then
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 [ "$fail2ban_log" = true ]
then
cp /var/log/fail2ban.log $tmpdir/syslogs/
fi
case $system in
"rhel")
cp /var/log/syslog $tmpdir/syslogs/
cp /var/log/message $tmpdir/syslogs/
if [ "$log_backup_web" = true]
then
if [ "$apache" = true ]
if [ "$fail2ban_log" = true ]
then
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/httpd $tmpdir/apachelogs
fi
if [ "$nginx" = true ]
then
fi
if [ "$nginx" = true ]
then
mkdir -p $tmpdir/nginxlogs
cp -r /var/log/nginx $tmpdir/nginxlogs
fi
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 ]
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
truncate -s 0 /var/log/httpd/*
rm /var/log/httpd/*.gz
fi
if [ "$nginx" = true ]
then
fi
if [ "$nginx" = true ]
then
truncate -s 0 /var/log/nginx/*
rm /var/log/nginx/*.gz
fi
if [ "$fail2ban_log" = true ]
then
truncate -s 0 /var/log/fail2ban.log
fi
fi
;;
"ubuntu")
cp /var/log/syslog $tmpdir/syslogs/
cp /var/log/message $tmpdir/syslogs/
if [ "$fail2ban_log" = true ]
then
truncate -s 0 /var/log/fail2ban.log
cp /var/log/fail2ban.log $tmpdir/syslogs/
fi
fi
echo "Finished" >&2
fi
}
function logbackupubuntu {
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
cp /var/log/fail2ban.log $tmpdir/syslogs/
fi
if [ "$log_backup_web" = true]
then
if [ "$apache" = true ]
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
fi
if [ "$nginx" = true ]
then
mkdir -p $tmpdir/nginxlogs
cp -r /var/log/nginx $tmpdir/nginxlogs
fi
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 ]
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
truncate -s 0 /var/log/apache2/*
rm /var/log/apache2/*.gz
fi
if [ "$nginx" = true ]
then
fi
if [ "$nginx" = true ]
then
truncate -s 0 /var/log/nginx/*
rm /var/log/nginx/*.gz
fi
fi
if [ "$fail2ban_log" = true ]
then
truncate -s 0 /var/log/fail2ban.log
fi
fi
echo "Finished" >&2
fi
fi
}
function push {