From 043411bd887f9fa903685178031e5f0338a8b1b0 Mon Sep 17 00:00:00 2001 From: Tracey Clark Date: Wed, 3 Oct 2018 20:27:03 -0500 Subject: [PATCH] Initial commit of local rsync backup script --- local_backup.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 local_backup.sh diff --git a/local_backup.sh b/local_backup.sh new file mode 100755 index 0000000..84b73c4 --- /dev/null +++ b/local_backup.sh @@ -0,0 +1,36 @@ +#!/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/$date' + +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 /home/tracey/rsync-output.txt + +echo "" +echo "Backup Complete" +echo "Log of this backup is in " +echo "" +echo "####"