#!/bin/sh

. /etc/default/rsnapshot
test "$ENABLE_CRON" = yes || exit

# 86400 seconds in a day, retry every 10 minutes for half a day
until=`expr $(date +%s) + 40000`
while [ $(date +%s) -lt $until ]; do
    test -d "$BACKUP_DISK" && break
    sleep 600
done

# See ionice(1)
if [ -x /usr/bin/ionice ] &&
    /usr/bin/ionice -c3 true 2>/dev/null; then
    IONICE="/usr/bin/ionice -c3"
fi

test -d "$BACKUP_DISK" && \
	nice -n 20 $IONICE /usr/bin/rsnapshot daily
