Can rsync compare/copy based on mod date and filename alone, ignoring file size?

Context: I'm trying to implement a two-stage backup using rsync. The first stage is onsite, and I have a bash rsync script to copy files from the source path to on-site storage, and this runs hourly. The second stage runs at night and uses rsync to transfer everything new/modified to an off-site data center from the on-site storage. Problem is, the on-site storage boxes are filling up. Neither reducing the data backed up, nor increasing the storage capacity, is an option.

I've written a purge script to remove files a year old or greater every night on the on-site storage boxes, and replace them with empty touch files, preserving the timestamp of the original files-- this is to prevent rsync from copying the same file back from the source after the destination file is removed. But I can't figure out how to tell rsync to ignore file sizes; I need it to ignore compare/copy based on mod date and file name alone.

I've been through the man pages and have searched, and it doesn't look like this is possible. Is this correct? Any workaround ideas?

  • Also, I've thought of doing a --files-from filelist, but from my testing it looks like rsync ignores exclusions if you specify a filelist, and this is a dealbreaker for me (for design constraints). – kiwisan May 22 '13 at 10:29
  • With AeroFS and "BitTorrent Sync" now available, it reduces the need for rsync IMHO except in some special situations. – djangofan May 22 '13 at 16:55

rsync does not seem to be able to ignore the file size.

A possible workaround if the actual file data doesn't matter is to make sparse destination files with the same size as the source files. Example:

dd if=/dev/urandom bs=1M count=4 of=a
rsync -a a b
truncate -s 0 b && truncate -r a b && touch -r a b

b is now empty and uses no space (if the file system supports sparse files), but still has the same size as a.

rsync -a a b
du -h a b
# 4.0M    a
# 0       b

As can be seen by the output of du, b was not updated as it still uses no space.


I think what you want is:

--delete                delete extraneous files from dest dirs

This will remove files from the destination if they have been deleted in the source dir.

Of course this would mean you would need to stop creating empty files instead of just deleting the expired files.


You can use the --update switch to "skip files that are newer on the receiver", but you can't preserve the timestamp when you touch the placeholder files (if the man page is accurate when saying "newer" and not "equal date or newer").

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.