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_backup=false # backup vhost config
|
||||||
vhost_dir='/etc/httpd/sites-enabled' # vhost location
|
vhost_dir='/etc/httpd/sites-enabled' # vhost location
|
||||||
log_backup=false # backup logs
|
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
|
rsync_push=false # enable push to remote server
|
||||||
push_clean=false # clean backup file after push
|
push_clean=false # clean backup file after push
|
||||||
target_host="127.0.0.1" # rsync target host
|
target_host="127.0.0.1" # rsync target host
|
||||||
|
133
main.sh
133
main.sh
@ -76,46 +76,38 @@ function logbackup {
|
|||||||
case $system in
|
case $system in
|
||||||
"rhel")
|
"rhel")
|
||||||
|
|
||||||
if [[ " ${log_to_backup[*]} " =~ " ${system} " ]];
|
if [[ " ${log_to_backup[*]} " =~ " ${system} " ]]; then
|
||||||
then
|
|
||||||
cp /var/log/syslog "$tmpdir/syslogs/"
|
cp /var/log/syslog "$tmpdir/syslogs/"
|
||||||
cp /var/log/message "$tmpdir/syslogs/"
|
cp /var/log/message "$tmpdir/syslogs/"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ " ${log_to_backup[*]} " =~ " ${fail2ban} " ]];
|
if [[ " ${log_to_backup[*]} " =~ " ${fail2ban} " ]]; then
|
||||||
then
|
|
||||||
cp /var/log/fail2ban.log "$tmpdir/syslogs/"
|
cp /var/log/fail2ban.log "$tmpdir/syslogs/"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ " ${log_to_backup[*]} " =~ " ${apache} " ]];
|
if [[ " ${log_to_backup[*]} " =~ " ${apache} " ]]; then
|
||||||
then
|
mkdir -p "$tmpdir/apachelogs"
|
||||||
mkdir -p "$tmpdir/apachelogs"
|
cp -r /var/log/httpd "$tmpdir/apachelogs"
|
||||||
cp -r /var/log/httpd "$tmpdir/apachelogs"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ " ${log_to_backup[*]} " =~ " ${nginx} " ]];
|
if [[ " ${log_to_backup[*]} " =~ " ${nginx} " ]]; then
|
||||||
then
|
mkdir -p "$tmpdir/nginxlogs"
|
||||||
mkdir -p "$tmpdir/nginxlogs"
|
cp -r /var/log/nginx "$tmpdir/nginxlogs"
|
||||||
cp -r /var/log/nginx "$tmpdir/nginxlogs"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ " ${log_to_backup[*]} " =~ " ${purge} " ]];
|
if [[ " ${log_to_backup[*]} " =~ " ${purge} " ]]; then
|
||||||
then
|
|
||||||
echo "Purging logs..." >&2
|
echo "Purging logs..." >&2
|
||||||
truncate -s 0 /var/log/syslog
|
truncate -s 0 /var/log/syslog
|
||||||
truncate -s 0 /var/log/message
|
truncate -s 0 /var/log/message
|
||||||
if [[ " ${log_to_backup[*]} " =~ " ${apache} " ]];
|
if [[ " ${log_to_backup[*]} " =~ " ${apache} " ]]; then
|
||||||
then
|
|
||||||
truncate -s 0 /var/log/httpd/*
|
truncate -s 0 /var/log/httpd/*
|
||||||
rm /var/log/httpd/*.gz
|
rm /var/log/httpd/*.gz
|
||||||
fi
|
fi
|
||||||
if [[ " ${log_to_backup[*]} " =~ " ${nginx} " ]];
|
if [[ " ${log_to_backup[*]} " =~ " ${nginx} " ]]; then
|
||||||
then
|
|
||||||
truncate -s 0 /var/log/nginx/*
|
truncate -s 0 /var/log/nginx/*
|
||||||
rm /var/log/nginx/*.gz
|
rm /var/log/nginx/*.gz
|
||||||
fi
|
fi
|
||||||
if [[ " ${log_to_backup[*]} " =~ " ${fail2ban} " ]];
|
if [[ " ${log_to_backup[*]} " =~ " ${fail2ban} " ]]; then
|
||||||
then
|
|
||||||
truncate -s 0 /var/log/fail2ban.log
|
truncate -s 0 /var/log/fail2ban.log
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -123,52 +115,101 @@ function logbackup {
|
|||||||
|
|
||||||
"ubuntu")
|
"ubuntu")
|
||||||
|
|
||||||
if [[ " ${log_to_backup[*]} " =~ " ${system} " ]];
|
if [[ " ${log_to_backup[*]} " =~ " ${fail2ban} " ]]; then
|
||||||
then
|
|
||||||
cp /var/log/syslog "$tmpdir/syslogs/"
|
|
||||||
cp /var/log/message "$tmpdir/syslogs/"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$fail2ban_log" = true ]; then
|
|
||||||
cp /var/log/fail2ban.log "$tmpdir/syslogs/"
|
cp /var/log/fail2ban.log "$tmpdir/syslogs/"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ " ${log_to_backup[*]} " =~ " ${fail2ban} " ]];
|
if [[ " ${log_to_backup[*]} " =~ " ${apache} " ]]; then
|
||||||
then
|
mkdir -p "$tmpdir/apachelogs"
|
||||||
cp /var/log/fail2ban.log "$tmpdir/syslogs/"
|
cp -r /var/log/apache2 "$tmpdir/apachelogs"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ " ${log_to_backup[*]} " =~ " ${apache} " ]];
|
if [[ " ${log_to_backup[*]} " =~ " ${nginx} " ]]; then
|
||||||
then
|
mkdir -p "$tmpdir/nginxlogs"
|
||||||
mkdir -p "$tmpdir/apachelogs"
|
cp -r /var/log/nginx "$tmpdir/nginxlogs"
|
||||||
cp -r /var/log/apache2 "$tmpdir/apachelogs"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ " ${log_to_backup[*]} " =~ " ${nginx} " ]];
|
if [[ " ${log_to_backup[*]} " =~ " ${alternatives} " ]]; then
|
||||||
then
|
mkdir -p "$tmpdir/syslogs/"
|
||||||
mkdir -p "$tmpdir/nginxlogs"
|
cp -r /var/log/alternatives.log "$tmpdir/syslogs/"
|
||||||
cp -r /var/log/nginx "$tmpdir/nginxlogs"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ " ${log_to_backup[*]} " =~ " ${purge} " ]];
|
if [[ " ${log_to_backup[*]} " =~ " ${apt} " ]]; then
|
||||||
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
|
echo "Purging logs..." >&2
|
||||||
truncate -s 0 /var/log/syslog
|
truncate -s 0 /var/log/syslog
|
||||||
truncate -s 0 /var/log/message
|
truncate -s 0 /var/log/message
|
||||||
if [[ " ${log_to_backup[*]} " =~ " ${apache} " ]];
|
if [[ " ${log_to_backup[*]} " =~ " ${apache} " ]]; then
|
||||||
then
|
|
||||||
truncate -s 0 /var/log/apache2/*
|
truncate -s 0 /var/log/apache2/*
|
||||||
rm /var/log/apache2/*.gz
|
rm /var/log/apache2/*.gz
|
||||||
fi
|
fi
|
||||||
if [[ " ${log_to_backup[*]} " =~ " ${nginx} " ]];
|
if [[ " ${log_to_backup[*]} " =~ " ${nginx} " ]]; then
|
||||||
then
|
|
||||||
truncate -s 0 /var/log/nginx/*
|
truncate -s 0 /var/log/nginx/*
|
||||||
rm /var/log/nginx/*.gz
|
rm /var/log/nginx/*.gz
|
||||||
fi
|
fi
|
||||||
if [[ " ${log_to_backup[*]} " =~ " ${fail2ban} " ]];
|
if [[ " ${log_to_backup[*]} " =~ " ${fail2ban} " ]]; then
|
||||||
then
|
|
||||||
truncate -s 0 /var/log/fail2ban.log
|
truncate -s 0 /var/log/fail2ban.log
|
||||||
fi
|
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
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
Loading…
Reference in New Issue
Block a user