Added ability to create directory and correct ownership before attempting rsync

This commit is contained in:
Tracey Clark 2022-03-03 19:39:26 -06:00
commit c5c4d696e3

View file

@ -4,6 +4,7 @@
#http://www.bobulous.org.uk/misc/rsync-backup.html
date=`date +%Y-%m-%d`
log_file='/home/tracey/backuplogs/usb-rsync-backup-'${date}'.txt'
backup_dir_mount='/data/LinuxBack'
echo "#####"
echo ""
@ -13,12 +14,13 @@ echo ""
# echo "OS we're running on is $OS"
source ~/git/shell-scripts/check_os.sh
# Get the mount point by uuid - for old USB drive
# Get the mount point by uuid
#UUID=ff0b3c83-853d-452f-abb6-48069e337446
#mount_point=`findmnt -rn -S UUID=$UUID -o TARGET`
# For dedicated Linux Backup drive
# LABEL="LinuxBack" UUID="af60e100-e805-4318-abc8-175f916ff18a" TYPE="ext4" PARTUUID="3b3d0d2d-65a8-e440-a878-29fbf9184759"
# LABEL="LinuxBackups" UUID="498d5c30-d9c2-4fcd-ba75-ca417ea5e962" TYPE="ext4" PARTUUID="f1ee7312-41a8-b044-879a-8eef185b0453"
mount_point=/data/LinuxBack
@ -37,10 +39,25 @@ 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 mounted backup volume!"
echo "Mounting failed! Cannot run backup without a mounted backup volume!"
exit 1
fi
# This only has to be done once per new ext* partition. Perms should stick after that every time its mounted
if [ -w $backup_dir_mount ]
then
echo "User has write permission for backup directory, proceeding with rsync"
else
echo "Changing ownership for backup directory - only has to be done once for the drive"
sudo chown tracey.users $backup_dir_mount
fi
# Check whether target directory exists. If not need to use sudo to make it
if [ ! -d "$backup_dir_mount/tracey_home" ]; then
echo "Creawting backup directory"
fi
echo "Preparing to rsync differences in home directory to backup USB drive."
rsync -azh --exclude '.cache' --exclude 'Videos' --exclude 'Nextcloud' --exclude 'Downloads/isos' --exclude 'VirtualBox VMs' --exclude 'Sync' --exclude '.local/share/Steam' --exclude 'Music' --exclude '.Trash-*' --exclude 'home_backup' --progress /home/tracey/ $mount_point/tracey_home --delete 2>&1 | tee $log_file