46

When I do something like:

rsync Videos/YouTube/LetsPlays foo@bar:/home/foo/

The resulting directory structure looks like:

/home/foo/LetsPlays

I've read the man pages but couldn't an option to maintain the directory structure, aiming for

/home/foo/Videos/YouTube/LetsPlays

as result. Any ideas?

As always thanks in regards, Markus

Markus
  • 1,585

2 Answers2

87

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

If you do not want the full path of the remote file, but only part of that, rsync offers this feature since version 2.6.7 (this is the version on the sending side which is the local side in your case).

Just insert a dot /./ into the path where you want to break the path

Ex:

rsync --relative Videos/./YouTube/LetsPlays foo@bar:/home/foo/

would result in this remote path:

/home/foo/YouTube/LetsPlays
Jan
  • 12,291
  • 3
  • 32
  • 38
4

I tried to use --relative flag that didn't work for me. Therefore, I used -R to retain the path. Insert a dot /./ into the path where you want to break it.

Command:

rsync -avR /src path/ /dest path/

Example:

rsync -avR Videos/./YouTube/LetsPlays foo@bar:/home/foo/

Result:

/home/foo/YouTube/LetsPlays