首先确定windows端存在如下的bat脚本
@ECHO OFF
REM *****************************************************************
REM
REM CWNETDRIVE.CMD - Batch file template to start your rsync command (s),from local to network drive
REM
REM *****************************************************************
REM arg1 is UNC path of net drive \192.168.31.118myshare
SET arg1=%1
REM arg2 is the username UNC test
SET arg2=%2
REM arg3 is the password UNC testpassword
SET arg3=%3
REM arg4 is local file path, exaple: d/result
SET arg4=%4
REM arg5 is remote file path
SET arg5=%5
REM arg6 is net drirve name
SET arg6=%6
REM Make environment variable changes local to this batch file
SETLOCAL
REM Specify where to find rsync and related files
REM Default value is the directory of this batch file
SET CWRSYNCHOME=%~dp0
SET SSHPATH="%CWRSYNCHOME%home\%USERNAME%.ssh"
REM Create a home directory for .ssh
IF NOT EXIST %SSHPATH% MKDIR %SSHPATH%
REM Make cwRsync home as a part of system PATH to find required DLLs
SET CWOLDPATH=%PATH%
SET PATH=%CWRSYNCHOME%bin;%PATH%
REM Windows paths may contain a colon (:) as a part of drive designation and
REM backslashes (example c:\, g:). However, in rsync syntax, a colon in a
REM path means searching for a remote host. Solution: use absolute path 'a la unix',
REM replace backslashes () with slashes (/) and put -/cygdrive/- in front of the
REM net use X: \192.168.31.118myshare /user:hz620 est testpassword
IF %arg2% neq - (
IF %arg3% neq - (
NET USE %arg1% /user:%arg2% %arg3%
)
)
REM 原始命令如下
rsync -avp /cygdrive/%arg4% /%arg6%svr/%arg5%
REM 修改之后的命令如下 arg6 为映射在windows 客户端的盘符 arg5为文件夹的路径
REM rsync -avp /cygdrive/%arg4% /cygdrive/%arg6%/%arg5%
REM ** CUSTOMIZE ** Enter your rsync command(s) here
然后确定文件目录【etc】下存在一个fstab的文件,里面的配置文件如下
none /cygdrive cygdrive binary,posix=0,user,noacl 0 0
//172.28.35.150/Share /Qsvr ntfs binary,posix=0,user,acl 0 0
//192.168.31.118/myshare /Esvr ntfs binary,posix=0,user,acl 0 0
目前我的理解是在使用rsync时,将samba共享地址【//192.168.31.118/myshare】指向为一个盘符 【E】写法为【/Esvr】
脚本的用法如下
.cwnetdrive.cmd \192.168.31.118myshare test testpassword d/soft/cwRsync/bin bin E
参数有6个,分别进行说明
- \192.168.31.118myshare 为samba的共享地址
- test 为samba设置的用户
- testpassword 为用户对应的密码
- d/soft/cwRsync/bin 为本机windows下的目录d为D盘
- bin 为远程服务端的文件名称,可以自行进行设置
- E 为盘符