Use rsync service to achieve trigger automatic data synchronization through inotify

  Experimental topology: HK36 ( Server 192.168.2.102 )====HK46 (Client 192.168.2.190 )

  Experimental requirements: backup the HK46 /data/ directory to /backup/ of HK36

 

(1) The rsync service depends on the xinetd super service management, first install the xinetd service     

[root@HK36 ~]# yum -y install xinetd

(2) Enter rsync to modify the configuration file information, change disable = yes to no, restart the service, and check whether port 873 is up     

[root@HK36 ~]# service xinetd restart

Stopping xinetd:                                           [  OK  ]

Starting xinetd:                                           [  OK  ]

[root@HK36 ~]# netstat  -anptu | grep 873

tcp        0      0 :::873                      :::*                        LISTEN      2729/xinetd

(3) Create a non-system test user and give the user nobody permission to the directory /backup     

[root@HK36 backup]# vim /etc/rsyncd.conf

uid = nobody

gid = nobody

address = 192.168.2.102

pid = 873

host allow = 192.168.2.190

use chroot = yes

max_connetion = 5

pid file = /var/run/rsyncd.pid

lock file = /var/run/rsyncd.lock

log file = /var/log/rsyncd.log

motd file = /etc/rsyncd.motd

[backup]

path = /backup/

comment = data for backup

read only = no

auth users = gz

list = yes

[root@HK36 backup]# chown nobody:nobody /backup/

[root@HK36 backup]# vim /etc/rsyncd.motd Create login template file

welcome to backup data!

[root@HK36 backup]# vim /etc/rs.passwd create password

gz:ggrr50152412

(4) Test, create a backup directory test under HK46:     

[root@HK36 /]# mkdir /backup/

[root@HK46 /]# mkdir /data/

[root@HK46 data]# ls

22  55  a  aaaaa  erer  kd  s  test

[root@HK46 data]# rsync -avz  ./  --delete   [email protected]::backup 

image.png

(5) Upload inotify and unzip the installation     

[root@HK46 ~]# tar -xvf inotify-tools-3.14.tar.gz -C /usr/local/src/

[root@HK46 inotify-tools-3.14]#./configure --prefix=/usr/local/inotify-tools;make;make install

(6) Call the command directly     

[root@HK36 ~]# ln -s /usr/local/inotify-tools/bin/* /usr/bin/

[root@HK46 ~]# vim /root/passfile Create password file

ggrr50152412

[root@HK46 data]# chmod 600 /root/passfile and give 600 permission

(7) Test     

image.png

(8) Edit the script and give execute permission     

#!/bin/bash

backup_Server=192.168.2.102

/usr/bin/inotifywait -mrq --format '%w%f' -e create,close_write,delete /data/ | while read line

do

cd / data /

 rsync -az ./ --delete gz@$backup_Server::backup --password-file=/root/ passfile

done

[root@HK46 ~]# vim inotify.sh

image.png

image.png

image.png

 

(9) The test is successful     

image.png



Use the LAMP environment to build a wordpress forum: http://blog.51cto.com/13719714/2108415                                                                              


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324928276&siteId=291194637