Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm about to transfer a large website over to a new server (CentOS on both ends) - at the moment the new server is running an old copy of all the files on there, something I think I did with SCP originally. Since making that copy, I made some changes to some of the files on the new server, and created a few as part of testing things.

I'm hoping to sync everything up again using rsync (as it seems to be the most appropriate tool), but I'm not sure how to remove everything that has been changed on the new server and replace it with the old files on the existing server, without copying a whole bunch of identical files again.

The -I syntax seems to do what I want, by ignoring dates I can get it to replace anything that's different, but how do I remove the files that shouldn't be there and get a true 1:1 copy on both ends?

share|improve this question
up vote 4 down vote accepted

Take a look at the --delete option:

--delete                delete extraneous files from dest dirs

something like this:

/usr/bin/rsync -avz --delete --ignore-existing /document/root/ user@newserver:/document/root/ 

You may also use the --checksum option instead of uses a "quick check" by default.

share|improve this answer
Thanks, I was a bit worried when I saw the notes about being cautious over using the delete option. I did a dry run earlier and it seemed to be what I expected. – Matt W Nov 5 '11 at 22:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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