I have this daily archiving job

rsync -a --ignore-existing --remove-source-files src dst

The intent is to copy files to an archive and remove them from the source when done.

I have one very important contraint: don't overwrite any file in the destination if it already exists and is different from the one in the source, because it means something is wrong.

Most of the time what goes wrong is the rsync job is interrupted. Not a big deal, the next day's run will recover, right? Wrong. Sadly, when it runs again the next day it doesn't transfer because of the --ignore-existing, even though the files on the destination are identical to the files on the source.

The simplest solution would be if rsync had an option like --ignore-existing-only-if-different, but it doesn't. I can't relax my constraint either. So, right now I'm stuck manually recovering the rsync when it fails.

Thoughts?

link|improve this question

22% accept rate
feedback

1 Answer

You can try the command:

rsync -au --remove-source-files src dst

Only the newer files should be copied. I think this should be fine for you. When it is interrupted, it will recopy the files again.

link|improve this answer
Doesn't work, overwriting a file in the destination with a newer file from the source would be a disaster. – mbac32768 Dec 6 '11 at 17:08
Only the interrupted files will be overwritten which should be fine. Isn't it? You are removing the files from source after copying. – Khaled Dec 6 '11 at 19:16
@Khaled - Target's files will only be safe if they're newer (they could be updated, but older -u would still step on them). You'd have to check for this with -n / --dry-run to make sure it doesn't do anything horrible. – voretaq7 Dec 9 '11 at 20:19
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.