#!/bin/sh
#
#Snapshotit backup script
#
#V1.0
#Haim Lichaa
#
#
. /etc/snapshotit.conf
date=`date "+%Y-%m-%d_%H-%M"`
day=`date "+%d"`
hour=`date "+%H"`
backtype=back
if [ $day -eq 7 ] && [ $hour -lt 4 ];then
backtype=monthly
fi
for iDATASRC in $DATASRC;do
[ ! -d $iDATASRC ] && echo "[$date] Skipping $iDATASRC: Not available" && continue
echo "[$date] Starting Backup for $iDATASRC"
#Destination Snapshot folder
SNAPDST=$BASEDIR/$backtype-$date/
#Excludes (add to file)
EXCLUDES="/etc/snapshotit.exclude"
#Current Snapshot backup
CURRDATA=$BASEDIR/_current
[ ! -x $CURRDATA ] && ln -s . $CURRDATA
cd $BASEDIR
rsync -aHltv --exclude-from=$EXCLUDES --link-dest=$CURRDATA $DATASRC $SNAPDST/ >$BASEDIR/$backtype-$date.log 2>&1
echo "[$date] Backup complete for $iDATASRC"
done
#File cleanup
rm -f $CURRDATA
ln -s $backtype-$date $CURRDATA
touch $backtype-$date
date=`date "+%Y-%m-%d_%H-%M"`
echo "[$date] starting file cleanup"
### Keep this many dailies
find $BASEDIR -maxdepth 1 -type d -name "back-*" -ctime +$AGE -exec rm -r {} \;
### Delete old logfiles
find $BASEDIR -maxdepth 1 -type f -name "back-*.log" -ctime +$AGE -exec rm -r {} \;
### Keep this many monthlies
find $BASEDIR -maxdepth 1 -type d -name "monthly-*" -ctime +$mAGE -exec rm -r {} \;
date=`date "+%Y-%m-%d_%H-%M"`
echo "[$date] Cleanup complete"
Tuesday, January 1, 2013
snapshotit.sh backup script
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment