当前位置:网站首页>Rsync remote synchronization (incremental backup)
Rsync remote synchronization (incremental backup)
2022-07-19 02:48:00 【For whom do the stars change】
1、rsync Service description
The configuration file : /etc/rsyncd.conf
Default port :tpc 837
Start the service :rsync --daemon
Out of Service :kill $(cat /var/run/rsyncd.pid)
Check the port :netstat -anpt | grep rsync
To restart the port, stop the port first and then start the port
2、 To configure rsync The source server
(1) Set up on the server /etc/rsyncd.conf The configuration file
vim /etc/rsyncd.conf
uid = nobody
gid = nobody
use chroot = yes ( Locked in the source directory )
address = 192.168.1.10 ( Monitor address )
port 873 ( Listening port )
log file = /var/log/rsyncd.log ( Log file location )
pid file = /var/run/rsyncd.pid ( Store process ID File location of )
hosts allow = 192.168.1.0/24 ( The client address allowed to access )
[wwwroot] ( Shared module name )
path = /var/www/html ( The actual path to the source directory )
comment = Document Root of 11111111 ( remarks )
read only = yes ( Is it read-only )
dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2 ( File types that are no longer compressed during synchronization )
auth users = backuper ( Authorized account )
secrets file = /etc/rsyncd_users.db ( Data file for storing account information )
(2) Create data file for backup account
mkdir -p /var/www/html/ ( Under this directory are the files to be backed up )
touch /var/www/html/1.txt
vim /etc/rsyncd_users.db
( Add account password )
backuper:123 ( The user is backuper, The password for 123)
chmod 600 /etc/rsyncd_users.db ( Configure read-only permissions )
ls -ld /var/www/html/ ( View permissions )
(3) start-up rsync Service program
rsync --daemon ( start-up rsync)
netstat -anpt | grep rsync ( see rsync port )
3、 Use rsync Backup tools
(1) Configure the representation of the source
Download the client to root Under the table of contents
rsync -avz [email protected]::wwwroot /root
Input backuper password
Download the client to myweb Under the table of contents
mkdir /myweb ( Create directory )
rsync -avzH --delete [email protected]::wwwroot /myweb
Input backuper password
(2) Automatically rsync Backup
vim /etc/server.pass ( preservation backuper password )
( Add password )
123
chmod 600 /etc/server.pass ( Add permissions )
crontab -e
( add to )
30 22 * * * /usr/bin/rsync -az --delete --password-file=/etc/server.pass [email protected]::wwwroot /myweb ( Every night 10 Point semi-automatic backup , The backup file is in myweb)
4、inotify+rsync Real time synchronization
inotify Notification interface , You can monitor changes in the file system .( Install... On the client , Can only go up )
(1) adjustment inotify Kernel parameters
vim /etc/sysctl.conf
( add to )
fs.inotify.max_queued_events = 16384
fs.inotify.max_user_instances = 1024
fs.inotify.max_user_watches =1048579
sysctl -p
(2) install inotify-toosl, You need to insert the disc first ,
tar zxf inotify-tools-3.14.tar.gz -C /usr/src/
cd /usr/src/inotify-tools-3.14/
./configure && make && make install
(3) Test monitoring directory
mkdir -p /var/www/html
inotifywait -mrq -e modify,create,move,delete /var/www/html/ ( You can't stop by force )
New terminal stay /var/www/html New file , Return to the original terminal to view ,
(4) Write triggered synchronization scripts
vim /opt/inotify_rsync.sh
( add to )
#!/bin/bash
INOTIFY_CMD="inotifywait -mrq -e modify,create,move,delete /var/www/html/"
RSYNC_CMD="rsync -azH --delete --password-file=/etc/server.pass /var/www/html/ [email protected]::wwwroot"
$INOTIFY_CMD | while read DIRECTORY EVENT FILE
do
$RSYNC_CMD
done
chmod +x /opt/inotify_rsync.sh
echo '/opt/inotify_rsync.sh' >> /etc/rc.local
(5) Configuration on the server
vim /etc/rsyncd.conf
take read only = yes Change it to
read only =no ( Set the permission to upload files , Have write permission )
chmod 777 /var/www/html ( Modify the permissions of the directory itself )
kill $(cat /var/run/rsyncd.pid)
rsync --daemon ( Stop service and start service )
(6) Execute script to test
/opt/inotify_rsync.sh ( Client execution script )
stay /var/www/html/ create a file
ls /var/www/html/ ( Check whether the file is uploaded on the server )
边栏推荐
- shell脚本之条件语句
- Brief introduction of Feature Engineering and its implementation of sklearn
- Usage instructions for MDK keil/arm printf
- shell脚本之循环语句与函数
- A preliminary study of MySQL
- HCIA_OSPF实验
- [solved] after referring to the local MySQL and forgetting the password, [server] --initialize specified but the data directory has files in it Aborti
- Leetcode 198:House Robber
- String Full Permutation Problem
- echo -e用法
猜你喜欢
squid代理服务部署
Swing swing ~ firewall
单片机之数码管秒表的动态显示
How to add software shortcuts to the right mouse button list
Firewall firewall
Response assertion of JMeter interface test
Use JMeter to test services based on websocket protocol
了解网络命名空间
二进制安装kubernetes 1.24.1
[solved] after referring to the local MySQL and forgetting the password, [server] --initialize specified but the data directory has files in it Aborti
随机推荐
Common English business mail phrases
OSPF综合实验
ENSP静态路由实验
MySQL backup and recovery
Traversal of binary tree
Plant a seed and grow into a towering b+ tree ten years later
Understand inheritance, polymorphism, abstraction and their concepts
Shell script case branch statement, pick the max address of anonymous login FTP
RHCE8学习指南 第4章 获取帮助
Bladex - a well-designed microservice architecture
Swing swing ~ firewall
MySQL数据库安装
C语言回调函数 & sprinf 实际应用一例
Dynamic programming problem - Small Soldiers rush forward
DHCP原理与配置
Leetcode 322: coin change - Dynamic Planning
MySQL差删改查用户登录修改密码
正则表达式
Arm cross compiler naming rules
Firewalld 防火墙