Installing RSYNC

Step-by-step guide for installing and configuring Remote Synchronization (RSYNC) for data synchronization.

rsync (Remote Synchronization) is a cross-platform command-line application for synchronizing data with minimal bandwidth usage. It is widely used for backup, migration, and mirroring data between servers.

For example, rsync can be used to transfer projects from web hosting to a VPS, synchronize directories between multiple dedicated servers, and maintain up-to-date copies of files within infrastructure.

Installing rsync

To install the rsync module on the server, run the corresponding commands depending on the operating system.

For CentOS:

yum -y install rsync

For Debian/Ubuntu:

sudo aptitude install rsync

Examples of using rsync

Synchronizing from a remote server to local

sudo rsync -avh --delete /var/www/ /root/backup/www/

This command synchronizes the contents of the /var/www/ directory with /root/backup/www/, deleting files that no longer exist in the source. This is useful for creating a directory mirror.

Synchronizing to a remote server

sudo rsync -avh --delete /var/www/ root@192.168.1.50:/root/backup/www/

In this example, files will be copied to a remote server via SSH. To perform synchronization, rsync must be installed on both servers.

Synchronizing from a remote server to local

sudo rsync -avh root@192.168.1.50:/var/www/ /root/backup/www/

This example shows synchronizing data from a remote server to a local machine. This is useful for transferring files from another server.

Synchronizing via SSH with a non-standard port

sudo rsync -avh -e "ssh -p 1111" root@192.168.1.50:/var/www/ /root/backup/www/

If the SSH server is configured to use a non-standard port, for example 1111, the -e parameter is used to specify the port. This example allows file synchronization through SSH on a different port.

Excluding directories

sudo rsync -avh --exclude='dir/' --exclude='dir/tmp/' /var/www/ /root/backup/www/

In this example, files from the dir and dir/tmp directories will be excluded from synchronization. This is useful if you want to exclude temporary or unnecessary data from backup.

Transferring files from a remote server (with removal of source)

sudo rsync -avh --remove-source-files root@192.168.1.50:/var/www/ /var/www/

This example copies files from a remote server and simultaneously removes them from the source directory. This is useful when migrating data from one server to another.

Copying MySQL database to another disk

sudo rsync -vrplogDtH --progress /var/lib/mysql/ /newhdd/var/lib/mysql/

This example is used to copy an entire MySQL database, including its structure and files. The --progress option is used to track the transfer progress.

Useful rsync parameters and flags

  • -v — verbose mode, which provides additional information about the copying process.
  • -r — recursive copying, used for copying directories.
  • -a — archive mode, preserves file permissions, symlinks, timestamps, and directory structure.
  • -b — backup mode, creates copies of modified files before replacing them.
  • -c — checksum verification, ensures that the data is synchronized correctly.
  • --delete — deletes files that no longer exist in the source folder.
  • -h — human-readable output, displaying file sizes in a user-friendly format (e.g., in megabytes).
  • -n — dry-run mode, which shows what will be done without making changes.
  • -p — preserves file permissions.
  • -z — compresses data during transmission, which helps reduce the amount of data being transferred.
  • -H — preserves hard links if present in the source data.
  • -x — restricts copying to a single file system.

For a complete list of available options, refer to the manual:

man rsync

Help

If you have any questions or need assistance, please contact us through the ticket system — we're always here to help!

Need help?Our engineers will help you free of charge with any question in minutesContact us