Real-time synchronization between inotify and rsync
1. Build rsync server
Systemctl start rsyncd
Systemctl enable rsyncd
Systemctl status rsyncd
Ss-ntl | grep 873
Rpm-ql rsync
two。 Modify the configuration file
Vi / etc/rsyncd.conf
Uid = root
Gid = root
Use chroot = no
Max connections = 0
Ignore errors
Exclude = lost+found/
Log file = / var/log/rsyncd.log
Pid file = / var/run/rsyncd.pid
Lock file = / var/run/rsyncd.lock
Reverse lookup = no
Hosts allow = 192.168.8.0 Compact 24 # client IP
[backup]
Path = / backup/
Comment = backup
Read only = no
Auth users = rsyncuser
Secrets file = / etc/rsync.pass
3. Create a rsync backup server directory
Mkdir / backup
The server generates a verification file
Echo "rsyncuser:magedu" > / etc/rsync.pass
Chmod 600 / etc/rsync.pass
server-side preparation directory
Mkdir / backup
The server starts the rsync service
Rsync-daemon can join / etc/rc.d/rc.local to realize boot
Systemctl start rsyncd CentOS 7
Client configuration password file
Echo "magedu" > / etc/rsync.pass
Chmod 600 / etc/rsync.pass
Client
Turn on inotify
Yum-y install inotify-tools
4. Client test synchronization data
Rsync-avz-- password-file=/etc/rsync.pass / data/backup rsyncuser@rsync server IP::backup
5. Client create inotify_rsync.sh script
Vim inotify_rsync.sh #! / bin/bash
SRC='/data/backup/'
DEST='rsyncuser@rsync server IP::backup'br/ > #! / bin/bash
SRC='/data/backup/'
DEST='rsyncuser@rsync Server IP::backup'
Do
FILEPATH=$ {DIR} ${FILE}
Rsync-az-- delete-- password-file=/etc/rsync.pass $SRC $DEST &
Echo "At ${TIME} on ${DATE}, file $FILEPATH was backuped up via rsync"
/ var/log/changelist.log
Done
Chmod + x inotify_rsync.sh
Start the background monitoring process
6.sh inotify_rsync.sh &
Ps-ef | grep inotify_rsync
Note: both hosts must enable ssh secret-free login, allowing clients to distribute data to rsync servers.