折腾:
【规避解决】sftp中rmdir出错:Couldn’t remove directory: Failure
期间,参考:
unix – sftp entire directory (directory having many directories recursively) – Server Fault
貌似直接用rsync直接搞定所有更新到事情了?
想要用rsync直接同步绕过sftp的rmdir和rm无法递归删除非空目录的问题
直接实现全部文件的同步。
rsync 同步
linux 下使用 rsync 进行文件 同步 – Daniel 的技术笔记 不积跬步无以至千里,不积小流无以成江海。 – CSDN博客
remote sync
使用rsync同步目录 – Mike_Zhang – 博客园
rsync命令_Linux rsync 命令用法详解:远程数据同步工具
-v, –verbose 详细模式输出。
-q, –quiet 精简输出模式。
-c, –checksum 打开校验开关,强制对文件传输进行校验。
-a, –archive 归档模式,表示以递归方式传输文件,并保持所有文件属性,等于-rlptgoD。
-r, –recursive 对子目录以递归模式处理。
-R, –relative 使用相对路径信息。
-b, –backup 创建备份,也就是对于目的已经存在有同样的文件名时,将老的文件重新命名为~filename。
可以使用–suffix选项来指定不同的备份文件前缀。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<backup-dir 将备份文件(如~filename)存放在在目录下。
-suffix=SUFFIX 定义备份文件前缀。
-u, –update 仅仅进行更新,也就是跳过所有已经存在于DST,并且文件时间晚于要备份的文件,不覆盖更新的文件。
-l, –links 保留软链结。
-L, –copy-links 想对待常规文件一样处理软链结。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<copy-unsafe-links 仅仅拷贝指向SRC路径目录树以外的链结。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<safe-links 忽略指向SRC路径目录树以外的链结。
-H, –hard-links 保留硬链结。
-p, –perms 保持文件权限。
-o, –owner 保持文件属主信息。
-g, –group 保持文件属组信息。
-D, –devices 保持设备文件信息。
-t, –times 保持文件时间信息。
-S, –sparse 对稀疏文件进行特殊处理以节省DST的空间。
-n, –dry-run现实哪些文件将被传输。
-w, –whole-file 拷贝文件,不进行增量检测。
-x, –one-file-system 不要跨越文件系统边界。
-B, –block-size=SIZE 检验算法使用的块尺寸,默认是700字节。
-e, –rsh=command 指定使用rsh、ssh方式进行数据同步。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<rsync-path=PATH 指定远程服务器上的rsync命令所在路径信息。
-C, –cvs-exclude 使用和CVS一样的方法自动忽略文件,用来排除那些不希望传输的文件。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<existing 仅仅更新那些已经存在于DST的文件,而不备份那些新创建的文件。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<delete 删除那些DST中SRC没有的文件。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<delete-excluded 同样删除接收端那些被该选项指定排除的文件。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<delete-after 传输结束以后再删除。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<ignore-errors 及时出现IO错误也进行删除。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<max-delete=NUM 最多删除NUM个文件。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<partial 保留那些因故没有完全传输的文件,以是加快随后的再次传输。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<force 强制删除目录,即使不为空。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<numeric-ids 不将数字的用户和组id匹配为用户名和组名。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<timeout=time ip超时时间,单位为秒。
-I, –ignore-times 不跳过那些有同样的时间和长度的文件。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<size-only 当决定是否要备份文件时,仅仅察看文件大小而不考虑文件时间。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<modify-window=NUM 决定文件是否时间相同时使用的时间戳窗口,默认为0。
-T –temp-dir=DIR 在DIR中创建临时文件。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<compare-dest=DIR 同样比较DIR中的文件来决定是否需要备份。
-P 等同于 –partial。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<progress 显示备份过程。
-z, –compress 对备份的文件在传输时进行压缩处理。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<exclude=PATTERN 指定排除不需要传输的文件模式。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<include=PATTERN 指定不排除而需要传输的文件模式。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<exclude-from=FILE 排除FILE中指定模式的文件。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<include-from=FILE 不排除FILE指定模式匹配的文件。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<version 打印版本信息。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<address 绑定到特定的地址。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<config=FILE 指定其他的配置文件,不使用默认的rsyncd.conf文件。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<port=PORT 指定其他的rsync服务端口。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<blocking-io 对远程shell使用阻塞IO。
-stats 给出某些文件的传输状态。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<progress 在传输时现实传输过程。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<log-format=formAT 指定日志文件格式。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<password-file=FILE 从FILE中得到密码。
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<bwlimit=KBPS 限制I/O带宽,KBytes per second。
-h, –help 显示帮助信息。
然后去试了试:
rsync -avz –progress –delete /Users/crifan/GitBook/Library/Import/http_restful_api/output [email protected]:/home/wwwroot/book.crifan.com/books/http_restful_api
输入密码,是可以同步的。
➜ http_restful_api git:(master) ✗ rsync -avz –progress –delete /Users/crifan/GitBook/Library/Import/http_restful_api/output [email protected]:/home/wwwroot/book.crifan.com/books/http_restful_api
[email protected]’s password:
building file list …
117 files to consider
output/
output/epub/
output/epub/http_restful_api.epub
1794927 100% 7.34MB/s 0:00:00 (xfer#1, to-check=114/117)
output/mobi/
output/mobi/http_restful_api.mobi
819548 100% 248.63kB/s 0:00:03 (xfer#2, to-check=112/117)
output/pdf/
output/pdf/http_restful_api.pdf
21286433 100% 173.40kB/s 0:01:59 (xfer#3, to-check=110/117)
output/website/
output/website/index.html
21353 100% 39.87kB/s 0:00:00 (xfer#4, to-check=108/117)
output/website/search_plus_index.json
23466 100% 43.73kB/s 0:00:00 (xfer#5, to-check=107/117)
output/website/sitemap.xml
3247 100% 6.05kB/s 0:00:00 (xfer#6, to-check=106/117)
output/website/appendix/
output/website/appendix/index.html
19400 100% 36.09kB/s 0:00:00 (xfer#7, to-check=104/117)
output/website/appendix/reference.html
21132 100% 39.23kB/s 0:00:00 (xfer#8, to-check=103/117)
output/website/assets/
output/website/assets/favicon.ico
1057 100% 1.96kB/s 0:00:00 (xfer#9, to-check=101/117)
output/website/assets/img/
output/website/assets/img/create_new_md_preview_1.png
83350 100% 114.32kB/s 0:00:00 (xfer#10, to-check=99/117)
output/website/assets/img/create_new_md_preview_2.png
117563 100% 137.17kB/s 0:00:00 (xfer#11, to-check=98/117)
output/website/assets/img/have_state.png
113202 100% 113.27kB/s 0:00:00 (xfer#12, to-check=97/117)
output/website/assets/img/postman_debug_api.png
64717 100% 64.49kB/s 0:00:00 (xfer#13, to-check=96/117)
output/website/assets/img/postman_generated_api_doc.png
193942 100% 152.99kB/s 0:00:01 (xfer#14, to-check=95/117)
output/website/assets/img/pycharm_restful_api_tool.png
163419 100% 580.32kB/s 0:00:00 (xfer#15, to-check=94/117)
output/website/assets/img/stateless.png
137135 100% 301.62kB/s 0:00:00 (xfer#16, to-check=93/117)
output/website/assets/img/swagger_generated_api_doc.png
215085 100% 395.56kB/s 0:00:00 (xfer#17, to-check=92/117)
output/website/assets/img/youdao_markdown_explain_preview_1.png
154604 100% 260.76kB/s 0:00:00 (xfer#18, to-check=91/117)
output/website/assets/img/youdao_markdown_explain_preview_2.png
114652 100% 155.94kB/s 0:00:00 (xfer#19, to-check=90/117)
output/website/assets/img/youdao_markdown_preview_1.png
259684 100% 268.93kB/s 0:00:00 (xfer#20, to-check=89/117)
output/website/assets/img/youdao_markdown_preview_2.png
222931 100% 193.69kB/s 0:00:01 (xfer#21, to-check=88/117)
output/website/gitbook/
output/website/gitbook/gitbook.js
105401 100% 779.78kB/s 0:00:00 (xfer#22, to-check=86/117)
output/website/gitbook/style.css
52701 100% 384.07kB/s 0:00:00 (xfer#23, to-check=85/117)
output/website/gitbook/theme.js
113264 100% 757.60kB/s 0:00:00 (xfer#24, to-check=84/117)
output/website/gitbook/fonts/
output/website/gitbook/fonts/fontawesome/
output/website/gitbook/fonts/fontawesome/FontAwesome.otf
124988 100% 562.48kB/s 0:00:00 (xfer#25, to-check=81/117)
output/website/gitbook/fonts/fontawesome/fontawesome-webfont.eot
76518 100% 213.50kB/s 0:00:00 (xfer#26, to-check=80/117)
output/website/gitbook/fonts/fontawesome/fontawesome-webfont.svg
391622 100% 970.67kB/s 0:00:00 (xfer#27, to-check=79/117)
output/website/gitbook/fonts/fontawesome/fontawesome-webfont.ttf
152796 100% 369.34kB/s 0:00:00 (xfer#28, to-check=78/117)
output/website/gitbook/fonts/fontawesome/fontawesome-webfont.woff
90412 100% 168.82kB/s 0:00:00 (xfer#29, to-check=77/117)
output/website/gitbook/fonts/fontawesome/fontawesome-webfont.woff2
71896 100% 108.35kB/s 0:00:00 (xfer#30, to-check=76/117)
output/website/gitbook/gitbook-plugin-alerts/
output/website/gitbook/gitbook-plugin-alerts/plugin.js
1184 100% 1.78kB/s 0:00:00 (xfer#31, to-check=74/117)
output/website/gitbook/gitbook-plugin-alerts/style.css
479 100% 0.72kB/s 0:00:00 (xfer#32, to-check=73/117)
output/website/gitbook/gitbook-plugin-copy-code-button/
output/website/gitbook/gitbook-plugin-copy-code-button/toggle.js
3013 100% 4.53kB/s 0:00:00 (xfer#33, to-check=71/117)
output/website/gitbook/gitbook-plugin-disqus/
output/website/gitbook/gitbook-plugin-disqus/plugin.css
63 100% 0.09kB/s 0:00:00 (xfer#34, to-check=69/117)
output/website/gitbook/gitbook-plugin-disqus/plugin.js
2392 100% 3.59kB/s 0:00:00 (xfer#35, to-check=68/117)
output/website/gitbook/gitbook-plugin-donate/
output/website/gitbook/gitbook-plugin-donate/plugin.css
2720 100% 4.08kB/s 0:00:00 (xfer#36, to-check=66/117)
output/website/gitbook/gitbook-plugin-donate/plugin.js
1960 100% 2.94kB/s 0:00:00 (xfer#37, to-check=65/117)
output/website/gitbook/gitbook-plugin-expandable-chapters-small/
output/website/gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css
580 100% 0.87kB/s 0:00:00 (xfer#38, to-check=63/117)
output/website/gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js
2058 100% 3.08kB/s 0:00:00 (xfer#39, to-check=62/117)
output/website/gitbook/gitbook-plugin-fontsettings/
output/website/gitbook/gitbook-plugin-fontsettings/fontsettings.js
6447 100% 9.64kB/s 0:00:00 (xfer#40, to-check=60/117)
output/website/gitbook/gitbook-plugin-fontsettings/website.css
8596 100% 12.84kB/s 0:00:00 (xfer#41, to-check=59/117)
output/website/gitbook/gitbook-plugin-ga/
output/website/gitbook/gitbook-plugin-ga/plugin.js
725 100% 1.08kB/s 0:00:00 (xfer#42, to-check=57/117)
output/website/gitbook/gitbook-plugin-github-buttons/
output/website/gitbook/gitbook-plugin-github-buttons/plugin.js
3318 100% 4.95kB/s 0:00:00 (xfer#43, to-check=55/117)
output/website/gitbook/gitbook-plugin-github-buttons/plugin.js.map
5362 100% 7.99kB/s 0:00:00 (xfer#44, to-check=54/117)
output/website/gitbook/gitbook-plugin-prism/
output/website/gitbook/gitbook-plugin-prism/prism-atom-dark.css
2025 100% 3.02kB/s 0:00:00 (xfer#45, to-check=52/117)
output/website/gitbook/gitbook-plugin-prism/prism-base16-ateliersulphurpool.light.css
3290 100% 4.90kB/s 0:00:00 (xfer#46, to-check=51/117)
output/website/gitbook/gitbook-plugin-prism/prism-cb.css
3107 100% 4.63kB/s 0:00:00 (xfer#47, to-check=50/117)
output/website/gitbook/gitbook-plugin-prism/prism-duotone-dark.css
3343 100% 4.97kB/s 0:00:00 (xfer#48, to-check=49/117)
output/website/gitbook/gitbook-plugin-prism/prism-duotone-earth.css
3344 100% 4.97kB/s 0:00:00 (xfer#49, to-check=48/117)
output/website/gitbook/gitbook-plugin-prism/prism-duotone-forest.css
3349 100% 4.97kB/s 0:00:00 (xfer#50, to-check=47/117)
output/website/gitbook/gitbook-plugin-prism/prism-duotone-light.css
3334 100% 4.95kB/s 0:00:00 (xfer#51, to-check=46/117)
output/website/gitbook/gitbook-plugin-prism/prism-duotone-sea.css
3352 100% 4.97kB/s 0:00:00 (xfer#52, to-check=45/117)
output/website/gitbook/gitbook-plugin-prism/prism-duotone-space.css
3342 100% 4.95kB/s 0:00:00 (xfer#53, to-check=44/117)
output/website/gitbook/gitbook-plugin-prism/prism-ghcolors.css
2232 100% 3.31kB/s 0:00:00 (xfer#54, to-check=43/117)
output/website/gitbook/gitbook-plugin-prism/prism-hopscotch.css
1921 100% 2.84kB/s 0:00:00 (xfer#55, to-check=42/117)
output/website/gitbook/gitbook-plugin-prism/prism-pojoaque.css
3932 100% 5.82kB/s 0:00:00 (xfer#56, to-check=41/117)
output/website/gitbook/gitbook-plugin-prism/prism-vs.css
2465 100% 3.64kB/s 0:00:00 (xfer#57, to-check=40/117)
output/website/gitbook/gitbook-plugin-prism/prism-xonokai.css
3373 100% 4.98kB/s 0:00:00 (xfer#58, to-check=39/117)
output/website/gitbook/gitbook-plugin-search-plus/
output/website/gitbook/gitbook-plugin-search-plus/jquery.mark.min.js
13390 100% 19.75kB/s 0:00:00 (xfer#59, to-check=37/117)
output/website/gitbook/gitbook-plugin-search-plus/search.css
1199 100% 1.77kB/s 0:00:00 (xfer#60, to-check=36/117)
output/website/gitbook/gitbook-plugin-search-plus/search.js
6841 100% 10.08kB/s 0:00:00 (xfer#61, to-check=35/117)
output/website/gitbook/gitbook-plugin-sharing-plus/
output/website/gitbook/gitbook-plugin-sharing-plus/buttons.js
3207 100% 4.72kB/s 0:00:00 (xfer#62, to-check=33/117)
output/website/gitbook/gitbook-plugin-splitter/
output/website/gitbook/gitbook-plugin-splitter/splitter.css
503 100% 0.74kB/s 0:00:00 (xfer#63, to-check=31/117)
output/website/gitbook/gitbook-plugin-splitter/splitter.js
3864 100% 5.67kB/s 0:00:00 (xfer#64, to-check=30/117)
output/website/gitbook/gitbook-plugin-tbfed-pagefooter/
output/website/gitbook/gitbook-plugin-tbfed-pagefooter/footer.css
271 100% 0.40kB/s 0:00:00 (xfer#65, to-check=28/117)
output/website/gitbook/gitbook-plugin-theme-comscore/
output/website/gitbook/gitbook-plugin-theme-comscore/test.css
206 100% 0.30kB/s 0:00:00 (xfer#66, to-check=26/117)
output/website/gitbook/gitbook-plugin-theme-comscore/test.js
217 100% 0.31kB/s 0:00:00 (xfer#67, to-check=25/117)
output/website/gitbook/gitbook-plugin-toolbar-button/
output/website/gitbook/gitbook-plugin-toolbar-button/plugin.js
467 100% 0.67kB/s 0:00:00 (xfer#68, to-check=23/117)
output/website/gitbook/images/
output/website/gitbook/images/apple-touch-icon-precomposed-152.png
4817 100% 6.92kB/s 0:00:00 (xfer#69, to-check=21/117)
output/website/gitbook/images/favicon.ico
4286 100% 6.16kB/s 0:00:00 (xfer#70, to-check=20/117)
output/website/restful_doc/
output/website/restful_doc/index.html
21102 100% 30.26kB/s 0:00:00 (xfer#71, to-check=18/117)
output/website/restful_doc/use_markdown.html
31427 100% 45.00kB/s 0:00:00 (xfer#72, to-check=17/117)
output/website/restful_doc/use_postman.html
20978 100% 29.99kB/s 0:00:00 (xfer#73, to-check=16/117)
output/website/restful_doc/use_swagger.html
21432 100% 30.60kB/s 0:00:00 (xfer#74, to-check=15/117)
output/website/restful_experience/
output/website/restful_experience/bad_design.html
24841 100% 35.41kB/s 0:00:00 (xfer#75, to-check=13/117)
output/website/restful_experience/experience_other.html
34513 100% 48.99kB/s 0:00:00 (xfer#76, to-check=12/117)
output/website/restful_experience/index.html
19575 100% 27.70kB/s 0:00:00 (xfer#77, to-check=11/117)
output/website/restful_experience/resp_data_style.html
23782 100% 33.61kB/s 0:00:00 (xfer#78, to-check=10/117)
output/website/restful_intro/
output/website/restful_intro/example.html
22677 100% 32.00kB/s 0:00:00 (xfer#79, to-check=8/117)
output/website/restful_intro/index.html
21931 100% 30.86kB/s 0:00:00 (xfer#80, to-check=7/117)
output/website/restful_rule/
output/website/restful_rule/index.html
19673 100% 27.68kB/s 0:00:00 (xfer#81, to-check=5/117)
output/website/restful_rule/rule.html
24179 100% 33.97kB/s 0:00:00 (xfer#82, to-check=4/117)
output/website/restful_tool/
output/website/restful_tool/framework_lib.html
20002 100% 28.06kB/s 0:00:00 (xfer#83, to-check=2/117)
output/website/restful_tool/index.html
19512 100% 27.34kB/s 0:00:00 (xfer#84, to-check=1/117)
output/website/restful_tool/test_tool.html
20431 100% 28.58kB/s 0:00:00 (xfer#85, to-check=0/117)
sent 26024566 bytes received 2082 bytes 187918.04 bytes/sec
total size is 27477074 speedup is 1.06
【已解决】rsync同步时使用–password-file但是没用仍需要输入密码
【总结】
最后,用代码:
sshpass -f sshpass_password.txt rsync -avz –progress –delete –force /Users/crifan/GitBook/Library/Import/http_restful_api/output/http_restful_api [email protected]:/home/wwwroot/book.crifan.com/books
其中当前文件夹下有sshpass_password.txt存放着密码。
可以实现所需要的效果:
第一次全部同步:
sshpass -f sshpass_password.txt rsync -avz –progress –delete –force /Users/crifan/GitBook/Library/Import/http_restful_api/output/http_restful_api [email protected]:/home/wwwroot/book.crifan.com/books
building file list …
117 files to consider
http_restful_api/
http_restful_api/epub/
http_restful_api/epub/http_restful_api.epub
1787100 100% 9.73MB/s 0:00:00 (xfer#1, to-check=114/117)
http_restful_api/mobi/
http_restful_api/mobi/http_restful_api.mobi
819796 100% 385.82kB/s 0:00:02 (xfer#2, to-check=112/117)
http_restful_api/pdf/
http_restful_api/pdf/http_restful_api.pdf
21286472 100% 332.71kB/s 0:01:02 (xfer#3, to-check=110/117)
http_restful_api/website/
http_restful_api/website/index.html
21353 100% 36.71kB/s 0:00:00 (xfer#4, to-check=108/117)
http_restful_api/website/search_plus_index.json
23466 100% 21.48kB/s 0:00:01 (xfer#5, to-check=107/117)
http_restful_api/website/sitemap.xml
3247 100% 2.97kB/s 0:00:01 (xfer#6, to-check=106/117)
…
http_restful_api/website/restful_rule/rule.html
24179 100% 26.71kB/s 0:00:00 (xfer#82, to-check=4/117)
http_restful_api/website/restful_tool/
http_restful_api/website/restful_tool/framework_lib.html
20002 100% 22.07kB/s 0:00:00 (xfer#83, to-check=2/117)
http_restful_api/website/restful_tool/index.html
19512 100% 21.51kB/s 0:00:00 (xfer#84, to-check=1/117)
http_restful_api/website/restful_tool/test_tool.html
20431 100% 22.49kB/s 0:00:00 (xfer#85, to-check=0/117)
sent 26016951 bytes received 2082 bytes 340118.08 bytes/sec
total size is 27469592 speedup is 1.06
第二次更新文件后,再去同步:
sshpass -f sshpass_password.txt rsync -avz –progress –delete –force /Users/crifan/GitBook/Library/Import/http_restful_api/output/http_restful_api [email protected]:/home/wwwroot/book.crifan.com/books
building file list …
117 files to consider
http_restful_api/
http_restful_api/epub/
http_restful_api/epub/http_restful_api.epub
1785468 100% 54.80MB/s 0:00:00 (xfer#1, to-check=114/117)
http_restful_api/mobi/
http_restful_api/mobi/http_restful_api.mobi
819780 100% 3.54MB/s 0:00:00 (xfer#2, to-check=112/117)
http_restful_api/pdf/
http_restful_api/pdf/http_restful_api.pdf
21286491 100% 24.97MB/s 0:00:00 (xfer#3, to-check=110/117)
http_restful_api/website/
http_restful_api/website/index.html
21353 100% 25.59kB/s 0:00:00 (xfer#4, to-check=108/117)
http_restful_api/website/search_plus_index.json
23466 100% 28.08kB/s 0:00:00 (xfer#5, to-check=107/117)
http_restful_api/website/sitemap.xml
3247 100% 3.88kB/s 0:00:00 (xfer#6, to-check=106/117)
http_restful_api/website/appendix/
http_restful_api/website/appendix/index.html
19400 100% 23.19kB/s 0:00:00 (xfer#7, to-check=104/117)
…
http_restful_api/website/restful_tool/
http_restful_api/website/restful_tool/framework_lib.html
20002 100% 21.70kB/s 0:00:00 (xfer#83, to-check=2/117)
http_restful_api/website/restful_tool/index.html
19512 100% 21.15kB/s 0:00:00 (xfer#84, to-check=1/117)
http_restful_api/website/restful_tool/test_tool.html
20431 100% 22.12kB/s 0:00:00 (xfer#85, to-check=0/117)
sent 286682 bytes received 74142 bytes 65604.36 bytes/sec
total size is 27467997 speedup is 76.13
总体上同步到速度相当快,非常满意。
把上述命令整合到Makefile中后:
# get current folder name
# support call makefile from anywhere, not only from current path of makefile located
# MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
# CURRENT_DIR := $(notdir $(patsubst %/,%,$(MAKEFILE_DIR))
MAKEFILE_LIST_LASTWORD = $(lastword $(MAKEFILE_LIST))
MAKEFILE_PATH := $(abspath $(MAKEFILE_LIST_LASTWORD))
MAKEFILE_DIR := $(dir $(MAKEFILE_PATH))
MAKEFILE_DIR_PATSUBST := $(patsubst %/,%,$(MAKEFILE_DIR))
MAKEFILE_DIR_NOSLASH = $(MAKEFILE_DIR_PATSUBST)
CURRENT_DIR = $(MAKEFILE_DIR)
CURRENT_DIR_NOSLASH = $(MAKEFILE_DIR_NOSLASH)
CURRENT_DIR_NAME := $(notdir $(MAKEFILE_DIR_PATSUBST))
OUTPUT_FOLDER_NAME = output
OUTPUT_PATH = $(CURRENT_DIR_NOSLASH)/$(OUTPUT_FOLDER_NAME)/$(BOOK_NAME)
################################################################################
# Upload to server
################################################################################
PASSWORD_FILE=sshpass_password.txt
REMOTE_USER=root
REMOTE_SERVER=45.79.205.194
REMOTE_BOOKS_PATH=/home/wwwroot/book.crifan.com/books
# REMOTE_PATH=$(REMOTE_BOOKS_PATH)/$(BOOK_NAME)
REMOTE_PATH=$(REMOTE_BOOKS_PATH)
## upload all genereted website/pdf/epub/mobi files to remote server using rsync
upload:
sshpass -f $(PASSWORD_FILE) rsync -avz –progress –delete –force $(OUTPUT_PATH) $(REMOTE_USER)@$(REMOTE_SERVER):$(REMOTE_PATH)
使用方法:
make upload
即可自动上传所有文件:
➜ http_restful_api git:(master) ✗ make upload
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<——————————————————————————
Author : crifan.com
Version : 20171220
Function: Auto use gitbook to generated files: website/pdf/epub/mobi
Run ‘make help’ to see usage
<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<——————————————————————————
sshpass -f sshpass_password.txt rsync -avz –progress –delete –force /Users/crifan/GitBook/Library/Import/http_restful_api/output/http_restful_api [email protected]:/home/wwwroot/book.crifan.com/books
building file list …
117 files to consider
http_restful_api/
http_restful_api/epub/
http_restful_api/epub/http_restful_api.epub
1787100 100% 9.73MB/s 0:00:00 (xfer#1, to-check=114/117)
http_restful_api/mobi/
更加完整的Makefile(和相关命令)可参考:
https://github.com/crifan/gitbook_template/blob/master/GitbookCommon.mk
注意:
此处rsync:
<code>sshpass -f sshpass_password.txt rsync -avz --progress --delete --force /Users/crifan/GitBook/Library/Import/http_restful_api/output/http_restful_api [email protected]:/home/wwwroot/book.crifan.com/books </code>
的SRC和DST:
SRC=/Users/crifan/GitBook/Library/Import/http_restful_api/output/http_restful_api
DST=/home/wwwroot/book.crifan.com/books
的逻辑是:
把源目录:
/Users/crifan/GitBook/Library/Import/http_restful_api/output/http_restful_api
的整个目录,包括目录http_restful_api本身,
都拷贝到目标目录:
/home/wwwroot/book.crifan.com/books
中。
而不是原以为的:
SRC和DST的文件名是一样的:
SRC=/Users/crifan/GitBook/Library/Import/http_restful_api/output/http_restful_api
DST=/home/wwwroot/book.crifan.com/books/http_restful_api
然后同步两个文件夹的内容。
-》为了达到上面的效果:
(1)把之前
/Users/crifan/GitBook/Library/Import/http_restful_api/output
下面新增了个http_restful_api的文件夹,其中有website,pdf等目录:
(2)设置了DST目标文件夹为:
/home/wwwroot/book.crifan.com/books/
而不是之前以为的:
/home/wwwroot/book.crifan.com/books/http_restful_api
总之:
要注意是SRC的整个目录(包括文件夹本身)都直接拷贝到DST目标文件夹下面
-》等价于:
SRC=/xxx/srcFolder
DST=/yyy
-〉/yyy/srcFolder
的效果。
转载请注明:在路上 » 【已解决】用rsync去同步本地文件到远程服务器