Windows和Linux下安装Rsync

 一、Linux安装rsync

 OS:CentOS 7

1.安装rsync
yum -y install rsync
 
2.启动rsync并设置开机自启动
systemctl start rsyncd
systemctl enable rsyncd
 
CentOS6.5:
(1)常规启动
rsync --daemon
echo “rsync --daemon” >>/etc/rc.local
(2)加入超级守护进程启动
cat >>/etc/xinetd.d/rsync << EOF
# default: off
# description: The rsync server is a good addition to an ftp server, as it \
#    allows crc checksumming etc.
service rsync
{
    disable    = no
    flags        = IPv6
    socket_type     = stream
    wait            = no
    user            = root
    server          = /usr/bin/rsync
    server_args     = --daemon
    log_on_failure  += USERID
}
EOF
service start xinetd
chkconfig xinetd on
 
3.服务端rsync配置文件
echo "backuper:123456"  >>/etc/rsyncd_users.db   #密码文件
chmod 600 /etc/rsyncd_users.db
vi /etc/rsyncd.conf
uid = nobody
gid = nobody
use chroot = yes                         #是否锁定到备份目录
address = 192.168.1.1                    #本机IP
port 873
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
hosts allow = 192.168.1.100              #可允许rsync同步本机的备份服务器

[backup_test]                            #rsync同步模块名称
    path = /opt/backup                   #需要同步的目录
    comment = rsync_backup               #描述
    read only = yes                      #只读
    dont compress = *.gz *.bz2 *.tgz *.zip *.rar *.z
    auth users = backuper                #用于rsync同步的用户
    secrets file = /etc/rsyncd_users.db  #指定密码文件位置

 chmod 655 /opt/backup   #同步目录需为655权限

 
4.客户端配置
yum -y install rsync
systemctl start rsyncd 
systemctl enable rsyncd
echo "123456" >/etc/rsync.pass
chmod 600 /etc/rsync.pass
 
5.测试同步(在备份服务执行)
rsync -rI  --password-file=/etc/rsync.pass backuper@192.168.1.1::backup_test /data/rsync_data/192.168.1.1/backup

 

二、windows安装rsync服务端

OS:Windows 7

 软件下载链接:https://www.backupassist.com/rsync/cwRsyncServer_4.1.0_Installer.zip

1.解压安装cwrsync软件,默认"下一步"即可

 

 

 

 

 安装完成

2.在程序安装目录下修改rsync.conf

use chroot = false
strict modes = false                                 #禁用文件mode检验
hosts allow = 192.168.1.1
log file = rsyncd.log
port = 873
uid = 0
gid = 0

[backup]
path = /cygdrive/c/Users/qbserver/Documents/QBdata   #"C:\" 需使用"/cygdrive/c/xxxx/xxxx/xxx "替代
read only = yes
transfer logging = yes
list = no
auth users = cw
secrets file = /cygdrive/e/r/ICW/pass.txt            #密码文件存放路径

3.修改完后重启RsyncServer服务

 操作完成,可在客户端同步测试

 注:确保密码文件和所同步目录rsync用户有修改或完全控制权限

   确保rsync服务端密码文件为  user:password    格式
   若安装完无法找到Rsync服务,则需在安装前在系统手动创建rsync用户
 

三、在Windows安装客户端(将本地文件同步到服务端)

 
1.解压到任意安装目录下,添加当前bin文件夹路径到环境变量;
计算机属性→高级系统设置→环境变量→系统变量→Path→编辑→新建→输入路径→确定

2.关闭防火墙或者开放873端口;
 
3.新建rsync.pass密码文件,将密码写入,不用写用户名;

 

4.查看当前登录用户对同步文件夹以及子文件夹是否具有完全控制的权限,取消同步文件夹的只读设置;
 
5.打开cmd,输入同步命令:
rsync -rI  --password-file=/cygdrive/d/rsync.pass /cygdrive/d/backup  backuper@192.168.1.1::backup_test
 
6.若出现权限拒绝,需要在服务端设置同步目录为777的权限;
 
7.将同步命令写入.bat文件,设置定时任务计划。

 rsync.bat

#在备份文件夹名称后面添加时间戳
if "%time:~0,1%"==" " set "time=0%time:~1%"

@echo off
color 0a
for /f "tokens=*" %%a in ('time/t') do set now=%%a
set ymd=%date:~0,4%%date:~5,2%%date:~8,2%
set hms=%now:~0,2%%now:~3%%time:~6,2%
set time=%ymd%%hms%
echo

#同步备份
rsync -rI  --password-file=/cygdrive/d/rsync.pass /cygdrive/d/Backup  backuper@192.168.1.1::backup_test/backup_%time%/Backup

 

参考文档:
posted on 2019-11-04 19:00  X……  阅读(1363)  评论(0编辑  收藏  举报