当前位置:网站首页>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 )边栏推荐
- Understanding of array and bubbling
- PXE automated installation
- 二进制安装kubernetes 1.23.2
- Getting to know Alibaba cloud environment construction for the first time: unable to connect remotely, and having been in the pit: the server Ping fails, FTP is built, the server builds the database,
- 二进制安装kubernetes 1.24.1
- RHCE8学习指南 第7章 服务管理
- Let's learn about awk~
- Swing swing ~ firewall
- The difference between cookies and sessions
- Gzip的动态压缩和静态压缩详解
猜你喜欢

Conditional statement of shell script

Shell脚本整数值比较、逻辑测试、if语句、提取性能监控指标

Services for NFS

PXE自动化安装

ctfhub--ssrf

shell脚本之条件语句

Shell编程规范与变量

Swing swing ~ firewall

Getting to know Alibaba cloud environment construction for the first time: unable to connect remotely, and having been in the pit: the server Ping fails, FTP is built, the server builds the database,

HCIA静态综合实验
随机推荐
Reflection and Discussion on time management methods
Common English business mail phrases
安装.NET提示“无法建立到信任根颁发机构的证书链”(方法简单有下载地址)
Shell programming specifications and variables
DNS域名解析
Lintcode 366:fibonacci Fibonacci sequence
Find() (if the name is used by too many people, I will add words)
HCIA静态综合实验
Leetcode 70:Climbing Stairs
HCIA总结
时间管理方法的反思与探讨
静态路由综合实验
shell脚本接收和返回参数
数组、冒泡的认识
Firewall firewall
通过Xshell7使用rz,sz命令上传下载文件
HCIA_NAT实验
Graduation thesis word skills Collection
Zabbix6.0通过iDRAC,IMM2监控DELL,IBM服务器硬件
Brief introduction of Feature Engineering and its implementation of sklearn