安装
查看是否安装rsync
rpm -qa | grep rsync
在线安装rsync
yum -y install rsync
配置开机自启动
systemctl enable rsyncd.service
编辑配置文件
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
read only = false
max connections = 100
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsync.log
exclude = lost+found/
transfer logging = yes
# timeout = 900
ignore nonreadable = yes
# dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
[databack]
comment = backup data
path = /data1 #备份文件存储的位置
read only = false
auth users = werben #登录用户
secrets file = /etc/rsyncd.password #登录密码
配置密码:
echo "werben:123456" > /etc/rsyncd.password
chmod 600 /etc/rsyncd.password
systemctl restart rsyncd.service
# 关闭防火墙
systemctl disable firewalld
systemctl stop firewalld
#关闭selinux
setenforce 0
sed -i '/^SELINUX=/c SELINUX=disabled' /etc/selinux/config
将/data目录,备份到/data1目录
#将密码写到文件,执行备份的时候就不要在终端输入密码了
echo "123456" > /etc/werben.pwd
chmod 600 /etc/werben.pwd
rsync -avz --delete /data werben@127.0.0.1::databack --password-file=/etc/werben.pwd