I am trying to make a "backuper script" to keep a copy of a directory up to date on a USB-drive.
Basically every time I open my computer it run
rsync -qrup dir/path backupKey/path. I want a copy instead of an archive backup so that the USB-drive is usable on the go
Now my issue is that anytime I change the structure of my bookshelf dir tree.
e.g: I move
~/bookshelf/studies/html to ~/bookshelf/studies/web-development/html
In my backupKey rsync will simply copy
~/bookshelf/studies/web-development/html(the new location) but not delete the original files at
This end-up creating duplicates that I have to manually delete.
Various things I've thought or read:
cp, but this would be a lot more slow and resource intensive.
patchonly work on text file (I saw advanced possibility but it getting complex and I don't understand fully)
jdiffdon't seem to have a recursive option and I also don't know if it will work on various file type.
If someone as code examples of the loop. I need it to work with any file type digital books as much as notes and images. Sorry its been multiple hour I search online and can't find a solution that fits my idea.
Here is my script:
#!/bin/bash ## Create an backup script to keep my usb device. ## check if media Bookshlef is available exec &>> /home/$USER/.local/scripts/bookSUpdater.log echo "-----" echo `date +%Y-%m-%d-%T` if [ -e /media/$USER/Bookshelf ]; then echo "Bookshelf usb key is available" ## use rsync to copy documents to usb dev. echo "Starting transfer" rsync -qrup /home/$USER/bookshelf/ /media/$USER/Bookshelf ## d= copy dir wihtout recursing, l= keep symlink: rsync -qdlup /home/$USER/bookshelf/* /media/$USER/Bookshelf ## try with binary difference tool ## make a loop to check if file are deleted. IF YES delete echo "Operation succesful" echo $? && exit 0 else echo 'Error: Usb device unavailable aborting' echo 'Usage: Usb device '\"'Bookshelf'\"' must be plugged in.' echo $? && exit 2 fi