Backup copies should play an important role in your server planning. In­di­vidu­al backups can be set up and performed quickly using the free syn­chron­isa­tion tool or the rsync protocol.

Cloud Backup powered by Acronis
Mitigate downtime with total workload pro­tec­tion
  • Automatic backup and easy recovery
  • Intuitive schedul­ing and man­age­ment
  • AI-based threat pro­tec­tion

How to set up rsync backups on Linux servers

To use rsync on Linux operating systems, install the protocol in the package with the same name and create your backups using terminal commands. In the following section, we will use Ubuntu to show you the most important steps for setting up backup processes using rsync. We’ve also included practical examples as well.

Rsync is already installed in Ubuntu by default. If this is not the case, use the following command to install it:

sudo apt-get install rsync
bash

If rsync is installed, you can use terminal commands to specify the source and des­tin­a­tion dir­ect­or­ies and the backup options. The re­spect­ive source directory and the directory where rsync should store the backup copy must be specified as the source and des­tin­a­tion paths. The standard mode (‘Archive’) is executed as follows, for example:

rsync -a source directory target directory
bash
Tip

Use the test run -n to check the cor­rect­ness of the specified para­met­ers and dir­ect­or­ies. Incorrect entries can, in the worst case, lead to data loss. If some files are not copied as they should be, this is often due to a lack of access rights. If this happens, try executing the command as an ad­min­is­trat­or with sudo in front of it.

VPS Hosting
VPS hosting at un­beat­able prices on Dell En­ter­prise Servers
  • 1 Gbit/s bandwidth & unlimited traffic
  • Minimum 99.99% uptime & ISO-certified data centres
  • 24/7 premium support with a personal con­sult­ant

Five examples for using rsync backup

Once you know the fun­da­ment­al commands, rsync is an out­stand­ing tool for copying files and creating backups. You can either test and apply in­di­vidu­al command setups or use proven com­bin­a­tions of the available rsync para­met­ers. We have sum­mar­ised five popular ways to carry out rsync backups in the following sections.

Standard backup with archive mode

The archive mode copies all files from the source directory to the target directory including all sub­dir­ect­or­ies. All au­thor­isa­tions, time stamps and device data are retained. This is the ideal and simplest solution in many cases as it combines various options in a single parameter. If you combine the mode with the -v parameter, you will also receive com­pre­hens­ive status in­form­a­tion during the backup process.

rsync -av Source directory Target directory
bash

The re­spect­ive source directory and the directory in which rsync should store the backup copy must be specified as the source and target path.

Identical copy of the source directory

Not only can rsync transfer files from A to B, it can also make identical copies of folders or entire dir­ect­or­ies. After standard archival, the files that were in the target folder before the rsync backup took place (but are not in the source folder) are deleted.

rsync -av --delete Source directory Target directory
bash

rsync backup excluding files of a specific format

If you want to run an rsync backup excluding files in a specific format, you can use the --exclude command to do so. The parameter allows you to define an in­di­vidu­al character pattern that rsync uses as an indicator to ignore a file. The following sample code excludes .txt files.

rsync -av --exclude'*.txt' Source directory Target directory
bash

Backing up files with a minimum or maximum size

If, instead of a specific character pattern, you want the file size to influence the exclusion of specific files in an rsync backup, you can use the --max-size and --min-size para­met­ers. If you use the following command, only files ranging from at least 10 MB to at most 100 MB are copied:

rsync -av --min-size=10MB --max-size=100MB Source directory Target directory
bash

Backup including character format con­ver­sion

You may have to convert files into a different character format in the target directory. If you want to transfer data from a Mac to a Linux server, for example, you’ll want to include character format con­ver­sion. Apple devices use UTF8-MAC by default, which is not available on Linux systems and would cause problems with special char­ac­ters. The --iconv option lets you easily adapt the character encoding as part of the rsync backup process (in the example below, from UTF8-MAC to UTF8):

rsync -av --iconv=UTF8-MAC,UTF8 Source directory Target directory
bash

Overview of the most important rsync backup options

You can define the in­di­vidu­al settings for your rsync backups using the different options, which can be ab­bre­vi­ated by letter or written out in full. The following table sum­mar­ises the most important para­met­ers, which can be combined with each other as required:

Option Function
-r, --recursive rsync backup takes all sub­dir­ect­or­ies into account
-u, --update In­struc­tion to skip files in the target directory that are newer than those in the source directory
-c, --checksum Dis­tin­guish source and target files based on checksums
-l, --links Symbolic links are copied as such (and not as files)
-p, --perms File per­mis­sions are retained
-g, --group Group file per­mis­sions are retained
-t, --times File time stamps (last change) are retained
-o, --owner File owners are retained (only if ad­min­is­trat­ors)
-D, --devices Device data is retained
-z, --compress Automatic com­pres­sion of the trans­ferred files
--compress-level=NUM De­term­ines the com­pres­sion level; values (‘NUM’) between 0 (no com­pres­sion) and 9 (maximum com­pres­sion) are possible
-v, --verbose More com­pre­hens­ive details during the backup processes
-q, --quiet Hide all details on the backup process (except error messages)
-a, --archive Archive mode used as standard mode and identical to the option com­bin­a­tion — rlptgoD
-n, --dry-run Test run in which no actual changes are made
-h, --help Auxiliary menu (can only be used without in­dic­at­ing source and target dir­ect­or­ies or other arguments)
--bwlimit=KBPS Restrict bandwidth (kilobytes per seconds); e.g. --bwlimit=30 (limit of 30 kbit/s)
--exclude=SAMPLE Exclude a pattern from syn­chron­isa­tion; e.g. --exclude sample folder (the ‘sample folder’ folder is not syn­chron­ised.)
--delete Delete all files that are in the target directory but not in the source directory
--progress Show the duration of the rsync backups and the transfer speed
--list-only List files instead of a backup
--stats Com­pre­hens­ive report on the trans­ferred data (number, size)
--max-size=SIZE Define a maximum file size; e.g. --max-size=10MB (only files with a size up to 10 MB are trans­ferred.)
--ignore-errors Prevent can­cel­la­tion of the backup process in the event of an error
Go to Main Menu