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.Another common related use case it to keep a selected part of the directory tree with
/./
, e.g. if you wanted:to go to:
you can write:
The magic
/./
gets specially parsed byrsync
before it passes that path to the system calls, and tells it where to start creating directories from. The/./
means nothing for other POSIX utilities in general, e.g. the patha/./b
is the same asa/b
in POSIX.With the Cygwin Windows rsync, and assuming the remote rsync is pointing to the root, I'd do:
That will put the contents of the remote pictures directory in /backup/home/udi/files/pictures. Presumably the syntax under unix would be similar.
JR