需要用到的工具cwrsync:http://down.51cto.com/data/2103716
windows上用到的bat脚本:
@echo off set fdate=%date:~0,4%_%date:~5,2%_%date:~8,2%_%time:~0,2%_%time:~3,2% echo %fdate% ldifde -f %fdate%.ldf move %fdate%.ldf D:\adbackup\addata D:\adbackup\command\cwRsync\rsync.exe --delete -az "/cygdrive/D/adbackup/addata" [email protected]::adbackup --password-file="/cygdrive/D/adbackup/command/cwRsync/pass.txt"
其中bat中取时间变量做为文件名:
“date:~0,10%是DOS里取日期的命令。
echo :~1,5% //指针向右→偏移1位,然后从指针处开始向右→提取5个字符.
echo :~0,-3% //指针不偏移,→提取所有字符,并除去最后3个字符.
echo :~5% //单个数字,不指定长度值.表示指针→偏移5个字符,然后,→提取所有字符.
echo :~-5% //单个负值,特例,表示指针反方向偏移,从最右端起,←偏移5位,然后从指针处开始→提取所有字符.也可以简单理解为提取字符串末尾5个字符。
举例:
C:\Documents and Settings\user>echo %date%
2012-08-08 星期三
C:\Documents and Settings\user>echo %date:~5,10%
08-08 星期三
C:\Documents and Settings\user>echo %date:~5,4%
08-0
C:\Documents and Settings\user>echo %date:~5,5%
08-08
cwrsync命令解释:
rsync.exe --delete -az "/cygdrive/D/adbackup/addata" [email protected]::adbackup --password-file="/cygdrive/D/adbackup/command/cwRsync/pass.txt"
--delete -az 去重性同步,保持两端文件一致
"/cygdrive/D/adbackup/addata" 源文件目录,代表d:/adbackup/addata
[email protected]::adbackup adrsync为rsync备份用户名,rsync.xx.com为rsync服务器名,adbackup为rsync模块
--password-file="/cygdrive/D/adbackup/command/cwRsync/pass.txt" 指定rsync备份用户名的密码文件路径,格式类似于“源文件目录”
rsync服务配置文件(linux):
[root@deer rdata]# cat /etc/rsyncd.conf uid = root gid = root [adbackup] path = /adbackup/rdata comment = Windows AD backup dir list = yes auth user = backuser secrets file = /abbackup/adrsync.pass read only = no
定期清理,服务器打包等操作不再赘述!