阅读985 返回首页    go 人物


使用rsync同步windows与Linux文件

有时候需要在windows和Linux之间同步数据,或者远程备份,可以使用rsync。在标准的RedHat Linux发行版本中,一般都带有rsync,而在windows上需要下载和安装cwrsync。具体配置如下。

  服务器配置

  假设服务器设置在Linux上,使用系统自带的rsync

  a ) 首先需要编辑一个配置文件/etc/rsyncd.conf,比如:

  log file = /var/log/rsyncd.log

  transfer logging=yes

  use chroot = no

  max connections = 4

  [test]

  path=/tmp/ruser/test

  comment=My laptop

  ignore errors = yes

  #strict modes = no

  read only = no

  list = no

  auth users = ruser

  secrets file = /etc/ruser.pas

  hosts allow=*

  hosts deny=*

  [web]

  path=/var/www/html

  comment =my home page

  前4行是全局设置。后面有两个模块test和web。每个模块下有自己的个性配置,比如路径(path)、注释(comment)、访问权限设置等。auth users设置可以访问的用户列表,这里为ruser。如果不指定,就为匿名,即不需要密码也可以同步。secret file指定密码文件,格式:帐号:密码 (每行一组,帐号和密码用:号分开)。这里指定为/etc/ruser.pas,内容为:

  ruser:123456

  hosts allow和hosts deny指定允许或拒绝的机器名。

  b) 配置后,就要启动rsync服务器,有两种方式:单独启动或者使用xinetd服务

  单独启动

  rsync –daemon –config=/etc/rsyncd.conf

  使用xinetd服务,编辑/etc/xinetd.d目录下的rsync文件,比如:

  # default: off

  # description: The rsync server is a good addition to an ftp server, as it \

  # allows crc checksumming etc.

  service rsync

  {

  disable = no

  socket_type = stream

  wait = no

  user = root

  server = /usr/bin/rsync

  server_args = –daemon

  log_on_failure += USERID

  }

  客户端配置

  假设到d:\Program Files\cwRsync,首先编辑一个密码文件,比如ruser.pas,这里要注意两个事情。a)与服务器上的密码文件格式不一样,直接为密码,没有用户名;b)要用bin目录下的chmod命令改变其访问权限,否则出现错误:”password file must not be other-accessible“。使用方法是chmod 600 ruser.pas。

  然后可以使用一个rsync命令就可以了,为了方便可以写如下批处理脚本:

  @ECHO OFF

  cd d:\Program Files\cwRsync\bin

  rsync.exe –password-file=ruser.pas -avz /cygdrive/e/tmp/SimpleCloudAPI-0.2/ ruser@cdev01.ihep.ac.cn::test

  cd ..

  注意,在第三行中,test前面是两个冒号,表示test是一个模块名,如果仅有一个冒号,就是具体的路径。对于模块名,服务器会到/etc/rsyncd.conf中查找路径,本文中就是/tmp/ruser/test。

  各种功能脚本

  使用rsync可以实现多种功能,比如远程增量备份、网站镜像等,只要写好客户端脚本都可以轻松实现。

最后更新:2017-01-04 22:34:37

  上一篇:go 如何选择合适的MySQL存储引擎
  下一篇:go mysql常用命令