#!/bin/bash # EvoBackup cronjob. . /etc/evobackup/conf.d/cron.cf # Verify if an EvoBackup is already launched, if true, kill it. if [ -e $PIDFILE ]; then # Killing the childs of evobackup. for pid in $(ps h --ppid $(cat $PIDFILE) -o pid | tr -s '\n' ' '); do kill -9 $pid; done # Then kill the main PID. kill -9 $(cat $PIDFILE) echo "$0 is running (PID $(cat $PIDFILE)). Process killed." >&2 fi echo "$$" > $PIDFILE trap "rm -f $PIDFILE" EXIT INT # Executes tasks to do before rsync. run-parts /etc/evobackup/actions.d/ hostname=$(hostname -f) start=$(date --rfc-3339=seconds) date=$(date +%Y-%m-%d) tmplog=$(mktemp --tmpdir=/tmp evobackup.XXX) args="-avzh --stats --force --ignore-errors --partial "\ "--include-from=/etc/evobackup/conf.d/include.cf "\ "--delete --delete-excluded" dst="rsync://${RSYNC_USERNAME}@${BACKUPSERVER}/${RSYNC_PATH}" # Is there a current version? If no create it. rsync --list-only ${dst}/current >/dev/null 2>&1 status=$? if [ "$status" != 0 ]; then # First backup. rsync $args / ${dst}/current > $tmplog else # Backups with incrementials. rsync $args --link-dest=/current/ / ${dst}/${date} > $tmplog fi status=$? # Keep the last 30 lines & clean temporary log. tail -30 $tmplog >> $LOG && rm $tmplog stop=$(date --rfc-3339=seconds) echo "EvoBackup started at $start." >> $LOG echo "EvoBackup finished at $stop." >> $LOG # Send a report # Did rsync sucessfully finished? if [ "$status" != 0 ]; then tail -30 $LOG \ | mailx -s "[warn] EvoBackup for $hostname did not finish correctly." \ $MAIL_TO else tail -30 $LOG \ | mailx -s "[info] EvoBackup report for $hostname" $MAIL_TO fi