Posts Tagged ‘bash backup script’

Bash backup script

December 15, 2013

Just a simple back up script and my cron entry.  This script will check to see if your USB device exist.  If so, it mounts, it rsyncs, it echo’s a date and a “complete” string into a file then unmounts the drive.  If the USB device don’t exist, it echos a fail into a file.

My script runs every night 1 minute after 3am.

*Reason I have unmount is so I can just yank it out whenever I want.  Also, with any *nix, there is more than one way to skin a cat, this is my way I figured out on my own.

#######  SCRIPT ########

#!/bin/sh

if [ -e ‘/dev/da0p1’ ] ; then

/sbin/mount /dev/da0p1 /backup

/usr/local/bin/rsync -a –delete /data/ /backup/

echo “$(date) COMPLETE” >> /home/user/backup.log

/sbin/umount -f /backup

else

echo “$(date) FAILED” >> /home/user/backup.log

fi

##############  CRONTAB ENTRY ##########

1 3 * * * root cd /home/user && ./backup.sh