83

When I run this command

rsync -avzp --del -e "ssh -p myport" user@hostname:/var/www/tests /var/www/tests

files get synchronized but instead of saving files in /var/www/tests, Rsync creates one more directory "tests" inside of existing "tests":

/var/www/tests/tests

and puts files there. How to tell Rsync not to create a new directory?

javi007
  • 833
  • 1
  • 6
  • 5

2 Answers2

80

If you don't want another tests directory created, the correct command would be

rsync -avzp --del -e "ssh -p myport" user@hostname:/var/www/tests/ /var/www/tests

Note the / at the end of user@hostname:/var/www/tests/.

etagenklo
  • 5,694
  • 1
  • 25
  • 31
  • 1
    beware also of the rsync option -R, if you are having this problem. The very purpose of -R (or --relative) is to recreate the full source directory path at the destination. So it will have the same effect as if you omit the trailing slash. – markling Nov 12 '19 at 11:15
  • `-a` already contains `-p` – mgutt Apr 01 '22 at 16:45
40

You need a trailing slash on the source.

Here is the correct command:

rsync -avzp --del -e "ssh -p myport" user@hostname:/var/www/tests/ /var/www/tests

More Info

Explanation of rsync and trailing slashes:

http://defindit.com/readme_files/rsync_backup.html

Rsync has two major modes of operation. The modes are dependent on the absence or presence of the trailing slash on the source directory.

Another example:

http://www.jveweb.net/en/archives/2010/11/synchronizing-folders-with-rsync.html

...you need to add the trailing slash, otherwise, a folder called Pictures is created inside the Pictures folder that we specify as destination.

Drew Khoury
  • 4,569
  • 8
  • 26
  • 28