Rsync

Rsync is a free Linux-based utility for transferring and synchronizing files between remote and local servers.

Rsync stands for "remote synchronization". Rsync is a free Linux-based utility for transferring and synchronizing files between remote and local servers.

It uses algorithms to minimize the time used to copy data by only moving portions that have only been changed.

Use cases for Rsync

Initially, Rsync was meant for file copying. Rsync is now mainly used to back up data to a server, including restoring the data if necessary.

Let's look at some other uses of Rsync:

  • Resume uploads. Uploads can resume even when there is a disconnection problem.
  • Resume downloads. Downloads can resume even when there is a disconnection problem.

Advantages of Rsync

Using Rsync as a syncronization tool has many advantages:

  • Rsync is done through command line, no UI
  • Rsync has a detailed documentation
  • Rsync has support for various circumstances such as transferring files, resuming uploads & downloads
  • Rsync requires a relatively small amount of system resources
  • Rsync synchronizes servers

Example of Rsync commands

Let's start with the most basic command from Rync, that of of syncing directories.

$ rsync [OPTIONS] [PATH/TO/DIRECTORY1] [PATH/TO/DIRECTORY2]

Here's what it means:

  • OPTIONS:the different options of the commands to use, such as -v, -delete, -h
  • PATH/TO/DIRECTORY1:The directory to be copied
  • PATH/TO/DIRECTORY2The directory where the contents will be copied.

Here's another example.

Let's first create a dummy directory required for our example. This code will create a new directory titled Filename and create 500 files.

$ mkdir Filename
$ cd Filename
$ touch file{1..500}.md
$ ls

The ls command should give you this output:

Rsync create dummy folder and create 500 files

Now let's copy all of these 500 files from the Filename directory to the Downloads directory:

rsync -av /home/ubuntu/Filename /home/ubuntu/Downloads/

By omitting the trailing slash on Filename, the whole directory will be copied to the Downloads directory.

The output should be this:

Rsync copy folder to folder with av parameters

Now go to the Downloads folder and type ls to confirm that your Downloads directory has the new Filename folder:

$ cd /home/ubuntu/Downloads/
$ ls

Your Downloads folder should like this:

Rsync copy folder to folder test results