How can I script making a backup of recently modified files in Bash?
A way would be to modify the file names that you get when running find. So in your loop, having a matched file name in $filename you shall:
- In $filename, replace the leading $i with nothing
- find out the $dir_name in the result of 1 by using dirname
- append a trailing $copyLocation to $dirname and use it as argument for mkdir -p to create missing directories
- copy $filename to "$copyLocation/$dirname"
I'm also going to suggest yet another file sync alternative: unison. It is easier to use than rsync.
rsync is made for this task. Check the examples page for usage.
A little off-topic perhaps, but you may want to take a look at BoxBackup. I used rsync scripts for a long time before moving to BoxBackup, and it really makes things easier - especially the "housekeeping"...