rsync推送备份服务器
程序员文章站
2022-05-28 10:45:53
...
rsync推送备份服务器
备份服务器操作
#编辑配置文件
vi /etc/rsyncd.conf
uid = root #运行RSYNC守护进程的用户
gid = root #运行RSYNC守护进程的组
use chroot = no #不使用chroot
max connections = 200 # 最大连接数为200
timeout = 300
port = 873 #默认端口873
[backup] #这里是认证的模块名,在被备份服务器端需要指定
path = /home/backup/ #需要做备份的目录,不可缺少!
ignore errors #可以忽略一些无关的IO错误
read only = no# 只读
list = false #不允许列文件
auth users = abc #认证的用户名,如果没有这行则表明是匿名,此用户与系统无关
secrets file = /etc/rsync.pas #密码和用户名对比表,密码文件自己生成
hosts allow = 10.96.9.0/24,10.96.10.113#允许主机
hosts deny = 0.0.0.0/0 #禁止主机
#transfer logging = yes
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
#添加访问用户密码文件
vi /etc/rsync.pas
abc:abc123
#用户:密码(用户对应rsyncd.conf)
chmod 600 /etc/rsync.pas
#添加开机启动rsync进程
vi /etc/rc.local
/usr/bin/rsync --daemon
需被备份的服务器操作
vi /etc/rsync.pas
abc123
#密码(只添加密码)
chmod 600 /etc/rsync.pas
rsync -avz /backup(本地目录) (用户名)@IP::backup/(模块名) --password-file=/etc/rsync.pas(密码表路径)
批处理shell
备份服务器操作(存储目录为/home/backup)
cp /etc/rsyncd.conf /etc/rsyncd.conf.bak
cat > /etc/rsyncd.conf << EOF
uid = root
gid = root
use chroot = no
max connections = 200
timeout = 300
port = 873
[backup]
path = /home/backup/
ignore errors
read only = no
list = false
auth users = abc
secrets file = /etc/rsync.pas
hosts allow = 0.0.0.0/0
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
EOF
echo abc:abc123 > /etc/rsync.pas
chmod 600 /etc/rsync.pas
/usr/bin/rsync --daemon
echo /usr/bin/rsync --daemon >> /etc/rc.local
需被备份的服务器操作
echo abc123 > /etc/rsync.pas
chmod 600 /etc/rsync.pas
需被备份的服务器操作(备份目录为/backup,改IP为备份服务器IP)
rsync -avz /backup [email protected]::backup/ --password-file=/etc/rsync.pas
上一篇: 使用jdom 解析xml字符串
下一篇: mysql5.7解压版安装