Operations 12 min read

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

This guide walks through configuring rsync and inotify on multiple Linux hosts to achieve real‑time backup of NFS static resources, covering host preparation, rsync daemon setup, password handling, daemon activation, inotify‑driven monitoring scripts, and verification of successful synchronization.

Raymond Ops
Raymond Ops
Raymond Ops
How to Set Up Real‑Time NFS Backup with inotify and rsync

Task Requirements

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

Architecture diagram 1
Architecture diagram 1
Architecture diagram 2
Architecture diagram 2

Implementation Steps

1. Set up rsync on rsync-test-241

1.1 Install rsync

[root@rsync-test-241 ~]# yum install rsync -y

1.2 Edit /etc/rsyncd.conf

# vim /etc/rsyncd.conf
# cat /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/

Key configuration parameters:

Parameter

Description

uid = rsync

Run rsync daemon as user

rsync

gid = rsync

Run rsync daemon as group

rsync

use chroot = no

Disable chroot for internal network sync

max connections = 200

Maximum concurrent connections

timeout = 300

Close idle connections after 300 seconds

pid file = /var/run/rsyncd.pid

File storing daemon PID

lock file = /var/run/rsync.lock

Lock file for connection limiting

log file = /var/log/rsyncd.log

Log file location

[backup-nfs] / path = /backup/

Backup module and directory

read only = false

Allow write access

hosts allow = 172.16.1.0/24

Whitelist of allowed client networks

hosts deny = 0.0.0.0/32

Blacklist (default deny)

auth users = rsync_backup

Virtual user for authentication

secrets file = /etc/rsync.password

Password file for the virtual user

1.3 Create rsync user, directory and password file

# useradd rsync -s /sbin/nologin -M
# id rsync
uid=1000(rsync) gid=1000(rsync) groups=1000(rsync)

# mkdir /backup
# chown -R rsync.rsync /backup/
# ls -ld /backup/
drwxr-xr-x 2 rsync rsync ... /backup/

# echo "rsync_backup:mima666" > /etc/rsync.password
# chmod 600 /etc/rsync.password

1.4 Enable and start rsync daemon

# systemctl start rsyncd
# systemctl enable rsyncd

1.5 Verify rsync service

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

2. Install and run 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 synchronization

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

Options:

-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 monitoring script

#!/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) event $line" >> /var/log/rsync.log 2>&1
done

3.3 Run script in background

# bash rsync_nginx.sh &

4. Verify synchronization

4.1 Modify a file on web-test-207

# cd /usr/share/nginx/html/
# vim 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 causes are firewall rules, NFS permission settings, or network connectivity problems.

OperationsLinuxsysadminrsyncnfsinotifyreal-time backup
Raymond Ops
Written by

Raymond Ops

Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.

0 followers
Reader feedback

How this landed with the community

login 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.