[X-Unix] Backup script help

Charles Howse chowse at charter.net
Wed Feb 22 10:21:45 PST 2006


Hi,
This is rather long, sorry.

Rather than use a 'third-party' application to do my backups, I have  
written a bash script to backup my important files to another  
computer on my home lan.  Why?  Just because I can.

It's working well, with the exception of a couple of things I would  
like some input on.

First, I'm not satisfied with how I'm verifying that the backup  
volume on the remote server is mounted or not.  Can anyone help make  
that section 'bullet-proof'?

Second, is it enough to just backup ~/Library/Application Support/ 
Firefox/, AddressBook/, iCal/, and ~/Library/Mail/, or should I use  
those application's Export/Backup feature to generate the files I  
want to backup?

Here is my script...
*****
#!/bin/bash

## NOTE: ADD 'n' TO THE cmd OPTIONS WHEN TESTING

dc=`date +%m%d%y`
file='/Users/Charles/Documents/backup.log.'$dc'.txt'
cmd='rsync -uvrtp --delete-after'
src=/Users/Charles
dest=/Users/charles/mnt

# Is the server on?
ping -o -t 5 moe > /dev/null 2>&1
if [ "$?" -ne 0 ] ; then
	# Assume server is not on, display alert and quit
	echo "Cannot ping server, exiting" >> $file
	mail -s "Weekly Backup results" charles < $file
     	exit
else
	# The server is on, is the backup volume mounted?
	if [ `ls /Users/charles/mnt/FreeBSD > /dev/null 2>&1` ] ; then
		#Volume is mounted, continue
		echo `date` > $file
		echo >> $file
		echo "Volume is apparently already mounted, continuing." >> $file
		echo >> $file
	else
		# Volume is not mounted, mount it and continue
		mount -t nfs moe:/backup /Users/charles/mnt > /dev/null 2>&1
		if [ "$?" -eq 0 ] ; then
			# Mounted OK
			echo `date` > $file
			echo >> $file
			echo "Mounted volume successfully, continuing." >> $file
			echo >> $file
		else	
			# Mount failed
			if [ "$?" ! -eq 0 ] ; then
				echo `date` > $file
				echo >> $file
				echo "Mount returned" "$?" ", exiting." >> $file
				mail -s "Weekly Backup results" charles < $file					
				exit
			fi
		fi
	fi
fi

echo 'AppleScripts...' >> $file
$cmd $src/AppleScripts/ $dest/AppleScripts >> $file
echo >> $file

echo 'bin...' >> $file
$cmd $src/bin/ $dest/bin >> $file
echo >> $file

echo 'Documents...' >> $file
$cmd --exclude=/Virtual* $src/Documents/ $dest/Documents >> $file
echo >> $file

echo 'Downloads...' >> $file
$cmd $src/Downloads/ $dest/Downloads >> $file
echo >> $file

echo 'Magazines...' >> $file
$cmd $src/Magazines/ $dest/Magazines >> $file
echo >> $file

echo 'Sites/HomeUnix...' >> $file
$cmd $src/Sites/HomeUnix/ $dest/HomeUnix >> $file
echo >> $file

echo 'Music...' >> $file
$cmd $src/Music/ $dest/Music >> $file
echo >> $file

echo 'Recipes...' >> $file
$cmd $src/Library/Application*/TLAF/ $dest/TLAF >> $file
echo >> $file

echo 'Firefox...' >> $file
$cmd $src/Library/Application*/Firefox/ $dest/Firefox >> $file
echo >> $file

echo 'AddressBook...' >> $file
$cmd $src/Library/Application*/AddressBook/ $dest/AddressBook >> $file
echo >> $file

echo 'iCal...' >> $file
$cmd $src/Library/Application*/iCal/ $dest/iCal >> $file
echo >> $file

echo 'Mail...' >> $file
$cmd $src/Library/Mail/ $dest/Mail >> $file
echo >> $file

echo "Space available on moe:/backup:" >> $file
df -h /Users/charles/mnt >> $file
echo >> $file

umount /Users/charles/mnt > /dev/null 2>&1
if [ ! "$?" -eq 0 ] ; then
	echo "Could not unmount /Users/charles/mnt" >> $file
else
	echo "/Users/charles/mnt unmounted successfully" >> $file
fi

mail -s "Weekly Backup results" charles < $file
*****


Thanks,
Charles




More information about the X-Unix mailing list