#!/bin/sh

# This is Jeremy's script to run rsback from crontab.  
# This script is needed to make sure the three types of backup jobs
# (hourly, daily, and weekly) run in the correct order

# This script sould be run every four hours from cron.
# Here's an example cron entry.  For this script to work, it must be run
# at MIDNIGHT (hour 0) each day, the minute doesn't matter though.

# (run every four hours including at midnight)
#
# 1 */4 * * *      /usr/local/sbin/run-rsback

RSBACK=/usr/local/sbin/rsback
CONFDIR=/usr/local/etc
CONFS="rsback-homes.conf rsback-imap.conf"

HOUR=`date +%k`
DAYOWEEK=`date +%w`

#repeat for all the various configurations

for RSCONF in $CONFS
do

# we always run the "hourly" configuration
$RSBACK -c $CONFDIR/$RSCONF hourly  || exit 1

# if it's midnight, run the daily configuration after hourly finishes
if [ $HOUR = 0 ]
then
	$RSBACK -c $CONFDIR/$RSCONF daily || exit 1

	# if it's Sunday, run the weekly after daily finishes
	if [ $DAYOWEEK = 0 ]
	then
		$RSBACK -c $CONFDIR/$RSCONF weekly || exit 1
	fi
fi

#end loop
done

