Code:
#!/bin/sh
mount /dev/usb-harddrive
# Author: Brice Burgess
# backup.sh -- backup to a local drive using rsync
# Directories to backup. Separate with a space. Exclude trailing slash!
SOURCES="/home"
# Directory to backup to. This is where your backup(s) will be stored.
# Exclude trailing slash!
TARGET="/mnt/usb-harddrive/backup"
# Comment out the following line to disable verbose output
VERBOSE="-v"
###########################
if [ ! -x $TARGET ]; then
echo "Backup target does not exist or you don't have permission!"
echo "Exiting..."
exit 2
fi
echo "Verifying Sources..."
for source in $SOURCES; do
echo "Checking $source..."
if [ ! -x $source ]; then
echo "Error with $source!"
echo "Directory either does not exist, or you do not have proper permissions."
exit 2
fi
done
if [ -f $EXCLUDE_FILE ]; then
EXCLUDE="--exclude-from=$EXCLUDE_FILE"
fi
echo "Sources verified. Running rsync..."
for source in $SOURCES; do
# Create directories in $TARGET to mimick source directory hiearchy
if [ ! -d $TARGET/$source ]; then
mkdir -p $TARGET/$source
fi
rsync $VERBOSE --exclude=$TARGET/ $EXCLUDE -a --delete $source/ $TARGET/$source/
done
umount /dev/usb-harddrive
exit 0
I decided to use this script I found and modified to fit my needs, but there's one thing missing and I have no idea how to do it. When the script runs the first thing it should do, before the mounting, is checking to see if there's an USB device connected. Anyone knows how to do this?