windows做服务端:
安装cwrsyncserver,注意用administrator安装,否则服务无法安装。
若不单独定义访问密码,则需要记住安装时的用户名密码
配置文件例如:
rsyncd.conf:

port = 7777
use chroot = false
strict modes = false
hosts allow = *
log file = rsyncd.log
pid file = rsyncd.pid
#max connections = 2
uid = 0
gid = 0
motd file = etc/welcome.txt
transfer logging = yes
read only = false
auth users = testuser
secrets file = etc/userlist

[test]
path = /cygdrive/d/www

userlist:
testuser:testpasswd

linux做客户端:
yum install -y rsync

#!/bin/bash
PASSWORD='/home/nova/Desktop/rsync/passwd'
SOURCE='115.128.182.117::test'
rsyncPort=7777
USER=testuser
DEST=/home/nova/Desktop/rsync/www/
excludeList='/home/nova/Desktop/rsync/exclude.txt'
echo "start backup file server"
rsync -av --port=rsyncPort --exclude-from=excludeList --progress --delete --password-file=PASSWORDUSER@SOURCEDEST
#rsync -av --port=rsyncPort --progress --delete --password-file=PASSWORD USER@SOURCE DEST
if [? -eq 0 ];then
    echo "file server backup successfully!"
else
    echo "file server backup failure, try again:"
fi

4 对 “rsync文件同步”的想法;

  1. @ERROR: Unknown module ‘zabbix’
    rsync error: error starting client-server protocol (code 5) at main.c(1516) [sender=3.0.9]

  2. rsync -avzP …,一定要考虑断点续传,就是这里的 P,否则网络一个闪断之类的就傻了

  3. #-*- coding: utf-8 -*-
    import os
    import fileinput
    rsyncSrc='D:\ptest'
    rsyncDes='test@120.26.245.181::opt'
    for line in fileinput.input():
        if line:
            lineArr=line.split(' ')
            oper=lineArr[0]
            file=lineArr[1]
            date=lineArr[2]
            time=lineArr[3]
            touched=False
            #print file
            #print rsyncSrc
            if file.index(rsyncSrc)==0:
            #if file.index('D:\ptest') == 0:
                if (oper=='MOVED_TO') or (oper=='CREATE'):
                    _cureent_file=file.replace(rsyncSrc,'/cygdrive/d/ptest')
                    cureent_file=_cureent_file.replace('\\','/')
                    cmd='set CYGWIN=nodosfilewarning && cd /d '+rsyncSrc+' && '+'start /b rsync -avz -R -d --port=873 --delete --progress '+cureent_file+' '+rsyncDes+' <"C:\Program Files (x86)\ICW\etc\pass.txt" '
                    #2>D:\logs\error.log
                    touched=True
                print rsyncSrc+' touched'
            if touched:
                print cmd
                #os.system(cmd)
    

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code