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?


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.

  • 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 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.