For the complete documentation index, see llms.txt. This page is also available as Markdown.

37.1 Rsync Data Synchronization

Rsync (Remote Sync) is an efficient file synchronization tool co-developed by Andrew Tridgell and Paul Mackerras. Rsync uses an incremental transfer algorithm that only transmits the differences between files, which can significantly reduce network bandwidth consumption and shorten synchronization time. It is a commonly used tool for system backup and data mirroring.

Environment Overview

Before starting the configuration, first clarify the roles of the two servers in this section.

Rsync Architecture Diagram
  • Server A (initiator, client): 192.168.179.128

  • Server B (sync source, server): 192.168.179.150

Design objective: synchronize data from Server B to Server A, i.e., B (server) → A (client), to achieve a complete data mirror.

Server B (Sync Source) Configuration

First, configure the sync source server, i.e., Server B.

Installing rsync

Install rsync on Server B. There are two installation options:

  • Install using pkg:

  • Or install using Ports:

  • View installation information

Sync Directory Preparation

File structure:

Server Main Configuration File

Edit the /usr/local/etc/rsync/rsyncd.conf file and write:

Tip

The 192.168.179.128 and 192.168.179.150 in the above example are placeholders and need to be replaced with actual values.

Creating the Password File for Authorized Backup Account Authentication (Server)

  • Edit the /etc/rsyncd_users.db file and write:

Note

The server password file should contain the mapping between usernames and passwords. The format is authorized_account_username:password.

  • Restrict the data file permissions, otherwise it will cause errors:

Set the rsync user database file permissions to be readable and writable only by the owner.

Service Startup Configuration

Service Port Verification

View the network ports used by the rsync service and the corresponding processes:

Server A (Initiator) Configuration

Please refer to the steps above to install rsync.

Local Backup Directory Configuration

Create the local backup directory /home/testBackUp/ and set the appropriate permissions:

Sync Operation (Password Input Method)

Synchronize files to the local backup directory /home/testBackUp/, requiring manual password input.

testcom is the sync module name defined in the /usr/local/etc/rsync/rsyncd.conf file, corresponding to the directory on the server.

Appendix: Specifying a Password File Method

Create a password file for authorized backup account authentication (client).

  • Edit the client's /etc/rsyncd_users.db file, writing only the password:

  • Restrict permissions, otherwise it will cause the error ERROR: password file must not be other-accessible.

Set the rsync user database file permissions to be readable and writable only by the owner.

Note

The client password file should contain only the password itself, one per line.

Execute the sync command.

Use rsync to synchronize the remote testcom module to the local backup directory, display sync progress, and specify the password file.

Sync Result Verification

List detailed file information in the local backup directory:

References

  • Tridgell A, Mackerras P. The rsync algorithm[EB/OL]. (1998-11-09)[2026-04-17]. https://rsync.samba.org/tech_report/. The original technical report on the rsync algorithm, co-authored by the two authors.

Last updated