Rsync push-pull backup
Requirements:
Configuring rsync service data can be achieved by all equipment and prepare
the environment to prepare:
server
CentOS7.6 backup01
eth0: 10.0.0.41/24 eth1: 172.16.1.41/24
client
CentOS7.6 web01
eth0: 10.0.0.7/24 eth1: 172.16.1.7/24
Realization of ideas
install Rsync service> configuration server and client configuration file> backup needs
Step one:
server
Installation Rsync service
[root@backup ~]# yum install -y rsync
Installed:
rsync.x86_64 0:3.1.2-6.el7_6.1
Complete!
[root@backup ~]#
Step two:
Delete the contents of the original configuration file, modify the following
[root@backup ~]# vim /etc/rsyncd.conf #rsync的配置文件
uid = rsync #运行进程的用户
gid = rsync #运行进程的用户组
port = 873 #监听端口
fake super = yes #无需让rsync以root身份运行,允许接收文件的完整属性
use chroot = no #禁锢推送的数据至某个目录,不允许跳出该目录
max connections = 200 #最大连接数
timeout = 600 #超时时间
ignore errors #忽略错误信息
read only = false #对备份的数据设置可读写
list = false #不允许查看模块信息
auth users = rsync_backup #定义的虚拟用户,作为连接认证用户
secrets file = /etc/rsync.passwd #定义rsync服务用户连接认证密码文件路径
log file = /var/log/rsyncd.log #rsync的日志信息
#####################################
[wesley] #模块名称
comment = welcome to oldboyedu backup! #模块注释信息
path = /backup #定义接收备份数据目录
~
Step three:
Create System User rsync and does not allow users to log on to create a home directory
[root@backup ~]# id rsync
id: rsync: no such user
[root@backup ~]# useradd rsync -s /sbin/nologin -M
[root@backup ~]# tail -1 /etc/passwd
rsync:x:1000:1000::/home/rsync:/sbin/nologin
[root@backup ~]#
Step Four:
Create a backup directory, and authorized users as rsync owner
[root@backup ~]# mkdir /backup
[root@backup ~]# chown -R rsync.rsync /backup/
: Step Five
(use for client connection) rsync create a virtual user's user profile password
[root@backup ~]# echo "rsync_backup" >/etc/rsync.passwd
[root@backup ~]# chmod 600 /etc/rsync.passwd
[root@backup ~]#
Step Six:
After the configuration file is modified, restart the service and add the boot from Kai
[root@backup ~]# systemctl start rsyncd
[root@backup ~]# systemctl enable rsyncd
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.
[root@backup ~]#
Step 7:
Check rsync port
[root@backup ~]# netstat -lntup|grep rsync
tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 16635/rsync
tcp6 0 0 :::873 :::* LISTEN 16635/rsync
[root@backup ~]#
Above server configuration
Began to configure the client
Step one:
install Rsync service
[root@web01 ~]# yum install -y rsync
Installed:
rsync.x86_64 0:3.1.2-6.el7_6.1
Complete!
[root@web01 ~]#
Step two:
Create a virtual user's password permissions and authorization for the security permissions of 600
[root@web01 ~]# echo "123456" >/etc/rsync.passwd
[root@web01 ~]# chmod 600 /etc/rsync.passwd
[root@web01 ~]#
Client Configuration End
Test
Client Push everything under the etc directory to Rsync server
[root@web01 ~]# rsync -avz /etc/ [email protected]::wesley
Test Two
data service client pull Rsync wesley end module to a local directory data
[root@web01 cs]# rsync -avz [email protected]::wesley ./ --password-file=/etc/rsync.passwd
Local transmission
backup etc directory to the directory ./
[root@web01 cs]# rsync -avz /etc/ ./
Create a new file to achieve incremental backup
[root@web01 cs]# touch /etc/123.txt
[root@web01 cs]# rsync -avz /etc/ ./
sending incremental file list
./
123.txt
sent 43,989 bytes received 641 bytes 89,260.00 bytes/sec
total size is 27,224,604 speedup is 610.01
[root@web01 cs]#
Remote transmission
pull remote file
[root@web01 cs]# rsync -avz [email protected]:/etc/passwd ./
[email protected]'s password:
receiving incremental file list
passwd
sent 43 bytes received 448 bytes 196.40 bytes/sec
total size is 843 speedup is 1.72
[root@web01 cs]#
Pull the ball all the files in the remote directory
[root@web01 cs]# rsync -avz [email protected]:/etc/ ./
yum/vars/infra
sent 34,535 bytes received 10,324,421 bytes 1,381,194.13 bytes/sec
total size is 27,224,646 speedup is 2.63
Pull remote directory and all files in a directory
[root@web01 cs]# rsync -avz [email protected]:/etc ./
etc/yum/vars/infra
sent 34,372 bytes received 10,325,252 bytes 2,302,138.67 bytes/sec
total size is 27,224,646 speedup is 2.63