# rsync copied 0-byte source file

## nordic bro

I'm kind of new to rsync and this is the cmd I use:

rsync -axu --delete 

there are a number of source partitions I backup to similarly-sized target partitions on a separate disc.  I run "$rsync_cmd $source/ $target/" from a script and after lots of double-checking initially it seemed to have been working great for many months.  

the other day in source /etc I came across 0-byte ntp.conf and have no idea how that happened.  so I mounted the corresponding rsync target to copy the file back but found its npt.conf was also 0-byte.  

that 0-byte file was the only one in target /etc, all the rest there looked ok so it seems my source ntp.conf got wiped out and when I did a subsequent rsync my good target copy got replaced.

so is there an rsync option I can add that would tell rsync to never replace something on target w/0-byte source file?

thanks.

----------

## eccerr0r

What if you deliberately zeroed out the file and needed an empty file, and needed a full restore - you'd also end up with a broken system.

Maybe the best way is to RCS all of these files... but the original way to deal with this is to have rotating and incremental backups or a version controlled filesystem.

I suppose the least software way to do this is to use

find /sourcedir -size 0 -type f > /tmp/newzerosized.txt

find /destdir -size 0 -type f > /tmp/oldzerosized.txt

[insert magic here to remove all old zerosized files from newzerosized file list]

to find empty files, and tell rsync --exclude-from /tmp/skipzerosized.txt to skip them.  Or you could do away with checking old ones and just let it skip them too even if they've never been copied.

Not a very clean solution either way...

(I was experimenting with a deduplication filesystem as backup, but lessfs is crap for large number of small file backups.)

----------

## Hu

According to man rsync, you can use --min-size to implement this.  However, as eccerr0r says, this may not be the right choice in some situations, so think carefully before deploying it across a large area.

----------

