rsync 增量备份
rsync 的传输方式选择需根据具体需求决定: 1、传输方式选择 SSH 传输 使用 -e ssh 参数通过 SSH 通道传输,适用于临时文件传输或小规模数据同步。 守护进程模式 使用 rsync:: 前缀指定守护进程服务,适合服务器间长期稳定的数据同步。 优化建议 传输大文件或频繁更新的数据时,建议开启压缩(-z)并使用增量同步。 脚本自动化同步推荐守护进程模式,支持断点续传和权限保留 2、服务端(守护进程模式) [root@localhost ~]# yum -y install rsync [root@VM-16-13-centos ~]# [root@VM-16-12-centos ~]# [root@VM-16-12-centos ~]# cat /etc/rsyncd.conf uid = rsync gid = rsync port 873 fake super = yes use chroot = no max connections = 200 timeout = 600 ignore errors read only = false list = false auth users = rsyncd_backup secrets file = /etc/rsyncd_passwd lock file = /var/run/rsyncd.lock log file = /var/log/rsync/rsync.log #局部模块 [backup] path = /backup [root@VM-16-12-centos ~]# useradd rsync -M -s /sbin/nologin [root@VM-16-12-centos ~]# [root@VM-16-12-centos ~]# mkdir /backup [root@VM-16-12-centos ~]# chown -R rsync:rsync /backup/ [root@VM-16-12-centos ~]# [root@VM-16-12-centos ~]# echo "rsyncd_backup:123456" >/etc/rsyncd_passwd [root@VM-16-12-centos ~]# chmod 600 /etc/rsyncd_passwd [root@localhost ~]# systemctl restart rsyncd [root@localhost ~]# systemctl enable rsyncd [root@localhost ~]# lsof -i:873 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME rsync 67937 root 3u IPv4 152956 0t0 TCP *:rsync (LISTEN) rsync 67937 root 5u IPv6 152957 0t0 TCP *:rsync (LISTEN) 客户端: [root@VM-16-13-centos ~]# echo "123456" >/etc/rsyncd_passwd [root@VM-16-13-centos ~]# chmod 600 /etc/rsyncd_passwd [root@VM-16-13-centos ~]# rsync -avz /root rsyncd_backup@119.45.16.7::backup/ --password-file=/etc/rsyncd_passwd [root@VM-16-13-centos ~]#