{"id":213,"date":"2015-12-02T17:07:54","date_gmt":"2015-12-02T09:07:54","guid":{"rendered":"http:\/\/yyshell.com\/?p=213"},"modified":"2015-12-02T17:13:06","modified_gmt":"2015-12-02T09:13:06","slug":"rsync%e5%91%bd%e4%bb%a4%e4%bd%bf%e7%94%a8%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/yyshell.com\/?p=213","title":{"rendered":"Rsync\u547d\u4ee4\u4f7f\u7528\u6307\u5357"},"content":{"rendered":"<p>Rsync\uff08remote synchronize\uff09\u662f\u4e00\u4e2a\u8fdc\u7a0b\u6570\u636e\u540c\u6b65\u5de5\u5177\uff1b\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u5bf9rsync\u547d\u4ee4\u7684\u4f7f\u7528\u4f5c\u7b80\u8981\u7684\u603b\u7ed3\u3002<\/p>\n<h3>Rsync\u7b80\u4ecb<\/h3>\n<p>Rsync\u53ef\u901a\u8fc7LAN\/WAN\u5feb\u901f\u540c\u6b65\u591a\u53f0\u4e3b\u673a\u4e4b\u95f4\u7684\u6587\u4ef6\uff1b\u4e5f\u53ef\u4ee5\u4f7f\u7528rsync\u540c\u6b65\u672c\u5730\u786c\u76d8\u4e2d\u7684\u4e0d\u540c\u76ee\u5f55\u3002\u5b83\u4f7f\u7528\u6240\u8c13\u7684rsync\u7b97\u6cd5\u8fdb\u884c\u6570\u636e \u540c\u6b65\uff0c\u8fd9\u79cd\u7b97\u6cd5\u53ea\u4f20\u9001\u4e24\u4e2a\u6587\u4ef6\u7684\u4e0d\u540c\u90e8\u5206\uff0c\u800c\u4e0d\u662f\u6bcf\u6b21\u90fd\u6574\u4efd\u4f20\u9001\uff0c\u56e0\u6b64\u901f\u5ea6\u76f8\u5f53\u5feb\u3002rsync\u7684\u521d\u59cb\u4f5c\u8005\u662fAndrew Tridgell\u548cPaul Mackerras\uff0c\u76ee\u524d\u7531<a href=\"http:\/\/rsync.samba.org\">http:\/\/rsync.samba.org<\/a>\u7ef4\u62a4\u3002<\/p>\n<p>\u5728\u4f7f\u7528rsync\u8fdb\u884c\u8fdc\u7a0b\u540c\u6b65\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e24\u79cd\u65b9\u5f0f\uff1a<\/p>\n<ul>\n<li>\u8fdc\u7a0bShell\u65b9\u5f0f\uff08\u5efa\u8bae\u4f7f\u7528ssh\uff0c\u7528\u6237\u9a8c\u8bc1\u7531ssh\u8d1f\u8d23\uff09<\/li>\n<li>C\/S\u65b9\u5f0f\uff08\u5373\u5ba2\u6237\u8fde\u63a5\u8fdc\u7a0brsync\u670d\u52a1\u5668\uff0c\u7528\u6237\u9a8c\u8bc1\u7531rsync\u670d\u52a1\u5668\u8d1f\u8d23\uff09\u3002<\/li>\n<\/ul>\n<h3>Rsync\u547d\u4ee4\u683c\u5f0f<\/h3>\n<blockquote><p>rsync [OPTION&#8230;] SRC&#8230; [DEST] #\u5728\u672c\u5730\u8fdb\u884c\u590d\u5236\u64cd\u4f5c<\/p>\n<p>rsync [OPTION&#8230;] [USER@]HOST:SRC&#8230; [DEST] #\u62c9\u52a8\u4f5c\uff0c\u4ece\u8fdc\u7a0b\u4e3b\u673a\u62c9\u6587\u4ef6\u5230\u672c\u5730<\/p>\n<p>rsync [OPTION&#8230;] SRC&#8230; [USER@]HOST:DEST #\u63a8\u52a8\u4f5c\uff0c\u628a\u672c\u5730\u6587\u4ef6\u63a8\u9001\u5230\u8fdc\u7a0b\u4e3b\u673a<\/p>\n<p>\u901a\u8fc7rsync\u670d\u52a1\u5668\u8bbf\u95ee:<\/p>\n<p>Pull: rsync [OPTION&#8230;] [USER@]HOST::SRC&#8230; [DEST]<\/p>\n<p>Pull: rsync [OPTION&#8230;] rsync:\/\/[USER@]HOST[:PORT]\/SRC&#8230; [DEST]<\/p>\n<p>Push: rsync [OPTION&#8230;] SRC&#8230; [USER@]HOST::DEST<\/p>\n<p>Push: rsync [OPTION&#8230;] SRC&#8230; rsync:\/\/[USER@]HOST[:PORT]\/DEST<\/p>\n<p>\u8bf4\u660e\uff1a<\/p>\n<p>SRC\u662f\u8981\u540c\u6b65\u7684\u6e90\u4f4d\u7f6e\uff1bDEST\u662f\u8981\u540c\u6b65\u7684\u76ee\u6807\u4f4d\u7f6e\uff1bOPTION\u662frsync\u7684\u53c2\u6570\u9009\u9879\uff1b<\/p>\n<p>\u4f7f\u7528\u8fdc\u7a0bshell\u540c\u6b65\u65f6\uff0c\u4e3b\u673a\u540d\u4e0e\u8d44\u6e90\u4e4b\u95f4\u4f7f\u7528\u5355\u4e2a\u5192\u53f7\u201c:\u201d\u4f5c\u4e3a\u5206\u9694\u7b26\uff1b<\/p>\n<p>\u4f7f\u7528rsync\u670d\u52a1\u5668\u540c\u6b65\u65f6\uff0c\u4e3b\u673a\u540d\u4e0e\u8d44\u6e90\u4e4b\u95f4\u4f7f\u7528\u4e24\u4e2a\u5192\u53f7\u201c::\u201d\u4f5c\u4e3a\u5206\u9694\u7b26\uff1b<\/p>\n<p>\u5f53\u8bbf\u95eersync\u670d\u52a1\u5668\u65f6\u4e5f\u53ef\u4ee5\u4f7f\u7528rsync:\/\/URL\uff1b<\/p><\/blockquote>\n<h3>Rsync\u4f7f\u7528\u5b9e\u4f8b<\/h3>\n<h4>1. \u5728\u672c\u5730\u76ee\u5f55\u8fdb\u884c\u6570\u636e\u7684\u590d\u5236\uff1a<\/h4>\n<pre class=\"lang:default decode:true \">$ rsync -zva \/dev\/mytest\/ \/opt\/project\/<\/pre>\n<p>\u4f7f\u7528-a\u9009\u9879\u4fdd\u7559\u539f\u6587\u4ef6\u65f6\u95f4\u6233\u3001\u5c5e\u4e3b\/\u5c5e\u7ec4\u3001\u6743\u9650\u5c5e\u6027\uff0c\u5305\u542b\u9012\u5f52\u7684\u4f5c\u7528\uff1b\u4f7f\u7528-z\u9009\u9879\u8868\u793a\u4f20\u8f93\u524d\u8fdb\u884c\u538b\u7f29\uff1b\u4f7f\u7528-v\u9009\u9879\u663e\u793a\u547d\u4ee4\u6267\u884c\u8be6\u7ec6\u4fe1\u606f\u3002<\/p>\n<pre class=\"lang:default decode:true \">$ rsync -zvau --existing \/dev\/mytest\/ \/opt\/project\/<\/pre>\n<p>\u4f7f\u7528 &#8211;existing \u9009\u9879\u53ef\u53ea\u5bf9\u76ee\u7684\u5730\u5df2\u7ecf\u6709\u7684\u6587\u4ef6\u8fdb\u884c\u540c\u6b65\uff0c\u800c\u4e0d\u7406\u4f1a\u6e90\u76ee\u5f55\u65b0\u589e\u7684\u6587\u4ef6\uff1b\u5982\u679c\u5bf9\u6e90\u6587\u4ef6\u548c\u76ee\u7684\u5730\u6587\u4ef6\u5747\u4f5c\u4e86\u4fee\u6539\uff0c\u540c\u65f6\u60f3\u5c06\u6e90\u6587\u4ef6\u4f5c\u7684\u4fee\u6539\u540c\u6b65\u5230\u76ee\u7684\u5730\uff0c\u4f46\u53c8\u4fdd\u7559\u5bf9\u76ee\u7684\u5730\u6587\u4ef6\u7684\u66f4\u6539\uff0c\u6b64\u65f6\u53ef\u4ee5\u4f7f\u7528-u \u9009\u9879\u3002<\/p>\n<pre class=\"lang:default decode:true \">$ rsync -zva --max-size='1M' \/dev\/mytest\/ \/opt\/project\/<\/pre>\n<p>\u4f7f\u7528&#8211;max-size\u9009\u9879\u53ef\u4ee5\u9650\u5236\u4f20\u8f93\u6587\u4ef6\u7684\u6700\u5927\u5927\u5c0f\uff0c\u5373\u5927\u4e8e&#8211;max-size\u8bbe\u7f6e\u7684\u503c\u7684\u6587\u4ef6\u4e0d\u8fdb\u884c\u4f20\u8f93\u3002<\/p>\n<h4>2. \u672c\u5730\u548c\u8fdc\u7a0b\u4e3b\u673a\u6570\u636e\u7684\u540c\u6b65 \uff1a<\/h4>\n<pre class=\"lang:default decode:true \">$ rsync -azv --delete --progress \/home\/test\/dev\/ caiyiting@192.168.1.201:\/home\/test\/<\/pre>\n<p>\u628a\u672c\u5730\u6570\u636e\u540c\u6b65\u5230\u8fdc\u7a0b\u4e3b\u673a\uff1b\u4f7f\u7528&#8211;delete\u9009\u9879\u80fd\u5220\u9664\u4e0d\u5b58\u5728\u4e8e\u6e90\u76ee\u5f55\u7684\u76ee\u7684\u5730\u6587\u4ef6\u6216\u6587\u4ef6\u5939\uff1b\u4f7f\u7528&#8211;progress\u9009\u9879\u53ef\u4ee5\u663e\u793a\u540c\u6b65\u7684\u8fdb\u5ea6\u3002<\/p>\n<pre class=\"lang:default decode:true \">$ rsync --delete -avzP -e 'ssh -p 2222' root@192.168.1.201:\/opt\/* \/data<\/pre>\n<p>\u4ece\u8fdc\u7a0b\u4e3b\u673a\u540c\u6b65\u6570\u636e\u5230\u672c\u5730\uff1b\u4f7f\u7528&#8211;partial\u6216-P\u9009\u9879\u80fd\u4fdd\u7559\u90a3\u4e9b\u56e0\u6545\u6ca1\u6709\u5b8c\u5168\u4f20\u8f93\u7684\u6587\u4ef6\uff0c\u4ee5\u52a0\u5feb\u968f\u540e\u7684\u518d\u6b21\u4f20\u8f93\u7684\u901f\u5ea6\uff1b\u4f7f\u7528-e &#8216;ssh -p 2222&#8217;\u6307\u5b9a\u4f7f\u7528SSH\u901a\u9053\u4f20\u8f93\uff0c\u4e14\u7aef\u53e3\u53f7\u4e3a2222\u3002<\/p>\n<h4>3. \u7b5b\u9009rsync\u540c\u6b65\u7684\u5185\u5bb9\uff1a<\/h4>\n<pre class=\"lang:default decode:true \">$ rsync -avz --include '*\/' --exclude '*' root@192.168.1.201:\/var\/wwwroot\/ \/opt\/wwwroot\/<\/pre>\n<p>\u4f7f\u7528&#8211;exclude \u9009\u9879\u6392\u9664\u6e90\u76ee\u5f55\u4e2d\u8981\u4f20\u8f93\u7684\u6587\u4ef6\uff1b\u4f7f\u7528&#8211;include \u9009\u9879\u6307\u5b9a\u8981\u4f20\u8f93\u7684\u6587\u4ef6\uff1b\u4e0a\u9762\u7684\u4f8b\u5b50\u4ec5\u540c\u6b65\u76ee\u5f55\u7ed3\u6784\u800c\u5ffd\u7565\u6389\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6\u3002\u5305\u542b\uff08include\uff09\u548c\u6392\u9664\uff08exclude\uff09\u89c4\u5219\u7684\u8bed\u6cd5\u53c2\u89c1<a href=\"http:\/\/rsync.samba.org\/ftp\/rsync\/rsync.html\">rsync man page<\/a>\u3002<\/p>\n<h4>4. \u901a\u8fc7rsync\u670d\u52a1\u5668\u540c\u6b65\u6570\u636e<\/h4>\n<pre class=\"lang:default decode:true \">$ rsync -vzrtopg --delete test@192.168.1.201::Data \/opt\/data --password-file=\/etc\/rsyncd.secrets<\/pre>\n<p>\u628a\u8fdc\u7a0brsync\u670d\u52a1\u5668\u7684\u8d44\u6e90Data\u63a8\u9001\u5230\u6307\u5b9a\u7684\u672c\u5730\u76ee\u5f55\u4e2d\uff1b\u4f7f\u7528\u9009\u9879&#8211;password-file \u6307\u5b9a\u540c\u6b65\u7684\u5bc6\u94a5\uff1b\u4f7f\u7528\u9009\u9879-r \u80fd\u591f\u9012\u5f52\u62f7\u8d1d\u76ee\u5f55\uff1b\u4f7f\u7528-t\u6216&#8211;times \u9009\u9879\u80fd\u591f\u4fdd\u6301\u6587\u4ef6\u7684\u65f6\u95f4\u4fe1\u606f\uff1b\u4f7f\u7528-o\u6216&#8211;owner \u9009\u9879\u4fdd\u6301\u6587\u4ef6\u5c5e\u4e3b\u4fe1\u606f\uff1b\u4f7f\u7528-p\u6216&#8211;perms \u9009\u9879\u4fdd\u6301\u6587\u4ef6\u6743\u9650\uff1b\u4f7f\u7528-g\u6216&#8211;group \u9009\u9879 \u4fdd\u6301\u6587\u4ef6\u5c5e\u7ec4\u4fe1\u606f\u3002<\/p>\n<pre class=\"lang:default decode:true \">$ rsync -aqzH --delete --delay-updates rsync:\/\/mirrors.sohu.com\/ubuntu\/ \/var\/www\/mirror\/ubuntu<\/pre>\n<p>\u4ece\u63d0\u4f9brsync \u670d\u52a1\u7684\u955c\u50cf\u7ad9\u70b9\u540c\u6b65\u955c\u50cf\u5230\u672c\u5730\uff1b\u4f7f\u7528-q \u9009\u9879\u5b9e\u73b0\u7cbe\u7b80\u8f93\u51fa\u6a21\u5f0f\uff1b\u4f7f\u7528&#8211;delay-updates \u9009\u9879\u80fd\u5c06\u6b63\u5728\u66f4\u65b0\u7684\u6587\u4ef6\u5148\u4fdd\u5b58\u5230\u4e34\u65f6\u76ee\u5f55\uff0c\u5f85\u4f20\u8f93\u5b8c\u6bd5\u518d\u66f4\u65b0\u76ee\u6807\u6587\u4ef6\u3002<\/p>\n<p>\u66f4\u591a\u7684rsync\u7684\u9009\u9879\uff0c\u53ef\u53c2\u770b<a href=\"http:\/\/rsync.samba.org\/ftp\/rsync\/rsync.html\">rsync man page<\/a>\u3002<\/p>\n<p>\u53c2\u8003\u6587\u7ae0\uff1a<\/p>\n<p><a href=\"http:\/\/rsync.samba.org\/ftp\/rsync\/rsync.html\">http:\/\/rsync.samba.org\/ftp\/rsync\/rsync.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Rsync\uff08remote synchronize\uff09\u662f\u4e00\u4e2a\u8fdc\u7a0b\u6570\u636e\u540c\u6b65\u5de5\u5177\uff1b\u8fd9\u7bc7\u6587<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-213","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/yyshell.com\/index.php?rest_route=\/wp\/v2\/posts\/213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yyshell.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yyshell.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yyshell.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yyshell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=213"}],"version-history":[{"count":3,"href":"https:\/\/yyshell.com\/index.php?rest_route=\/wp\/v2\/posts\/213\/revisions"}],"predecessor-version":[{"id":216,"href":"https:\/\/yyshell.com\/index.php?rest_route=\/wp\/v2\/posts\/213\/revisions\/216"}],"wp:attachment":[{"href":"https:\/\/yyshell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yyshell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yyshell.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}