For more than a year I have been running my own virtual host (thanks to Tom for helping with the setup of the mail system). Before I had almost no skills regarding Linux administration. Meanwhile I’m kindof able to maintain it and add this and that. For a while a few tasks have been pending

  • Frequent logging file reports
  • Monthly backup
  • Moving backup files to some external storage service

Due to my pretty constrained time budget only now I was able to spend some hours on getting some task done.

For Frequent logging file reports I added logwatch to my system, customized it in /etc/logwatch/conf/logwatch.conf.

1
2
3
4
5
6
7
8
9
10
# Default person to mail reports to.  Can be a local account or a
# complete email address.
MailTo = recipient@domain
# Default person to mail reports from.  Can be a local account or a
# complete email address.
MailFrom = Logwatch

# If set to 'Yes', the report will be sent to stdout instead of being
# mailed to above person.
Print = No

I added logwatch to my daily cron jobs in /etc/cron.daily/logwatch

1
2
test -x /usr/share/logwatch/scripts/logwatch.pl || exit 0
/usr/share/logwatch/scripts/logwatch.pl

I added a /etc/cron.monthly/backup script for performing monthly backups of important system files

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
outputFolder=/var/tmp/backup
now=`date +%Y%m%d%H%M`
hostname=`hostname`
outputFolder=$outputFolder/$hostname/$now

if [ -d $outputFolder ]
then
        echo "Backup has alread run on '$hostname'  for '$now'"
        exit 1
else
        mkdir --parents --verbose $outputFolder
fi

echo backup...
options=-cvvz
tar $options --file=$outputFolder/backup.tar.gz --exclude=/var/cache/* --exclude=/var/spool/* --exclude=/var/lock/* --exclude=/var/run/* --exclude=/var/tmp/* --exclude=/var/log/* /var /etc /home 1>$outputFolder/backup.log

echo "Backup for $hostname ready at $outputFolder/backup.tar.gz" | mail -s "Backup completed for $hostname `date`" recipient@domain

Comments