3

I am having trouble using the rsync properly and your help is needed. Here is what I would like to do. I have some files on a remote server (server1) and I'd like to copy them to the other server (server2). Server2 can access the server1 over ssh without any password.

Here is the file structure on server1.

/data/01/file[s] /data/02/file[s]

I would like to copy over everything under /data to server2 and keep the directory structure under /data and also keep the permissions as is.

1 Answer 1

5

rsync commands have the following syntax:

rsync [options] [source] [destination]

So, from server2, as the user who has passwordless access to server1:

rsync -avzh server1:/data/ /data/

See the rsync man page for more details, but a short explanation:

  • -avzh specifies the options to use when running this command
    • -a enables archive mode, which preserves permissions, ownership, and modification times, among other things
    • -v enables verbose mode, which simply increase how much rsync prints to stdout
    • -z enables compression during transfer
    • -h outputs numbers in human-readable format (e.g. "36864 bytes" becomes "36 kilobytes")
  • server1:/data/ tells rsync that the source is a remote server (server1) and, on that remote server, the source is /data/
  • /data/ tells rsync the destination to copy the source to -- note that no remote server is specified, meaning this is a local directory
3
  • @drewbenn - actually, I think you have that backwards; the destination trailing slash doesn't do much here, and the trailing slash on the source is what we want. From the rsync man page: 'A trailing slash on the source changes this behavior to avoid creating an additional directory level at the destination. You can think of a trailing / on a source as meaning "copy the contents of this directory" as opposed to "copy the directory by name", but in both cases the attributes of the containing directory are transferred to the containing directory on the destination.'
    – edaemon
    Nov 28, 2016 at 23:01
  • I have tried this myself and it does not do what I want it to do. I mean it does only half of it. When executing this command, all the directories in server1:/data/ is created in destination but no files are transferred. I want all the files within those directories to be copied over as well.
    – amdjml
    Nov 29, 2016 at 15:17
  • @amdjml: that command does copy files. If it doesn't for you, something else is preventing the transfer of the files. You may have a permissions issue.
    – edaemon
    Nov 29, 2016 at 17:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .