On my RHEL6 pair of servers, I tested the rsync from server-1 to Server-2 with SSH. Everything was good as expected. However, when I moved a file under A directory, A/x.file to B/ of /home/user on Server-1, repeated the same rsync with --delete (or similar options) did not remove x.file on A/ and backup x.file to B/ on Server-2. Here is the rsync script:

rsync -avhu -e ssh --delete home/user/ remote_user@remote_host:/home/user/.  

ssh was set up without passphrase. I tried different order of those options, none of them work, meaning that x.file was still under A/ at destination (server-2), not on B/. What went wrong?

  • 1
    Can you include the first few lines of the log output from rsync? It occasionally skips deletion if anything was amiss with the transfer.
    – alienth
    Sep 3, 2015 at 22:14

2 Answers 2


Here's some general guidance on how to get rsync to do what you'd like it to do using the options you've selected in your script:

To copy the contents of a directory from the source directory to a remote destination directory (the first time), you can do:

    rsync --archive --verbose --human-readable source -e ssh username@servername:/home/user/ . 

Once you've made some changes to the source directory that you'd like to sync with your destination directory, do:

    rsync --archive --verbose --human-readable --delete source/ -e ssh username@servername:/home/user/source . 

Take note:

  • When you first copy a source directory to a destination directory, you do not need to follow source with a / (forward slash).

  • When you sync a source directory to a destination directory, you do need to follow source with a / (forward slash).This / means the content of the source directory, and not the directory itself.

You can test drive your script with this option: --dry-run .

  • Isn't the destination missing in the first command?
    – sebix
    Sep 4, 2015 at 18:41
  • The omission is intentional @sebix. In this case, rsync will create a directory called source in /home/user on the remote server.
    – marshki
    Sep 4, 2015 at 19:37
  • Okay, but you wrote to a remote *destination* directory. Now you say source = destination.
    – sebix
    Sep 4, 2015 at 19:56
  • That's a fair point @sebix, and one I overlooked. I'll amend my initial proposal accordingly.
    – marshki
    Sep 4, 2015 at 20:04

This slightly modified code works for me:

rsync -avhu -e ssh --delete /home/user/ remote_user@remote_host:/home/user/.

If your production code really does reference home/user/ instead of /home/user/ then that could easily be a reason it's failing. You would also be getting an error rsync: change_dir "/home/user//home/user" failed: No such file or directory (2)

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.