advertisement

Article:
  Automated Backups on Tiger Using rsync
Subject:   rsync backup script - now Incremental with little storage impact
Date:   2006-12-04 14:25:36
From:   Inspector71
Response to: rsync backup script - now Incremental with little storage impact

OK, so I think the last script will work OK if you are only backing up stuff from within your home dir, but I decided to convert my script to a shell script so I could run it as root from crontab.


I have also updated the rsync options a bit to preserve permissions and access dates. The cpio command needs a little work as it seems to change perms on the files it 'copies' (or relinks to).


Anyway, here is the shell script (saved in /etc/backup.sh, called through crontab):



echo ================================ rsync Backup script ================================= >>/var/log/rsync.log
date >>/var/log/rsync.log


if [ -d /Volumes/Backup ]
then
echo ==Mounting Backup Disk: >>/var/log/rsync.log
diskutil mountDisk disk1s2
if [ -d /Volumes/Backup ]
then
echo : Backup Disk Mounted >>/var/log/rsync.log
else
echo : Could Not Mount Backup Disk - Exiting =============!!!============= >>/var/log/rsync.log
exit 2
fi
fi


echo ==Rotating Backup Directories== >>/var/log/rsync.log
rm -rf /Volumes/Backup/09
mv /Volumes/Backup/08 /Volumes/Backup/09
mv /Volumes/Backup/07 /Volumes/Backup/08
mv /Volumes/Backup/06 /Volumes/Backup/07
mv /Volumes/Backup/05 /Volumes/Backup/06
mv /Volumes/Backup/04 /Volumes/Backup/05
mv /Volumes/Backup/03 /Volumes/Backup/04
mv /Volumes/Backup/02 /Volumes/Backup/03
cd /Volumes/Backup/01 && find . -print | cpio -pdla /Volumes/Backup/02


echo ==Directories Successfully Rotated== >>/var/log/rsync.log


echo ==start rsync logging== >>/var/log/rsync.log
rsync -aEp --progress --delete-after --exclude=Volumes/ --exclude=Downloads/ --exclude=.Trashes --exclude=/dev --exclude=/tmp --exclude=/private /Volumes/Backup/01 >>/var/log/rsync.log || echo -n
echo =rsync Backup Ended== >>/var/log/rsync.log


sleep 2m


diskutil unmount disk1s2
echo =====Backup Complete===== >>/var/log/rsync.log


One problem I am having is that the HDD won't unmount afterwards; I think a process must be hogging it. If anyone can clean this up a bit the help would be appreciated :)


Cheers


Marcel