rsync+inotify Synchronizing backup MYSQL data
Rsync has the advantages of high security, fast backup, support of incremental backup, and so on, which can solve the requirement of low real-time data backup. , but Rsync is not able to monitor and synchronize data in real time. . Inotify is a powerful, fine-grained, asynchronous file system event monitoring mechanism, through Inotify can monitor the file system to add, delete, modify, move and other subtle events .
Lab Environment: Backup Side 1 92.168.1.123 (rsync server)
Backup Source 192.168.124(rsync client inotify mysql)
Experimental principle: Using INotify to monitor MySQL database data directory:/usr/local/mysql/data
, and then use Rsync to synchronize the changed data to the/var/mysqldata on the backup side.
A. configuration of backup-side services
1) Verify that rsync is installed and that most Linux distributions install rsync by default
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/76/22/wKioL1ZLRrqT4gewAAAKUUdYr1U309.png "style=" float: none; "title=" 1.PNG "alt=" Wkiol1zlrrqt4gewaaakuudyr1u309.png "/>
2) manually create a configuration for rsync file
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/76/25/wKiom1ZLRmiwShN1AAAGeKlKZUM480.png "style=" float: none; "title=" 2.PNG "alt=" Wkiom1zlrmiwshn1aaageklkzum480.png "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/76/22/wKioL1ZLRrrT3dHeAAA0_u7ASL4375.png "style=" float: none; "title=" 3.PNG "alt=" Wkiol1zlrrrt3dheaaa0_u7asl4375.png "/>
3) build rsync username and password files , and Authorized for/etc/rsync.password
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/76/25/wKiom1ZLR5-CL7vHAAAR2qoW9tY703.png "style=" float: none; "title=" 5.PNG "alt=" Wkiom1zlr5-cl7vhaaar2qow9ty703.png "/>
4) start the rsync service
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/76/25/wKiom1ZLRmnB_KZJAAAaGtm2JuA383.png "style=" float: none; "title=" 4.PNG "alt=" Wkiom1zlrmnb_kzjaaaagtm2jua383.png "/>
The backup-side service configuration is complete
two. Backup Source Configuration
1) Set the rsync client password file to set the password file's permissions to
The client only needs to set the Rsync sync password, without resetting the user name
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/76/23/wKioL1ZLR_GSXTedAAAPQ7wtqsE214.png "style=" float: none; "title=" 7.PNG "alt=" Wkiol1zlr_gsxtedaaapq7wtqse214.png "/>
2) Installing INotify
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/76/25/wKiom1ZLR6DxA51mAAAPiS5sSLY211.png "style=" float: none; "title=" 6.PNG "alt=" Wkiom1zlr6dxa51maaapis5ssly211.png "/>
3) write a run monitoring script. to ensure that the/usr/local/mysql/data directory is automatically synchronized, after the installation completes inotify, write a inotify script.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/76/23/wKioL1ZLR_Kw6_xcAAAFhn28r8I542.png "style=" float: none; "title=" 8.PNG "alt=" Wkiol1zlr_kw6_xcaaafhn28r8i542.png "/>
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/76/22/wKioL1ZLRruTUJeUAABAUtXqvv8310.png "style=" float: none; "title=" 9.PNG "alt=" Wkiol1zlrrutujeuaabautxqvv8310.png "/>
three. Test Effect
1) run the written inotify.sh script
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/76/25/wKiom1ZLRmqA6k92AAAE9y-80aA330.png "style=" float: none; "title=" 12.PNG "alt=" Wkiom1zlrmqa6k92aaae9y-80aa330.png "/>
Inserting data in MySQL at the same time
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/76/22/wKioL1ZLRrvDNYdcAAAfvnY0Hdw805.png "style=" float: none; "title=" 11.PNG "alt=" Wkiol1zlrrvdnydcaaafvny0hdw805.png "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/76/22/wKioL1ZLRryC6IDnAABkVq9L1aE468.png "style=" float: none; "title=" 13.PNG "alt=" Wkiol1zlrryc6idnaabkvq9l1ae468.png "/>
You can see that the script is in effect
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/76/25/wKiom1ZLRmqxItNxAABgpu_QDNU302.png "style=" float: none; "title=" 14.PNG "alt=" Wkiom1zlrmqxitnxaabgpu_qdnu302.png "/>
2) View the/var/mysqldata on the backup side to see the synchronized data
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/76/23/wKioL1ZLRrzAtz8eAAAkJOCbW3A720.png "style=" float: none; "title=" 15.PNG "alt=" Wkiol1zlrrzatz8eaaakjocbw3a720.png "/>
This article is from the "10319031" blog, please be sure to keep this source http://10329031.blog.51cto.com/10319031/1713842
Rsync+inotify synchronizing backup MySQL data