A fast incremental backup tool [Remote Sync, remote synchronization]
remote disaster backup function
* supports local replication, or synchronization with other SSH, rsync hosts
Configure the rsync source server [rsync synchronization source]
*Refers to the remote server of the backup operation, also known as the backup source
The web server has a local server, and the IDC computer room has a backup host (remote synchronization). The specific user who is the synchronization source or the initiator can customize it.
*Downlink: Initiator has read permission
*Uplink: Write permission is required
*Uplink is mostly configured as ssh mode
environment:
Two centos:
Make sure rsync is installed on both
Main server ip 192.168.254.11
client ip 192.168.254.20
Here I only back up an http directory and synchronize it to the client. In fact, you can synchronize any directory, and the / directory is the same
The service of httpd is required to synchronize the two hosts. This is to synchronize the files in /var/www/html
Notice:
In fact, any directory can be synchronized, here is just for experiment
We write files in /var/www/html/ on the main server
touch /var/www/html/{1..4}.txt
In addition to these four files, there is an other directory
main configuration
to the server
cat /etc/passwd |grep "^nobody"
If there is no nobody user, create one
vim /etc/rsyncd.conf
to write
uid = nobody gid = nobody # 任何人 use chroot = yes address = 192.168.254.11 #服务器 port 873 # 端口号 log file = /var/log/rsyncd.log # 日志 pid file = /var/run/rsyncd.pid # 储存pid,等会用于关服务 hosts allow = 192.168.254.0/24 # 允许那个网段去同步 [http] # 名字 path = /var/www/html # 同步的根目录 comment = 123123 # 解释可以随便写 read only = yes dont compress = *.gz *.bz2 *.tgz *.zip *.rar *.z # 同步时不再压缩的文件 auth users = tarro # 允许的用户 secrets file = /etc/user_list # 用户路径
vi /etc/user_list
User in the front: Password in the back
chmod 600 /etc/user_list
rsync --daemon
# start the service
kill $(cat /var/run/rsyncd.pid)
# close the service
Now on to the client
Nothing at all
rsync -avzH [email protected]::http /var/www/html
# Then enter the password
Synced now
Go to the main server and modify a few files casually
to the client
rsync -avzH --delete rsync://[email protected]/http /var/www/html
delete the old one and sync it
It is a bit troublesome to always enter the password, which also hinders our automatic backup at the point, and the use of scheduled tasks. We can write the password into a file, and it will be used simultaneously to find the password in the file, so we don’t have to enter it
Let's go to the server to modify the file
back to the client
vim /etc/server.pass
write the password in
rsync -avzH --delete --password-file=/etc/server.pass rsync://[email protected]/http /var/www/html
This time, we don't need to enter the password, and it will be synchronized directly.
Use crontab to test periodic synchronization
Then go to the server to modify the file
crontab -e
to write
30 22 * * * /usr/bin/rsync -az --delete --password-file=/etc/server.pass rsync://[email protected]/http /var/www/html/
# Execute the command at 10.30 every day
date -s 22:29:30
Change the time
Then it can be executed at the point