Operations 11 min read

How to Set Up Real-Time NFS Backup with Inotify and Rsync on Linux

This step‑by‑step guide shows how to configure Linux servers for real‑time NFS static resource backup using inotify and rsync, covering host preparation, rsync daemon setup, user and password management, inotify script creation, and verification of synchronized files across multiple machines.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Set Up Real-Time NFS Backup with Inotify and Rsync on Linux

Task Requirements

1. Real‑time backup of static resources on an NFS server using inotify + rsync.

Host List

# External IP   Internal IP   Hostname
192.168.122.207 172.16.1.207 web-test-209
192.168.122.231 172.16.1.231 nfs-test-231
192.168.122.241 172.16.1.241 rsync-test-241

Architecture Diagram

1. Set up rsync on rsync-test-241

1.1 Install rsync

# yum install rsync -y

1.2 Modify configuration file /etc/rsyncd.conf

uid = rsync
gid = rsync
fake super = yes
use chroot = no
max connections = 200
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 172.16.1.0/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password

[backup-nfs]
comment = This is nfs backup!
path = /backup/

uid / gid : run rsync daemon as the rsync user.

use chroot = no : disable chroot for internal network sync.

max connections = 200 : maximum concurrent connections.

read only = false : allow read‑write access.

hosts allow / deny : whitelist and blacklist IP ranges.

auth users : virtual user for authentication.

secrets file : password file for the virtual user.

path : directory to be backed up.

1.3 Create user, directory and authentication file

# useradd rsync -s /sbin/nologin -M
# id rsync
# mkdir /backup
# chown -R rsync.rsync /backup/
# echo "rsync_backup:mima666" > /etc/rsync.password
# chmod 600 /etc/rsync.password

1.4 Start rsync service and enable at boot

# systemctl start rsyncd
# systemctl enable rsyncd

1.5 Verify rsync service

# systemctl status rsyncd
# ps -ef|grep rsync
# netstat -tnlp | grep rsync

2. Install rsync on nfs-test-231

2.1 Install rsync

# yum install rsync -y

2.2 Create password file

# echo 'mima666' > /etc/rsync.password
# chmod 600 /etc/rsync.password

2.3 Test rsync data sync

# rsync -avzP network_init.sh [email protected]::backup-nfs --password-file=/etc/rsync.password

Flags: -a preserve attributes, -v verbose, -z compress, -P show progress.

3. Deploy inotify on nfs-test-231

3.1 Install inotify‑tools

# yum install inotify-tools -y

3.2 Write script rsync_nginx.sh

#!/bin/bash
/usr/bin/inotifywait -mrq -e modify,delete,create,attrib,move /nfs-web-share/ | while read line
do
    rsync -a --delete /nfs-web-share/ [email protected]::backup-nfs --password-file=/etc/rsync.password
    echo "`date +%F\ %T`出现事件$line" >> /var/log/rsync.log 2>&1
done

3.3 Run script in background

# bash rsync_nginx.sh &

4. Verify synchronization

4.1 Update file on web-test-207

# cd /usr/share/nginx/html/
# vim index.html
# cat index.html

4.2 Check log on nfs-test-231

# tail -f /var/log/rsync.log

4.3 Check backup on rsync-test-241

# cd /backup/
# ls
# cat index.html

If the process fails, common reasons include firewall blocks, incorrect NFS permissions, or network connectivity issues; consult error messages for further troubleshooting.

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.

Linuxrsyncinotifyreal-time-syncNFS backup
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.