作者:E4b9a6, 创建:2021-07-01, 字数:2121, 已阅:94, 最后更新:2024-03-10
假设有两台机器,分别如下
备份步骤如下
首先检查B机器的Rsync服务情况,一般是默认开启的
➜ ~ sudo systemctl status rsync
● rsync.service - fast remote file copy program daemon
Loaded: loaded (/lib/systemd/system/rsync.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2021-06-30 16:15:49 UTC; 14h ago
Main PID: 8218 (rsync)
Tasks: 1 (limit: 4655)
CGroup: /system.slice/rsync.service
└─8218 /usr/bin/rsync --daemon --no-detach
Jun 30 16:15:49 ubuntu1804-server systemd[1]: Started fast remote file copy program daemon.
可以看到B机器的Rsync正常运行中,接下来编辑(或添加)Rsync的配置文件
sudo vim /etc/rsyncd.conf
# /etc/rsyncd: configuration file for rsync daemon mode
# See rsyncd.conf man page for more options.
# configuration example:
uid = root
gid = root
use chroot = no
max connections = 10
strict modes = no
port = 41000
# pid文件,如无法再次启动可删除
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/run/rsyncd.log
[rsync-backup]
path = /mnt/sdb/rsync-server
comment = rsync backup
ignore errors
read only = no
write only = no
hosts allow = 10.0.0.0/24
list = false
uid = chancel
gid = chancel
auth users = rsync
# 用户认证配置文件
secrets file = /etc/rsync-user.pass
创建一个配置文件中的 用户认证配置文件(/etc/rsync-user.pass)
sudo vim /etc/rsync-user.pass
user:password
注意rsync-user.pass文件为400权限,最后重启下B机器的Rsync服务即可
sudo chmod 400 /etc/rsync-user.pass
sudo systemctl restart rsync.service
接下来我们登录A机器,同样创建 /etc/rsync-user.pass 文件,存入密码即可
password
还是需要注意rsync-user.pass文件的权限为400
sudo chmod 400 rsync-user.pass
接下来就可以尝试进行同步
rsync -vzrtp --delete --progress --password-file=/etc/rsync_user.pass --port=41000 /srv rsync@192.168.11.11::rsync-backup/A
参数解释