Home » Questions » Computers [ Ask a new question ]

How can I script making a backup of recently modified files in Bash?

How can I script making a backup of recently modified files in Bash?

I have written this backup script that looks in a file and copies recent files into a folder.

Asked by: Guest | Views: 263
Total answers/comments: 2
bert [Entry]

"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."
bert [Entry]

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"...