Operations 15 min read

Mastering Rsync: Build Reliable Backup Services and Optimize Data Transfer

Learn how to design and implement a robust Rsync backup service, covering backup fundamentals, Rsync basics, transfer modes, server deployment, configuration steps, and practical scenarios such as data push/pull, incremental sync, bandwidth limiting, and common troubleshooting tips.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Mastering Rsync: Build Reliable Backup Services and Optimize Data Transfer

Rsync Backup Service Practice

1. Backup Basics Overview

1.1 What is Backup

Backup is copying files to another location to prevent data loss. It ensures rapid recovery when data is lost and reduces damage. Methods include file backup, snapshot backup, binlog backup, and cluster solutions.

File backup: store a copy on external disk or network drive; simple for personal or small‑business use.

Snapshot backup: point‑in‑time full copy, often incremental (e.g., VMware snapshots).

Binlog backup: record of database operations, allowing rollback of accidental deletions.

Cluster solution: multiple identical nodes; loss of one node's data does not affect overall availability.

1.2 Why Backup

Data is critical.

Prevents data loss.

Facilitates quick recovery.

1.3 Can You Skip Backup

For non‑critical data such as temporary files, log files, or cache, backup may be omitted.

1.4 How to Backup

Full backup (inefficient, high space and bandwidth) vs. incremental backup (more efficient, saves space and bandwidth).

1.5 Backup Tools

Local backup: cp Remote backup: scp,

rsync

2. Rsync Overview

2.1 What is Rsync

rsync

is a remote synchronization tool that supports both incremental and full backups.

Official address: (link omitted)

Listening port: 873

Running mode: client/server

2.2 Rsync Sync Modes

Push: all hosts push local data to the Rsync server (suitable for small data sets, can be slow).

image.png
image.png

Pull: the Rsync server pulls data from all hosts (higher load on the backup server).

image.png
image.png

2.3 Rsync Application Scenarios

Large‑scale server backup and off‑site backup.

image.png
image.png
image.png
image.png

3. Rsync Transfer Modes

Local mode

Remote mode

Daemon mode

3.1 Local Transfer

Local transfer works like the cp command.

Syntax:

rsync [OPTION...] SRC... [DEST]
[root@backup ~]# rsync -avz /etc/passwd /tmp/

3.2 Remote Transfer

Remote transfer uses SSH, similar to scp. Pull syntax:

# Pull example
rsync -avz [email protected]:/etc/hostname ./

Push syntax:

# Push example
rsync -avz /backup/ [email protected]::backup/

3.3 Daemon Mode

Daemon mode uses its own protocol without system users, providing a more secure transfer.

# Pull example (daemon)
rsync -avz [email protected]::backup/ /mnt/
# Push example (daemon)
rsync -avz /mnt/ [email protected]::backup/

3.4 Common Options

-a   archive mode (equivalent to -rlptgoD)
-v   verbose output
-z   compress data during transfer
-r   recurse into directories
-t   preserve modification times
-o   preserve owner
-p   preserve permissions
-g   preserve group
-l   preserve symlinks
-P   show progress during transfer
--exclude=PATTERN   exclude files matching pattern
--bwlimit=100      limit bandwidth
--partial          keep partially transferred files
--delete           delete extraneous files from destination

4. Rsync Service Deployment

4.1 Install Rsync on Server

yum -y install rsync

4.2 Configure /etc/rsyncd.conf

uid = rsync
gid = rsync
port = 873
fake super = yes
use chroot = no
max connections = 200
timeout = 600
read only = false
list = false
auth users = rsync_backup
secrets file = /etc/rsync.passwd
log file = /var/log/rsyncd.log

[backup]
comment = welcome backup!
path = /backup

4.3 Initialize Server

Create rsync user (no login, no home directory).

Create backup directory (e.g., /backup) and set ownership to the rsync user.

Create password file /etc/rsync.passwd with permissions 600.

Start rsync daemon and enable it at boot.

Verify the service is listening on port 873 (e.g., netstat -lntp).

4.4 Configure Client

Option 1: create a password file (e.g., /etc/rsync.pass) with 600 permissions.

Option 2: set environment variable RSYNC_PASSWORD for scripts.

5. Rsync Practical Scenarios

5.1 Push and Pull Data

# Push all contents of /backup to the server
export RSYNC_PASSWORD=sun
rsync -avz /backup/ [email protected]::backup/
# Pull the "backup" module from the server to local /backup
export RSYNC_PASSWORD=sun
rsync -avz [email protected]::backup /backup/

5.2 Zero‑Difference Synchronization

# Pull with delete (make local identical to server)
export RSYNC_PASSWORD=sun
rsync -avz --delete [email protected]::backup/ /data/
# Push with delete (make server identical to local)
export RSYNC_PASSWORD=sun
rsync -avz --delete /data/ [email protected]::backup/

5.3 Bandwidth‑Limiting Scenario

# Limit transfer to 1 MB/s to avoid saturating network
export RSYNC_PASSWORD=sun
rsync -avz --bwlimit=1 [email protected]::backup/ /data/

5.4 Common Issues

Using a system user for Rsync is insecure.

Using a normal user may cause permission problems during transfer.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Linuxdata synchronizationBackuprsync
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.