ROOTMAIL="root@localhost"
LOCKDIR="/var/lock/backup"
LOCKFILE="$LOCKDIR/hetznerbackup"
-LOGFILE="/var/log/hetznerbackup"
+LOGFILE="/var/log/hetznerbackup.log"
SESSIONLOG=$(mktemp /var/tmp/hetznerbackup.XXXXXXXXX)
ERRSTAT=0
## Backup job for main
job_main() {
+ echo "" >> $SESSIONLOG
+ echo "Backing up main `date`" >> $SESSIONLOG
+ echo "" >> $SESSIONLOG
+
echo "Going for /etc" >> $SESSIONLOG
duplicity $BMODE $dry /etc $PROTO://$FTP_USER@$FTP_HOST/main/etc >> $SESSIONLOG 2>&1 || ERRSTAT=1
duplicity remove-all-but-n-full 5 --force $dry $PROTO://$FTP_USER@$FTP_HOST/main/etc >> $SESSIONLOG 2>&1 || ERRSTAT=1
echo "Going for /home" >> $SESSIONLOG
duplicity $BMODE $dry /home $PROTO://$FTP_USER@$FTP_HOST/main/home >> $SESSIONLOG 2>&1 || ERRSTAT=1
- duplicity remove-all-but-n-full 5 --force $dry $PROTO://$FTP_USER@$FTP_HOST/main/home >> $SESSIONLOG 2>&1 || ERRSTAT=1
+ duplicity remove-all-but-n-full 5 --force $dry $PROTO://$FTP_USER@$FTP_HOST/main/home >> $SESSIONLOG 2>&1 || ERRSTAT=1
duplicity cleanup --extra-clean --force $dry $PROTO://$FTP_USER@$FTP_HOST/main/home >> $SESSIONLOG 2>&1 || ERRSTAT=1
echo "Going for /var/www" >> $SESSIONLOG
duplicity remove-all-but-n-full 5 --force $dry $PROTO://$FTP_USER@$FTP_HOST/main/var/www >> $SESSIONLOG 2>&1 || ERRSTAT=1
duplicity cleanup --extra-clean --force $dry $PROTO://$FTP_USER@$FTP_HOST/main/var/www >> $SESSIONLOG 2>&1 || ERRSTAT=1
+ echo "Going for /var/lib/tomcat6" >> $SESSIONLOG
+ duplicity $BMODE $dry /var/lib/tomcat6 $PROTO://$FTP_USER@$FTP_HOST/main/tomcat6 >> $SESSIONLOG 2>&1 || ERRSTAT=1
+ duplicity remove-all-but-n-full 5 --force $dry $PROTO://$FTP_USER@$FTP_HOST/main/tomcat6 >> $SESSIONLOG 2>&1 || ERRSTAT=1
+ duplicity cleanup --extra-clean --force $dry $PROTO://$FTP_USER@$FTP_HOST/main/tomcat6 >> $SESSIONLOG 2>&1 || ERRSTAT=1
+
echo "Going for /var/lib/automysqlbackup" >> $SESSIONLOG
if [ -e /var/lib/automysqlbackup/backupdone ]; then
duplicity $BMODE $dry /var/lib/automysqlbackup $PROTO://$FTP_USER@$FTP_HOST/main/automysqlbackup >> $SESSIONLOG 2>&1 || ERRSTAT=1
else
echo "WARNING: It seems that the last mysql backup is still runing" >> $SESSIONLOG
echo "Skipping mysql backup - please re-schedule" >> $SESSIONLOG
+ ERSSTAT=10
fi
echo "" >> $SESSIONLOG
}
-## Append the session log to the main logfile and remove it
-clean_log() {
+# Append the session log to the main logfile and remove log and lock
+cleanup() {
+ ENDDATE=$(date)
+ if [ $ERRSTAT -eq 0 ]; then
+ echo "Backup finished successfully $ENDDATE" >> $SESSIONLOG
+ else
+ echo "ERROR Backup FAILED $ENDDATE" >> $SESSIONLOG
+ cat $SESSIONLOG|mail -s "ERROR Backup FAILED $ENDDATE with ERRCODE $ERRSTAT" $ROOTMAIL
+ fi
cat $SESSIONLOG >> $LOGFILE
- rm $SESSIONLOG
+ rm $SESSIONLOG $LOCKFILE
}
### check for other runing instances of this script
exit 5
else
if [ ! -d $LOCKDIR ]; then
- mkdir -m 700 $LOCKDIR
+ mkdir -m 700 $LOCKDIR
fi
touch $LOCKFILE
fi
-### Starting
- echo "" >> $SESSIONLOG
- echo "Starting Backup `date`" >> $SESSIONLOG
- echo "" >> $SESSIONLOG
-
### Set the duplicity backup mode we would like to use
if [[ $(LANG=C; date +%A) =~ Sunday ]]; then
echo "Runing in full mode" >> $SESSIONLOG
### Start the backup jobs
job_main
-
### Cleanup and reporting
-ENDDATE=$(date)
-if [ $ERRSTAT -eq 0 ]; then
- echo "Backup finished successfully $ENDDATE" >> $SESSIONLOG
- clean_log
- rm $LOCKFILE
- exit 0
-else
- echo "ERROR Backup FAILED $ENDDATE" >> $SESSIONLOG
- cat $SESSIONLOG|mail -s "ERROR Backup FAILED $ENDDATE" $ROOTMAIL
- clean_log
- exit 1
-fi
+cleanup
+exit $ERRSTAT