shell-scripts/local_backup.sh

36 lines
1.3 KiB
Bash
Executable file

#!/bin/bash
#Script to back up /home/tracey to external USB drive
#http://www.bobulous.org.uk/misc/rsync-backup.html
date=`date +%Y-%m-%d`
mount_point='/media/tracey/Backup'
log_file='/home/tracey/usb-rsync-backup-'${date}'.txt'
echo "#####"
echo ""
# Check whether target volume is mounted, and mount it if not.
if ! mountpoint -q ${mount_point}/; then
echo "Mounting the external USB drive."
echo "Mountpoint is ${mount_point}"
if ! mount ${mount_point}; then
echo "An error code was returned by mount command!"
exit 5
else echo "Mounted successfully.";
fi
else echo "${mount_point} is already mounted.";
fi
# Target volume **must** be mounted by this point. If not, die screaming.
if ! mountpoint -q ${mount_point}/; then
echo "Mounting failed! Cannot run backup without backup volume!"
exit 1
fi
echo "Preparing to transfer differences in home directory to backup USB drive using rsync."
rsync -avzh --exclude '.cache' --exclude 'Videos' --exclude 'Nextloud' --exclude 'Downloads/isos' --exclude 'VirtualBox VMs' --exclude 'Sync' --exclude 'Downloads/torrents' --exclude '.local/share/Steam' --exclude 'Music' --progress --delete /home/tracey/Documents /media/tracey/Backup/tracey/Documents/ 2>&1 | tee $log_file
echo ""
echo "Backup Complete"
echo "Log of this backup is in $log_file"
echo ""
echo "####"