win32下基于cwRsync的本机工作区和移动硬盘文件增量同步的例子


寒假闲无事,在家里用虚拟机学习(cw)Rsync,顺便写了一个批处理,实现了win32下基于cwRsync的本机工作区和移动硬盘文件增量同步!

话说增量备份,我的Dropbox已经在云端实现了,但是我还是不放心,因为我的这台联想(说起这个词我觉于一种莫名其妙的恶心和厌恶感)Y450,买了回来充电器就有问题,用起来咯咯吱吱乱叫(虽说充电器工作的时候有电流音正常,但是那个也太不像话了把,不靠近都听得见,真害怕会爆炸),咨询客服总是一句话,正常的,奶奶的,人家的怎么就不响啊?拖了2-3个月实在是受不了了,就拿到家里这边的客服换了一个(话说常州那边的客服态度真恶劣),现在虽说换了一个充电器,用起来也不怎么卡卡的了(相比原来),但是还是不敢放心的防上自己的重要文件,因为那个硬盘,时不时关机或者使用的时候,就“啪”的响一下,每次关机都不爽,咨询客服,还是那句话,正常(奶奶的,我机器什么毛病在你们嘴里都正常),说是XP的驱动问题,奶奶的我系统从XP→Vista→Win7了,驱动从联想官方到驱动之家最新都换过了,还是“啪”的响一下,受不了,每次“啪”的响一下,就好像在敲击一下我的神经,听多了头疼,再加上机器的非正常震动,我非常担心我的数据,Dropbox还不够,哪天撞墙了,我的数据也完蛋了。

如上所述,做一个本地的Rsync到移动硬盘还是很有必要的,呵呵,由于我的移动硬盘的最后一个分区是K,把我的Dropbox同步到K:\ Dropbox

先安装cwRsync Server

[text]
# +==============================+
# | Rsync Conf for BACKUP |
# | by ihipop.gicp.net |
# | Last Modify:2010-02-23 |
# +==============================+
# General Settings
pid file = rsyncd.pid
port = 53333
#address = 127.1
uid = 0
gid = 0
use chroot = false
read only = false
motd file = rsyncd.motd
# Define the Welcome Msg!
#timeout = 800
secrets file = rsyncd.secrets
lock file = rsyncd.lock

# ACL Rules
hosts allow = 211.XXX.XXX.XXX/255.255.255.255 127.0.0.1 192.168.233.1 192.168.233.128
hosts deny = *
# ONLY hosts IN hosts allow HAVE THE ACCESS
max connections = 4

# Log Settings
#log format = %t %a %m %f %b
#syslog facility = local3
transfer logging = yes

#
# Virtual Directory Setting
#
#

[dropbox]
path = /cygdrive/E/My Documents/My Dropbox
read only = false
#transfer logging = yes
#lock file = rsyncd.lock
comment = My Dropbox Directory

[music]
path = /cygdrive/E/music
read only = false
#transfer logging = yes
#lock file = rsyncd.lock
comment = My Music Directory

[htdocs]
path = /cygdrive/E/xampp/xampp/htdocs
read only = false
#transfer logging = yes
#lock file = rsyncd.lock
comment = My htdocs Directory

[mysqldata]
path = /cygdrive/E/xampp/xampp/mysql/data
read only = false
#transfer logging = yes
#lock file = rsyncd.lock
comment = My mySQL Directory
[/text]

不多做解释了,看这里吧

然后在服务里面启动RsyncServer服务即可验证

然后 cwRsync clinet

主要是这里了,打开client的安装目录,一般是%ProgramFiles%cwRsync

打开cwrsync,清空和输入如下内容,其中 :setenv根据自己环境修改

[text]@ECHO OFF
echo *****************************************************************
echo * *
echo *CWRSYNC My Files By ihipop. Connect Your K Device First Please *
echo * *
echo *By ihipop. (http://ihipop.info) *
echo *****************************************************************

goto check-k

:setenv
Echo ※→Initializing The Environment...
ping -n 5 127.1 >null
REM Make environment variable changes local to this batch file
SETLOCAL
REM ** CUSTOMIZE ** Specify where to find rsync and related files (C:\CWRSYNC)
SET CWRSYNCHOME=%PROGRAMFILES%\CWRSYNC
REM Set CYGWIN variable to 'nontsec'. That makes sure that permissions
REM on your windows machine are not updated as a side effect of cygwin
REM operations.
SET CYGWIN=nontsec
REM Set HOME variable to your windows home directory. That makes sure
REM that ssh command creates known_hosts in a directory you have access.
SET HOME=%HOMEDRIVE%%HOMEPATH%
REM Make cwRsync home as a part of system PATH to find required DLLs
SET CWOLDPATH=%PATH%
SET PATH=%CWRSYNCHOME%\BIN;%PATH%
goto sync

:sync
REM ** CUSTOMIZE ** Enter your rsync command(s) here
Echo ※→Starting the Rsync Service...
net start RsyncServer >null
Echo ※→Sync My dropbox...
rsync -hav --progress --delete rsync://127.0.0.1:53333/dropbox/ /cygdrive/K/Dropbox
Echo ※→Stoping the Rsync Service...
net Stop RsyncServer >null
goto end

:none-k
echo →Connect Your K Device First Please!
goto end

:k-is-ready
echo →K Device Connected!
goto setenv

:check-k
echo ※→Checking The K Device...
IF EXIST "K:\Dropbox" goto k-is-ready
goto none-k

:end
echo ※→Will Close The Window in 20s....
ping -n 20 127.1 >null
exit
[/text]

此批处理可以在这里下载

SYNC To K|

Author Info :
  • From:win32下基于cwRsync的本机工作区和移动硬盘文件增量同步的例子
  • URL:http://blog.ihipop.info/2010/02/634.html
  • Please Reserve This Link,Thanks!
  • 发表评论

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