用rsync实现linux服务器备份
一、服务端配置
1、安装软件
linux os安装rsync和xinetd
windows os 只要安装rsync
2、配置软件
1) linux:
2.1 修改将rsync加入到xinetd中 sudo vi /etc/xinetd.d/rsync
将disable=yes改为no
service rsync
{
disable = no
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
2.2 设置xinetd自启动
chkconfig rsync on
chkconfig rsync --list
2.3 配置rsyncd.conf
sudo vi /etc/rsyncd.conf
use chroot = false
max connections = 20
strict modes = false
hosts allow= *
port = 873
UID=0
GID=0
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
secrets file = /etc/rsyncd.secrets
[confluence] #被监听项
path = /var/atlassian/application-data/confluence
read only = false
transfer logging = yes
2.4 配置rsync端口号
sudo vi /etc/services
rsync 873/tcp # rsync
rsync 873/udp # rsync
2.5 配置过滤文件
sudo vi /etc/rsyncd.filter (输入需要过滤的文件名)
2.6 配置同步用户
sudo vi /etc/rsyncd.secrets
yfzheng:XX
2.7 重启xinted
sudo ./etc/init.d/xinted restart
2)Windows
2.1 一路安装rsync
2.2 配置安装目录下rsyncd.conf
use chroot = false
strict modes = false
hosts allow = *
log file = rsyncd.log
UID=0
GID=0
# Module definitions
# Remember cygwin naming conventions : c:\work becomes /cygwin/c/work
#
[testu-web-81125]
path = /cygdrive/D/web
read only = false
transfer logging = yes
2.3 service配置
运行中输入services.msc找到RsyncServer服务,将“登陆”设置为“本地系统帐户”,服务为自动重启
二、客户端配置
1、客户端安装rsync
2、同步文件
2.1 从服务器上下载文件
rsync -vzrtopg --delete --progress --exclude-from=/etc/rsyncd.filter yfzheng@192.168.82.85::confluence/tmp/test
2.2 从本地上传到服务器上去
rsync -vzrtopg --delete --progress --exclude-from=/etc/rsyncd.filter /tmp/test yfzheng@192.168.82.85::confluence
备注:
如果服务器端不指定secrets file,则运行同步脚本时要带用户密码文件,即加参数--password-file=/etc/rsync.secrets(windows用/cygdrive/D/rsync.ps),其中密码文件rsync.secrets存在于服务器端