diff --git a/main.sh b/main.sh index f787d7d..1177e50 100644 --- a/main.sh +++ b/main.sh @@ -1,5 +1,6 @@ #! /bin/bash +function init { echo "Backify is starting, looking for configuration file..." >&2 config='backup.cfg' @@ -27,6 +28,22 @@ if [ "$EUID" -ne 0 ] then echo "Please run as root" exit fi +} + +function system { + +if [ -f /etc/redhat-release ] +then + system='rhel' +fi + +if [ -f /etc/lsb-release ] +then + system='ubuntu' +fi + +echo "Discovered $system based OS..." >&2 +} function makedir { timestamp=$(date +%Y%m%d_%H%M) @@ -54,7 +71,7 @@ then fi } -function logbackup { +function logbackupcentos { if [ "$log_backup" = true ] then echo "Backing up system logs..." >&2 @@ -88,13 +105,64 @@ then truncate -s 0 /var/log/message if [ "$apache" = true ] then - # TODO: removal for .1.2.3 logs truncate -s 0 /var/log/httpd/* + rm /var/log/httpd/*.gz fi if [ "$nginx" = true ] then - # TODO: removal for .1.2.3 logs 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 + 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 ] + then + mkdir -p $tmpdir/apachelogs + cp -r /var/log/apache2 $tmpdir/apachelogs + fi + if [ "$nginx" = true ] + then + mkdir -p $tmpdir/nginxlogs + cp -r /var/log/nginx $tmpdir/nginxlogs + 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 ] + then + truncate -s 0 /var/log/apache2/* + rm /var/log/apache2/*.gz + fi + if [ "$nginx" = true ] + then + truncate -s 0 /var/log/nginx/* + rm /var/log/nginx/*.gz fi if [ "$fail2ban_log" = true ] then @@ -164,6 +232,10 @@ function dockerbackup { } function runbackup { + # init, config check + init + # run system detection + system if [ "$enabled" = true ] then # step 1 : create directory @@ -173,7 +245,14 @@ function runbackup { # step 3 : vhost backup vhostbackup # step 4: log backup - logbackup + if [ $system = "rhel" ] + then + logbackuprhel + fi + if [ $system = "ubuntu" ] + then + logbackupubuntu + fi # step 5: docker backup dockerbackup # archive data