I really don’t like working with Mac’s, though the fact that they are based off of unix now does make it easier to work with. A little while back I had to write a script to backup a Mac to a usb drive. I had first looked for some free or low cost software that would backup the Mac and a NAS, but didn’t have a lot of luck. Instead I ended up writing a shell script to do it. It’s a little rough, but works, another note the logging to email isn’t the best, but does work if you enable postfix on the Mac.
here is the script:
——————————————->start of script<————————————————————
#!/bin/sh
#written by David Hedges
DATE=`date +%Y%m%d` #get the date
DOW=`date +%a` #get day of the week
TIMEDIR=/Volumes/LaCie/time
mkdir /Volumes/scans
mkdir /Volumes/shareddata
mkdir /Volumes/usersdata
mkdir /Volumes/it
mkdir /Volumes/LaCie
mount -t hfs /dev/disk1s1 /Volumes/LaCie
mount -t smbfs //administrator:<password>@192.168.42.10/it /Volumes/it
mount -t smbfs //administrator:<password>@192.168.42.10/usersdata /Volumes/usersdata
mount -t smbfs //administrator:<password>@192.168.42.10/shareddata /Volumes/shareddata
mount -t smbfs //administrator:<password>@192.168.42.10/scans /Volumes/scans
rsync -avz /Volumes/it /Volumes/LaCie/current/it >/Volumes/LaCie/logs/$DOW.log
rsync -avz /Volumes/usersdata /Volumes/LaCie/current/usersdata >>/Volumes/LaCie/logs/$DOW.log
rsync -avz /Volumes/shareddata /Volumes/LaCie/current/shareddata >>/Volumes/LaCie/logs/$DOW.log
rsync -avz /Volumes/scans /Volumes/LaCie/current/scans >>/Volumes/LaCie/logs/$DOW.log
rsync -avz –exlcude Volumes / /Volumes/LaCie/current/local >>/Volumes/LaCie/logs/$DOW.log
# Weekly full backup
if [ $DOW = “Fri” ]; then
NEWER=””
NOW=`date +%d-%b`
echo $NOW > $TIMEDIR/full-date
tar $NEWER -zcvf /Volumes/LaCie/$DOW.tgz /Volumes/LaCie/current >>/Volumes/LaCie/logs/$DOW.log
else
NEWER=”–newer `cat $TIMEDIR/full-date`”
tar $NEWER -zcvf /Volumes/LaCie/$DOW.tgz /Volumes/LaCie/current >>/Volumes/LaCie/logs/$DOW.log
fi
grep -i fail /Volumes/LaCie/logs/$DOW.log >/Volumes/LaCie/logs/$DOW.error.log
grep -i error /Volumes/LaCie/logs/$DOW.log >>/Volumes/LaCie/logs/$DOW.error.log
mail -s backup-results <email address> </Volumes/LaCie/logs/$DOW.error.log
mail -s backup-results <email address> </Volumes/LaCie/logs/$DOW.log
——————————————->end script<————————————-
Leave a Reply