Widen the support for system logs on Debian systems
This commit is contained in:
parent
bc0480689d
commit
225a9d4db4
@ -9,7 +9,8 @@ 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_to_backup=("apache" "nginx" "fail2ban" "system") # logs to backup, options: apache,nginx,fail2ban)
|
||||
log_to_backup=("apache" "nginx" "fail2ban" "alternatives" "apt" "auth" "dmesg" "dpkg" "letsencrypt" "php" "syslog" )
|
||||
# logs to backup, options: apache, nginx, fail2ban, alternatives, apt, auth, dmesg, dpkg, letsencrypt, php, syslog)
|
||||
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
|
||||
|
133
main.sh
133
main.sh
@ -76,46 +76,38 @@ function logbackup {
|
||||
case $system in
|
||||
"rhel")
|
||||
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${system} " ]];
|
||||
then
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${system} " ]]; then
|
||||
cp /var/log/syslog "$tmpdir/syslogs/"
|
||||
cp /var/log/message "$tmpdir/syslogs/"
|
||||
fi
|
||||
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${fail2ban} " ]];
|
||||
then
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${fail2ban} " ]]; then
|
||||
cp /var/log/fail2ban.log "$tmpdir/syslogs/"
|
||||
fi
|
||||
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${apache} " ]];
|
||||
then
|
||||
mkdir -p "$tmpdir/apachelogs"
|
||||
cp -r /var/log/httpd "$tmpdir/apachelogs"
|
||||
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"
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${nginx} " ]]; then
|
||||
mkdir -p "$tmpdir/nginxlogs"
|
||||
cp -r /var/log/nginx "$tmpdir/nginxlogs"
|
||||
fi
|
||||
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${purge} " ]];
|
||||
then
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${purge} " ]]; then
|
||||
echo "Purging logs..." >&2
|
||||
truncate -s 0 /var/log/syslog
|
||||
truncate -s 0 /var/log/message
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${apache} " ]];
|
||||
then
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${apache} " ]]; then
|
||||
truncate -s 0 /var/log/httpd/*
|
||||
rm /var/log/httpd/*.gz
|
||||
fi
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${nginx} " ]];
|
||||
then
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${nginx} " ]]; then
|
||||
truncate -s 0 /var/log/nginx/*
|
||||
rm /var/log/nginx/*.gz
|
||||
fi
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${fail2ban} " ]];
|
||||
then
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${fail2ban} " ]]; then
|
||||
truncate -s 0 /var/log/fail2ban.log
|
||||
fi
|
||||
fi
|
||||
@ -123,52 +115,101 @@ function logbackup {
|
||||
|
||||
"ubuntu")
|
||||
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${system} " ]];
|
||||
then
|
||||
cp /var/log/syslog "$tmpdir/syslogs/"
|
||||
cp /var/log/message "$tmpdir/syslogs/"
|
||||
fi
|
||||
|
||||
if [ "$fail2ban_log" = true ]; then
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${fail2ban} " ]]; then
|
||||
cp /var/log/fail2ban.log "$tmpdir/syslogs/"
|
||||
fi
|
||||
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${fail2ban} " ]];
|
||||
then
|
||||
cp /var/log/fail2ban.log "$tmpdir/syslogs/"
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${apache} " ]]; then
|
||||
mkdir -p "$tmpdir/apachelogs"
|
||||
cp -r /var/log/apache2 "$tmpdir/apachelogs"
|
||||
fi
|
||||
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${apache} " ]];
|
||||
then
|
||||
mkdir -p "$tmpdir/apachelogs"
|
||||
cp -r /var/log/apache2 "$tmpdir/apachelogs"
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${nginx} " ]]; then
|
||||
mkdir -p "$tmpdir/nginxlogs"
|
||||
cp -r /var/log/nginx "$tmpdir/nginxlogs"
|
||||
fi
|
||||
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${nginx} " ]];
|
||||
then
|
||||
mkdir -p "$tmpdir/nginxlogs"
|
||||
cp -r /var/log/nginx "$tmpdir/nginxlogs"
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${alternatives} " ]]; then
|
||||
mkdir -p "$tmpdir/syslogs/"
|
||||
cp -r /var/log/alternatives.log "$tmpdir/syslogs/"
|
||||
fi
|
||||
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${purge} " ]];
|
||||
then
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${apt} " ]]; then
|
||||
mkdir -p "$tmpdir/syslogs/"
|
||||
mkdir -p "$tmpdir/syslogs/apt"
|
||||
cp -r /var/log/apt/* "$tmpdir/syslogs/apt/"
|
||||
fi
|
||||
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${auth} " ]]; then
|
||||
mkdir -p "$tmpdir/syslogs/"
|
||||
cp -r /var/log/auth.log "$tmpdir/syslogs/"
|
||||
fi
|
||||
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${dmesg} " ]]; then
|
||||
mkdir -p "$tmpdir/syslogs/"
|
||||
cp -r /var/log/dmesg "$tmpdir/syslogs/"
|
||||
fi
|
||||
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${dpkg} " ]]; then
|
||||
mkdir -p "$tmpdir/syslogs/"
|
||||
cp -r /var/log/dpkg.log "$tmpdir/syslogs/"
|
||||
fi
|
||||
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${letsencrypt} " ]]; then
|
||||
mkdir -p "$tmpdir/syslogs/"
|
||||
mkdir -p "$tmpdir/syslogs/letsencrypt"
|
||||
cp -r /var/log/letsencrypt/* "$tmpdir/syslogs/letsencrypt/"
|
||||
fi
|
||||
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${php} " ]]; then
|
||||
mkdir -p "$tmpdir/syslogs/"
|
||||
cp -r /var/log/php*.log "$tmpdir/syslogs/"
|
||||
fi
|
||||
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${syslog} " ]]; then
|
||||
mkdir -p "$tmpdir/syslogs/"
|
||||
cp -r /var/log/syslog "$tmpdir/syslogs/"
|
||||
fi
|
||||
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${purge} " ]]; then
|
||||
echo "Purging logs..." >&2
|
||||
truncate -s 0 /var/log/syslog
|
||||
truncate -s 0 /var/log/message
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${apache} " ]];
|
||||
then
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${apache} " ]]; then
|
||||
truncate -s 0 /var/log/apache2/*
|
||||
rm /var/log/apache2/*.gz
|
||||
fi
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${nginx} " ]];
|
||||
then
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${nginx} " ]]; then
|
||||
truncate -s 0 /var/log/nginx/*
|
||||
rm /var/log/nginx/*.gz
|
||||
fi
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${fail2ban} " ]];
|
||||
then
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${fail2ban} " ]]; then
|
||||
truncate -s 0 /var/log/fail2ban.log
|
||||
fi
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${alternatives} " ]]; then
|
||||
truncate -s 0 /var/log/alternatives.log
|
||||
fi
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${apt} " ]]; then
|
||||
truncate -s 0 /var/log/apt/*
|
||||
fi
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${auth} " ]]; then
|
||||
truncate -s 0 /var/log/auth.log
|
||||
fi
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${dmesg} " ]]; then
|
||||
truncate -s 0 /var/log/dmesg
|
||||
fi
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${dpkg} " ]]; then
|
||||
truncate -s 0 /var/log/dpkg.log
|
||||
fi
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${letsencrypt} " ]]; then
|
||||
truncate -s 0 /var/log/letsencrypt/*
|
||||
fi
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${php} " ]]; then
|
||||
truncate -s 0 /var/log/php*.log
|
||||
fi
|
||||
if [[ " ${log_to_backup[*]} " =~ " ${syslog} " ]]; then
|
||||
truncate -s 0 /var/log/syslog
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
Loading…
Reference in New Issue
Block a user