[Gllug] rsync problems

Keith Edmunds kae at midnighthax.com
Mon Dec 19 05:53:28 UTC 2011


I suspect the problem is that the destination directory doesn't exist.

What username are you running the scrip as?
What filesystem is on the external disk?

Here's a slightly modified version of the script. It uses some symbols to
make the script more readable, and avoids the backticks. It tries to
create the destination directory before running if necessary, although
that step will fail if the user running the script has insufficient
permissions. Finally, it writes any errors to your log file, so you'll be
able to see why things fail (if they still do). 

--------------------------------------------------------------------------------
#!/bin/bash -x #shell script for use with rsync in user crontab

USB_DIR="/media/8eef3b99-c17b-4913-ae61-d34c7fd5d459"
BACKUP_DIR="$USB_DIR/$(/bin/date +%Y%m%d)"

if [ -d $USB_DIR ]; then
	[ -d $BACKUP_DIR ] || mkdir $BACKUP_DIR \
		>> /home/boztu/cron/backup.txt 2>&1
	/usr/bin/rsync -avz \
		--exclude-from '/home/boztu/cron/xclude.txt' \
		/home/boztu/ $BACKUP_DIR \
   		>> /home/boztu/cron/backup.txt 2>&1
fi
--------------------------------------------------------------------------------

Personally, I would log the output of such a script to syslog, which means
it will be automatically time-stamped and log-rotated. This is how I would
do that:

--------------------------------------------------------------------------------
#!/bin/bash -x #shell script for use with rsync in user crontab

USB_DIR="/media/8eef3b99-c17b-4913-ae61-d34c7fd5d459"
BACKUP_DIR="$USB_DIR/$(/bin/date +%Y%m%d)"
LOG="/usr/bin/logger -t my_backups"

$LOG "Backup starting"
if [ -d $USB_DIR ]; then
	[ -d $BACKUP_DIR ] || mkdir $BACKUP_DIR \
		2>&1 | $LOG
	/usr/bin/rsync -avz \
		--exclude-from '/home/boztu/cron/xclude.txt' \
		/home/boztu/ $BACKUP_DIR 2>&1 | $LOG
fi
$LOG "Backup finished"
--------------------------------------------------------------------------------

Please note that I've not tested either script above. You should ensure
that you understand and test them (and fix them if necessary) before
relying on them.
-- 
"You can have everything in life you want if you help enough other people
get what they want" - Zig Ziglar. 

Who did you help today?
--
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list