How to use RSYNC

Rsync is a very handy tool should you need to migrate a whole lot of files from one server to another. It also helps to provide you with a very customizable way of moving files. All in all a very good tool for testing, doing a live migration, or just moving files around in a server environment.

This article presumes you have some knowledge of how to use the terminal/command prompt and the basics of SSH. The first thing you need is a place where you want to move files from and too. Either doing the push or pull method is up to you. Let’s say you want to pull files from another server:

  1. Log onto the DESTINATION server

    If with us that would be something like this:

    ssh username@hostname

    You can find the exact username and hostname under your site’s server login information:

  2. Note the SSH information from the SOURCE server

    This shouldn’t be very different from the SSH credentials you would have with us. What you need is:
    – Username
    – Hostname
    – SSH Password
    – Source directory
    – Port number (not necessary to note should it be 22)

  3. Run RSYNC from the DESTINATION server

    The normal syntax for the RSYNC pull method looks like this:

    rsync -[OPTION] [USER]@[HOST]:[SRC-DIR] [DESTINATION]

    So an example could look like this:

    rsync -av [email protected]:~/secret/folder/ ~/new/server/destination

    Same example with a specific port number:

    rsync -av -e "ssh -p 12345" [email protected]:~/secret/folder/ ~/new/server/destination

  4. Some things to note


    -[OPTION] is not necessary should you not need to use any specific options. Though using at least -a option will ensure you to copy most things as they are on the source server

    Not adding / after the source directory will move the whole directory and not just it contents. Also not specifying the source directory will pull everything from the user root.

    The ~ means to begin from the user root at the specified server.

    Should you need to read the manual pages for rsync you can always run man rsync or you can check out this link.

And that’s the gist of how to pull something from another server. You can also use the push method where you push your contents from source to your destination. How you will do that is by just switching the specified source and destination around and running it from the source server, like this:

rsync -[OPTION] [DESTINATION] [USER]@[HOST]:[SRC-DIR]

This is an article that looks just at the surface of rsync. We urge you to test it for yourself and see what works and not.


Also, we’ll always be available for you on our chat at servebolt.com should you have any questions!