一个伪linux粉丝的blog

  1. 首页
  2. network
  3. 正文

cwRsync windows to linux

25 5 月, 2018 5467点热度 1人点赞 2条评论

最近折腾了一个小需求,将一台windwos下的文件定时同步到linux机器上,这样内外网访问基本一致,记录一下,参考了几篇文章,地址见文末。

1、Windows 客户端配置:

cwRsync是基于cygwin平台的rsync软件包,支持windows对windows、windows对Linux、Linux对windows高效文件同步。Cwrsync还集成了OpenSSH for windows,可以实现Linux 下Rsync一模一样的操作。使用 cwRsync 来同步文件后,只需要对一台主服务器进行文件修改,其他镜像服务器可以自动同步,包括文件的更新、删除、重命名等。

  • cwRsync分为付费版和免费版两种,我们只需要使用免费版即可,在官方网站上面下载 cwRsync Free Edition 版本。

https://www.itefix.net/content/cwrsync-free-edition

cwrsync logo

cwrsync_5.7.2_x86_free.zip

  •  解压 cwRsync_5.7.2_x86_Free.zip 到  C:\cwRsync目录中
  • 双击 cwrsync.cmd 运行,会在当前生成 home\%USERNAME%\.ssh 目录,供 ssh 认证方式使用。
  • 为系统新建一个环境变量,目录为cwrsync的bin目录下,例:path: C:\cwRsync\bin。这样 cmd 命令行下可以直接运行 rsync 这个命令
    C:\Users\Administrator>rsync --version
    rsync version 3.1.3 protocol version 31

2、linux客户端

Linux 一般自带  rsync 工具,没有的话,安装也很简单  apt-get install rsync 搞定

      •  配置文件
    • vim /etc/rsyncd.conf
      # configuration example:
      pid file = /var/run/rsync.pid
      port = 873
      log file = /var/log/rsyncd.log
      lock file = /var/run/rsync.lock# create new
      # any name you like
      [resources]
      # destination directory to copy
      path = /home/wwwroot/你的域名目录/wiki/data/
      # hosts you allow to access
      hosts allow = *
      hosts deny = *
      secrets file = /etc/rsyncd.pass
      # 表示该节点是否可被发现。
      list = true
      # 指定传输到这里文件所属的用户。
      uid = www
      # 指定传输到这里的文件所属的组。
      gid = www
      # rsync连接时的用户名,要和客户端rsync的命令一致
      auth users = www
      # 该目录是否只读
      read only = no
      transfer logging = yes
      log format = %t: host %h (%a) %o %f (%l bytes). Total %b bytes.
      timeout = 600
      # 创建密码文件
      touch /etc/rsyncd.pass
      #权限修改
      chown root:root /etc/rsyncd.pass
      chmod 600 /etc/rsyncd.pass
      vim /etc/rsyncd.pass
      内容为:www:passwd # 用户名:密码   如我的  www:3660wiki

3、 windows下配置文件设置
C:\cwRsync\ 目录下新建 rsync.pass
密码和前面linux下相同,3660wiki ,这里有坑,不需要用户名,只有纯密码!

否则后面会遇到类似这样的错误

auth failed on module resources from unknown (ip省略): missing secret for user "www"

同步测试
同步命令如下

rsync -acrtzv --password-file=/cygdrive/c/cwRsync/rsync.pass /cygdrive/d/DokuWikiStick/dokuwiki/data/ www@服务器ip::resources
因为这里有了用户名www, 所以前面rsync.pass文件不需要用户名了

测试通过后,设置定时处理文件

dynamicres_sync.bat

@echo off
rsync -acrtzv --password-file=/cygdrive/c/cwRsync/rsync.pass /cygdrive/d/DokuWikiStick/dokuwiki/data/ www@服务器ip::resources

每15分钟执行一次 dynamicres_sync.bat 这个同步脚本,够用了。

查看日志

tail -10f /var/log/rsyncd.log
2018/05/17 01:45:01 [10078] connect from UNKNOWN (*.*.*.*)
2018/05/16 17:45:02 [10078] rsync to resources/ from www@unknown (*.*.*.*)
2018/05/16 17:45:02 [10078] receiving file list
2018/05/16 17:46:10 [10078] sent 1907 bytes received 581652 bytes total size 200818115

windows下的密码文件也切记不要开放给everyone

否则依然会出现如下报错,害我查了半天服务器配置,后来回想起自己动过windows下客户端密码文件的权限:)

C:\cwRsync>dynamicres_sync.bat
ERROR: password file must not be other-accessible
rsync error: syntax or usage error (code 1) at authenticate.c(196) [sender=3.1.3]

cwRsync 目录权限

cwRsync 目录权限

参考如下

https://www.liurongxing.com/use-rsync-crontab-windows-system-file-to-linux-system.html

http://happyqing.iteye.com/blog/2218153

https://www.itefix.net/content/how-can-i-secure-connections-between-windows-rsync-clients-and-cwrsync-servers (这篇代后续折腾)

相关文章:

  1. Real Time Sync with Sersync
  2. Hiweed Linux 2.0RC 发布了
  3. 腾讯发布 QQ for linux 1.0 Preview
  4. wget for Windows
标签: cwRsync RSYNC
最后更新:25 6 月, 2019

wanjie

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

  • 路人

    网上无法下载免费版了,楼主能发一份给我吗?谢谢

    9 10 月, 2018
    回复
    • wanjie

      @路人 官网还真没找到,已发送

      24 10 月, 2018
      回复
  • razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
    取消回复

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    归档
    分类
    • network / 332篇
    • Uncategorized / 116篇
    • unix/linux / 121篇
    • 业界资讯 / 38篇
    • 公司杂事 / 11篇
    • 数码影像 / 12篇
    • 美剧 / 3篇
    • 美图共赏 / 21篇
    • 英语学习 / 3篇
    标签聚合
    浏览器 gitlab kubectl deepseek docker kernel 邮件归档 ssh Google wget Nginx 虚拟主机 网站运营 VPS 天翼live dreamhost Google Voice google-chrome postgres d90 dreamhost空间 openssl debian Ubuntu ldap k8s 泰国 squid nexus jira

    COPYRIGHT © 2008-2025 wanjie.info. ALL RIGHTS RESERVED.

    Theme Kratos Made By Seaton Jiang