When backing up with rsync, How do I keep the full directory structure?

For example, the remote server is saturn, and I want to backup saturn's /home/udi/files/pictures to a local directory named backup.

I want to have (locally) backup/home/udi/files/pictures rather than backup/pictures.


Use the -R or --relative option to preserve the full path.

| improve this answer | |

Another common related use case it to keep a selected part of the directory tree with /./, e.g. if you wanted:


you can write:

rsync --relative /home/udi/./files/pictures backup

The magic /./ tells rsync where to start creating directories from.

| improve this answer | |
  • 2
    This worked for me! Is the magic ./ a Linux construct or specific to rsync? Just trying to gain some insight into this behavior. – flow2k Sep 23 '19 at 19:31
  • 1
    @flow2k just rsync magic, for POSIX it is redundant. – Ciro Santilli 郝海东冠状病六四事件法轮功 Sep 23 '19 at 21:55

With the Cygwin Windows rsync, and assuming the remote rsync is pointing to the root, I'd do:

rsync -vtrz --delete server::rsyncid/home/udi/files/pictures /cygdrive/d/backup/home/udi/files

That will put the contents of the remote pictures directory in /backup/home/udi/files/pictures. Presumably the syntax under unix would be similar.


| improve this answer | |
  • It is not useful because we need to reproduce the whole directory hierarchy on the local side before executing the rsync command. – Ludovic Kuty Apr 2 '12 at 11:42

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.