2014-01-30 17:00:27 +01:00
|
|
|
#!/bin/bash
|
2013-08-03 22:53:04 +02:00
|
|
|
# EvoBackup cronjob.
|
|
|
|
|
|
|
|
. /etc/evobackup/conf.d/cron.cf
|
|
|
|
|
|
|
|
# Verify if an EvoBackup is already launched, if true, kill it.
|
|
|
|
if [ -e $PIDFILE ]; then
|
2013-08-05 15:46:18 +02:00
|
|
|
# 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)
|
2013-08-03 22:53:04 +02:00
|
|
|
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)
|
2014-04-02 18:34:58 +02:00
|
|
|
date=$(date +%Y-%m-%d)
|
2013-08-03 22:53:04 +02:00
|
|
|
tmplog=$(mktemp --tmpdir=/tmp evobackup.XXX)
|
|
|
|
|
2014-04-02 18:34:58 +02:00
|
|
|
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
|
2013-08-03 23:14:54 +02:00
|
|
|
status=$?
|
2013-08-03 22:53:04 +02:00
|
|
|
|
2014-02-02 20:24:26 +01:00
|
|
|
# Keep the last 30 lines & clean temporary log.
|
2014-01-30 16:03:58 +01:00
|
|
|
tail -30 $tmplog >> $LOG && rm $tmplog
|
2013-08-03 22:53:04 +02:00
|
|
|
|
|
|
|
stop=$(date --rfc-3339=seconds)
|
2014-02-14 16:39:52 +01:00
|
|
|
echo "EvoBackup started at $start." >> $LOG
|
|
|
|
echo "EvoBackup finished at $stop." >> $LOG
|
2013-08-03 22:53:04 +02:00
|
|
|
|
|
|
|
# Send a report
|
|
|
|
# Did rsync sucessfully finished?
|
|
|
|
if [ "$status" != 0 ]; then
|
2014-01-30 16:03:58 +01:00
|
|
|
tail -30 $LOG \
|
2013-08-03 22:53:04 +02:00
|
|
|
| mailx -s "[warn] EvoBackup for $hostname did not finish correctly." \
|
|
|
|
$MAIL_TO
|
|
|
|
else
|
2014-01-30 16:03:58 +01:00
|
|
|
tail -30 $LOG \
|
2013-08-03 22:53:04 +02:00
|
|
|
| mailx -s "[info] EvoBackup report for $hostname" $MAIL_TO
|
2014-04-02 18:34:58 +02:00
|
|
|
fi
|