Rsync is an incredibly handy tool for migrating a large number of files from one server to another. It offers a highly customizable way of transferring files, making it ideal for various tasks, including live migrations, testing, or simply moving files within a server environment.
Prerequisites
This guide assumes you have basic knowledge of using the terminal or command prompt and a fundamental understanding of SSH. Before you start, ensure you have a target location where you want to move the files. You can push files to the destination server or pull files from the source server.
Getting Started with Rsync
To illustrate, let’s say you want to pull files from another server. Here’s how you can do it:
- 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: - 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) - 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
- Some things to note
-[OPTION]
is unnecessary should you not need to use any specific options. Though using at least-a
option will ensure you copy most things as they are on the source server
Not adding/
after the source directory will move the whole directory, not just its 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 runman rsync
or you can check out this link.
And that’s the gist of how to pull files from another server. You can also use the push method to transfer your content from the source to the destination. To do this, simply switch the specified source and destination and run the command from the source server, like this:
rsync -[OPTION] [DESTINATION] [USER]@[HOST]:[SRC-DIR]
This how-to article only scratches the surface of what rsync can do. We encourage you to test it yourself to discover what works best for your needs and what doesn’t.
Also, we’ll always be available on our chat at servebolt.com if you have any questions!