Rsync stands for “remote synchronization”. It is a remote and local file synchronization tool that helps you efficiently transfer files.
What RSync Is
Some of the additional features of Rsync include:
- Supports copying links, devices, owners, groups, and permissions
- Does not require super-user privileges
- Pipelines file transfers to minimize latency costs
You can only transfer files from local? to ?remote or remote? to ?local. Rsync does not support remote? to ?remote file transfers.
How RSync Works
Now that you know what Rsync is, let's look at how to work with it.
Rsync works similarly to other remote server management tools like SSH and SCP.
Here is the basic syntax of Rsync:
rsync [options] source [destination]
Here is the syntax to transfer a file from your local system to a remote server. It is also called a “push” operation.
rsync local_file_path user@remote-host:remote_file_path
Here's how to transfer a file from a remote server to your local system, also called a “pull” operation.
rsync user@remote-host:remote_file_path local_file_path
Note: When working with remote systems, make sure you have SSH access to the remote system. Rsync establishes the connection using SSH in order to enable file transfer.
How to Use Flags in RSync
Rsync lets you add additional options via command-line flags. Let's look at a few useful flags.
If you add the -r option, RSync will execute a recursive file transfer. This is useful when working with directories. Here is an example:
rsync -r user@remote-host:remote_directory/ local_directory
The -a flag is used to preserve symbolic links while transferring files. The archive flag also preserves special and device files, modification times, and permissions from the source directory.
The archive flag also syncs files recursively, so it is used more than the recursive flag. Here is how you use it:
rsync -a user@remote-host:remote_directory/ local_directory
You can also compress files using the -z flag. Compressing files can reduce network load and speed up file transfer.
rsync -az user@remote-host:remote_directory/ local_directory
For large file transfers, it is useful to know the progress of the operation. You can use the -P flag to know the progress of the file transfer. With Rsync, you can also resume file transfers if they are interrupted.
rsync -aP user@remote-host:remote_directory/ local_directory
Finally, the verbose command can help you understand every step of the file transfer. You can use the -v flag for this.
rsync -av user@remote-host:remote_directory/ local_directory
You can also use the help command with RSnsc to get a list of all the options and flags.
Rsync simplifies the whole file transfer process by offering a robust, versatile, and flexible tool compared to alternatives like SCP.
RSync is great for maintenance operations, backups, and general file operations between local and remote machines.