50

I have an rsync backup script I run, which also restores files back where they came from when I ask. But if the files at the destination are newer than those in the backup when I try to restore, it will not replace them. I really want to replace the newer files with those in the backup but I don't see a way to make rsync do this.

tldr: is there a way to force rsync to overwrite files at the destination?

edit: I've been running rsync -avhp When I want to restore a backup, I use the same command with the "to" and "from" swapped. So it tries to copy files from the backup drive to the place on my computer they belong.

  • 16
    rsync will always overwrite files at the destination unless you tell it not to do this (option -u, --update). Check your command line arguments. – scai Jun 17 '13 at 12:12
  • Can you share your actual rsync command? Rsync will overwrite older files with newer ones, so you're most likely comparing files by just timestamp, and the dates are slightly out of whack between the 2 computers. – slm Jun 17 '13 at 12:51
  • I've tried using touch to make the files I want to replace "older" than my backup, but it still doesn't replace the existing ones in my home folder. – jedipixel Jun 17 '13 at 15:34
  • Maybe '-I --modify-window=999999999' works for you? – jelle foks Jun 19 '13 at 23:43
55

The manual says:

-I, --ignore-times   don't skip files that match size and time

With more details:

-I, --ignore-times

Normally rsync will skip any files that are already the same size and have the same modification timestamp. This option turns off this "quick check" behavior, causing all files to be updated.

| improve this answer | |
  • 1
    what about just size? skip files that match exactly, but replace those if there is a diff ... regardless if the target one is newer – mmm Nov 21 '19 at 10:45
  • 1
    @mmm That sounds like the --size-only option. From the rsync man: "This modifies rsync's lqquick checkrq algorithm for finding files that need to be transferred, changing it from the default of transferring files with either a changed size or a changed lastmodified time to just looking for files that have changed in size. This is useful when starting to use rsync after using another mirroring system which may not preserve timestamps exactly." – mellow-yellow Jul 6 at 16:00

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.