【www.bbyears.com--其它】
说明:
有一个目录/var/www/test/public/下面,有很多文件、目录,但我只需要同步其中的2个目录(js,css)。用exclude将其它的文件,目录排除当然是可以的,但因为其它文件,目录非常多,在exclude中排除明显太费时;或2行rsync直接同步/var/www/test/public/js,/var/www/test/public/css也是可以的。
类似rsync -nrv /var/www/feibo/fbtime_in/public/js /tmp/test/public这样,写2行
但如果我只想要1行rsync同步/var/www/test/public目录呢。这里,我就需要先include-from指定需要同步的文件或目录,exclude将/var/www/test/public所有文件、目录排除掉
实现:
1.编写/root/shell/test.include文件
代码如下# cat /root/shell/test.include
js
css
2.rsync同步指定文件,目录
代码如下# rsync -nrv --include-from=/root/shell/test.include --exclude=/* /var/www/test/public/ /tmp/test/public
-n, --dry-run perform a trial run with no changes made //干跑,光显示哪些文件目录会被rsync而不运行,用于测试非常方便
-r, --recursive recurse into directories //详细模式输出
-v, --verbose increase verbosity //对子目录以递归模式处理
参照网上写的,rsync -nrv --include-from=/root/shell/test.include --exclude=* /var/www/test/public/ /tmp/test/public,发现任何文件都没有同步。原来--exlucde=*是不行的,需要指定--exclude=/*。估计意思是指当前目录/var/www/test/public/下的所有文件目录。--exclude=*/则是指定当前目录/var/www/test/public/下的所有目录。
这里要注意/var/www/test/public/需要添加最后的/
附录:
附录1.执行的结果,可以看到只有js,css目录被rsync
代码如下sending incremental file list
css/animate.css
css/b
css/global.css
css/global.css_bak
js/a
js/feibo.js
js/feibo.js_bak
js/global.js
js/global.js_bak
js/jquery-1.7.2.min.js
js/jquery-1.8.0.min.js
js/json2.min.js
js/swfupload.js
js/swfupload.swf
js/swfupload_fp9.swf
js/swfuploadhandlers.js
js/WdatePicker/WdatePicker.js
js/WdatePicker/calendar.js
js/WdatePicker/lang/en.js
js/WdatePicker/lang/zh-cn.js
js/WdatePicker/lang/zh-tw.js
js/WdatePicker/skin/WdatePicker.css
js/WdatePicker/skin/datePicker.gif
js/WdatePicker/skin/default/datepicker.css
js/WdatePicker/skin/default/img.gif
js/WdatePicker/skin/whyGreen/bg.jpg
js/WdatePicker/skin/whyGreen/datepicker.css
js/WdatePicker/skin/whyGreen/img.gif
js/zero/ZeroClipboard.as
js/zero/ZeroClipboard.fla
js/zero/ZeroClipboard.js
js/zero/ZeroClipboard.swf
js/zero/ZeroClipboard10.as
js/zero/ZeroClipboard10.fla
js/zero/ZeroClipboard10.swf
sent 1045 bytes received 126 bytes 2342.00 bytes/sec
total size is 947225 speedup is 808.90 (DRY RUN)