I’m trying to create a script that will automatically backup a complete directory tree. I also want it to work for incremental backups. Basically, it wil work like this:
- If file is in both source and destination and they are different, source file will be copied
- If file is in both source and destination and they are the same, nothing will be copied
- If file is only in the source, source file will be copied
- If file is only in the destination, destination file will be deleted.
I’m still new to shell scripting and I’m not sure how I could implement this. Any ideas? Windows batch scripts would be better, but shell scripts that run on Cygwin are also fine.
For windows batch scripting xcopy (native to windows) or robocopy (a free download in windows) both work extremely well.
An example
xcopyscript (in a.batfile):It will even support orphaned files (if you delete something from your source you no longer need a copy in the backup).
Xcopyis typically fine for your needs until you deal with sync between NTFS and Fat32 file systems – the later only has a 2 second resolution and problems with daily savings time so you occasionally run into issues: (a) on time change day you might not get a backup of a changed file – depends on change-regularity of course or you might get a backup of all files even though none have changed (b) because of time resolution some files may backup even though they haven’t changed.