Operations 10 min read

How to Set Up Real‑Time NFS Static Asset Backup with inotify and rsync

This step‑by‑step guide shows how to install and configure rsync as a daemon, create secure authentication, deploy inotify‑tools on an NFS server, and use a Bash script to achieve real‑time backup of static assets across multiple Linux hosts.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How to Set Up Real‑Time NFS Static Asset Backup with inotify and rsync

1. Install and configure rsync daemon on the backup server

On rsync-test-241 install rsync, then edit /etc/rsyncd.conf with the following key parameters:

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

use chroot = no : disable chroot for simplicity.

max connections = 200 : allow up to 200 concurrent connections.

log file = /var/log/rsyncd.log : log activity.

hosts allow = 172.16.1.0/24 : whitelist the internal network.

auth users = rsync_backup and secrets file = /etc/rsync.password : enable password‑based authentication.

[backup-nfs] module with path = /backup/ and read only = false.

# yum install rsync -y
# vim /etc/rsyncd.conf   # (add the configuration above)
# systemctl start rsyncd
# systemctl enable rsyncd

2. Create the rsync user and authentication files

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

3. Verify the rsync service

# systemctl status rsyncd
# netstat -tnlp | grep rsync   # should show listening on port 873

4. Install rsync on the NFS source server and perform a test sync

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

The options mean: -a: preserve file attributes. -v: verbose output. -z: compress data during transfer. -P: show progress.

5. Deploy inotify‑tools on the NFS server to trigger real‑time sync

# yum install inotify-tools -y

Create 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

Run the script in the background:

# bash rsync_nginx.sh &

6. Validate the end‑to‑end synchronization

Modify a file on web-test-207 (e.g., index.html) and then check:

Log on nfs-test-231 ( tail -f /var/log/rsync.log) shows the inotify event.

On rsync-test-241 the file appears under /backup with the same content.

7. Common troubleshooting

If synchronization fails, verify:

Firewalls are disabled or ports opened (TCP 873).

NFS export permissions allow the client.

Network connectivity between the three hosts.

Architecture diagram
Architecture diagram
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.

LinuxSystem AdministrationrsyncNFSinotifyreal-time backup
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

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.