3

I recently discovered that a few files on a volume had been mysteriously truncated - or more accurately, replaced with a zero length file.

Fortunately, these files were hard-linked from multiple places, and only about half the links were actually overwritten with a zero-length file with seemingly the same attributes.

However, when I looked in my backups, I found the issue had occurred before my previous backup. For the volume in question, a simple mirror backup should be sufficient, because files shouldn't get deleted - it's mostly append only. But since the file isn't actually being deleted, I can't simply tell rsync to not delete.

Is there a way to tell rsync to not sync a file that is zero length locally, but has a non-zero length on the remote side?

I could of course simply write some code to look for zero length files and exclude them, but this is an extra time-consuming step (now there are two full scans of the filesystem) and it could exclude files which legitimately should be rsynced (in case there are files that are expected to be zero length).

  • You might want to look at rsync's --backup options... – derobert Apr 1 '15 at 7:48
  • Also, it's not possible to have some of the hard links to a file be of a different size. All hard linked names are to the same file. If this isn't just a case of using the wrong term, and you actually have two hard links to the same file showing a different size—you have something very, very broken. – derobert Apr 1 '15 at 7:50
  • @derobert The hard links appears to have been replaced by zero length files which had the same file name and timestamp as the original file. – Michael Apr 1 '15 at 17:05
5

rsync has a --min-size option:

 --min-size=SIZE         don't transfer any file smaller than SIZE

That should help you unless you have files that do have to be transferred if there is no zero byte sized file on the destination side of things.

AFAIK there is no way to tell rsync to take special action based on source and destination side.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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