安装 Rsync Server
-
检查是否已经存在 rsync
rsync --version -
安装 rsync server
apt install rsync -
编辑配置文件
vim /etc/rsyncd.conf⚠️ 这里指定的 user 需要在系统中存在,并且该用户拥有目标目录的写权限。
/etc/rsyncd.conf
# Global configuration of the rsync service pid file = /var/run/rsyncd.pid # Username and group for working with backups uid = backup-user gid = backup-user # Don't allow to modify the source files read only = no # Data source information [data] path = /data/rsync_test list = yes auth users = backup-user secrets file = /etc/rsyncd.passwd -
设置 rsync 用户的密码,编辑
/etc/rsyncd.passwd文件/etc/rsyncd.passwd
backup-user:test-pass修改该文件的权限
chmod 0600 /etc/rsyncd.passwd -
复制 systemctl 的 service 启动文件
cp /lib/systemd/system/rsync.service /etc/systemd/system/rsync.service -
启动服务
systemctl restart rsync
客户端配置
-
增加 rsync 的 认证密码,
/etc/rsyncd.passwd文件中存储是 rsync server 的密码/etc/rsyncd.passwd
test-pass设置文件权限
chmod 0600 /etc/rsyncd.passwd -
从 rsync server 下载文件到客户端
rsync -a --password-file=/etc/rsyncd.passwd backup-user@ServerIP::data /root/rsync-des/ -
从本地上传文件到 rsync server
rsync -a --password-file=/etc/rsyncd.passwd ./myout.file backup-user@ServerIP::data
Rsync 常用参数
示例:
rsync -avz --delete --bwlimit=10240 root@ClientIP:/backup/data/ /data/backup/
--delete: 删除那些DST中SRC没有的文件--bwlimit=KBPS: 限制I/O带宽,KBytes per second--password-file=FILE:从FILE中得到密码-a, --archive: 归档模式,表示以递归方式传输文件,并保持所有文件属性,等于-rlptgoD-v, --verbose: 详细模式输出-z, --compress对备份的文件在传输时进行压缩处理