Friday, February 17, 2006

mac backups

http://www.digital501.com/2006021110/mac-backup-osx/
some info on unix commands that are available on the mac to automate backups

--------

"My method is a terminal job that runs at login, which is a simple saved rsync command. I just back up my user folder, but in principle this could be extended to the whole drive (I assume). Rsync has the advantage that it only moves those files which have changed - usually the script is done in a couple minutes.

The command takes the form of

sudo rsync -rlptv –delete /Volumes/(internal hard drive)/Users/ /Volumes/(external hard drive)/Users/

I just save that command as a .term file and add it to my login items."

---------------


Another alternative is to use rsync (or rsyncX) to create a clone without copying every file, every time.

Also, instead of using cron, an daily backup command can simply be added to /etc/daily.local. This will include “custom” commands in the pre-existing scheduled process. Results will be written to /var/log/daily.out.

----------

Try this :


#!/bin/sh

echo "################################################################"
echo "### Server backup"
echo "### `date`"
echo " "

if [ -d "/Volumes/Mac OS X 1" ] ; then
echo "!!! Error : Something went wrong the last time"
echo "### "
echo "### `date`"
echo "### Backup failed"
echo "################################################################"
echo " "
exit 1
fi

if [ -d "/Volumes/Sauvegarde" ] ; then
echo "### destination volume /Volumes/Sauvegarde found"
else
echo "!!! Error : Destination volume absent"
echo "### "
echo "### `date`"
echo "### Backup failed"
echo "################################################################"
echo " "
exit 1
fi

/usr/sbin/asr -erase -noprompt -source /Volumes/Mac\ OS\ X -target /Volumes/Sauvegarde

/usr/sbin/diskutil rename /Volumes/Mac\ OS\ X\ 1 Sauvegarde

echo "### `date`"
echo "### End of backup"
echo "################################################################"
echo " "

You have to rename the disk at the end, because asr does a plain clone, including the volume name.

The check for Mac OS X 1 is because one day something went wrong in the middle of the backup, and the machine rebooted. As there were two Volumes named Mac OS X , one of them was labelled Mac OS X 1 internally. AND IT WAS THE BOOT VOLUME !!! I could get it fixed before my script would have renamed the internal disk to “Sauvegarde” and backed up the bacup to the internal disk at the next run.
This problem is mainly because my backup-disk is firewire, and I have two of them (even and odd days) and therefore I can’t use /dev/diskxx sthle addressing, because it’s never the same address when I swap disks.

----------------

open a terminal and type “man asr”. This will show the documentation for the “asr” command. Disk Utility is a GUI for the asr command. You can script the asr command.