﻿{"id":1491,"date":"2016-12-21T16:05:38","date_gmt":"2016-12-21T08:05:38","guid":{"rendered":"http:\/\/nick.txtcc.com\/?p=1491"},"modified":"2016-12-21T16:05:40","modified_gmt":"2016-12-21T08:05:40","slug":"linux-%e4%b8%8b%e4%bd%bf%e7%94%a8-rsync-%e8%bf%9b%e8%a1%8c%e6%96%87%e4%bb%b6-%e5%90%8c%e6%ad%a5","status":"publish","type":"post","link":"http:\/\/nick.txtcc.com\/index.php\/linux\/1491","title":{"rendered":"linux \u4e0b\u4f7f\u7528 rsync \u8fdb\u884c\u6587\u4ef6 \u540c\u6b65"},"content":{"rendered":"<h2>rsync \u4ecb\u7ecd<\/h2>\n<p><a href=\"http:\/\/zh.wikipedia.org\/zh-cn\/Rsync\" target=\"_blank\">rsync<\/a>\u662f\u7c7bunix\u7cfb\u7edf\u4e0b\u7684\u6570\u636e\u955c\u50cf\u5907\u4efd\u5de5\u5177\u2014\u2014remote sync\u3002<\/p>\n<p>rsync\u662f\u4e00\u4e2a\u529f\u80fd\u975e\u5e38\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u5176\u547d\u4ee4\u4e5f\u6709\u5f88\u591a\u529f\u80fd\u7279\u8272\u9009\u9879\uff0c\u6211\u4eec\u4e0b\u9762\u5c31\u5bf9\u5b83\u7684\u9009\u9879\u4e00\u4e00\u8fdb\u884c\u5206\u6790\u8bf4\u660e\u3002<\/p>\n<p>\u5b83\u7684\u7279\u6027\u5982\u4e0b\uff1a<\/p>\n<p>\u53ef\u4ee5\u955c\u50cf\u4fdd\u5b58\u6574\u4e2a\u76ee\u5f55\u6811\u548c\u6587\u4ef6\u7cfb\u7edf\u3002<\/p>\n<p>\u53ef\u4ee5\u5f88\u5bb9\u6613\u505a\u5230\u4fdd\u6301\u539f\u6765\u6587\u4ef6\u7684\u6743\u9650\u3001\u65f6\u95f4\u3001\u8f6f\u786c\u94fe\u63a5\u7b49\u7b49\u3002<\/p>\n<p>\u65e0\u987b\u7279\u6b8a\u6743\u9650\u5373\u53ef\u5b89\u88c5\u3002<\/p>\n<p>\u5feb\u901f\uff1a\u7b2c\u4e00\u6b21\u540c\u6b65\u65f6 rsync \u4f1a\u590d\u5236\u5168\u90e8\u5185\u5bb9\uff0c\u4f46\u5728\u4e0b\u4e00\u6b21\u53ea\u4f20\u8f93\u4fee\u6539\u8fc7\u7684\u6587\u4ef6\u3002rsync \u5728\u4f20\u8f93\u6570\u636e\u7684\u8fc7\u7a0b\u4e2d\u53ef\u4ee5\u5b9e\u884c\u538b\u7f29\u53ca\u89e3\u538b\u7f29\u64cd\u4f5c\uff0c<\/p>\n<p>\u56e0\u6b64\u53ef\u4ee5\u4f7f\u7528\u66f4\u5c11\u7684\u5e26\u5bbd\u3002<\/p>\n<p>\u5b89\u5168\uff1a\u53ef\u4ee5\u4f7f\u7528scp\u3001ssh\u7b49\u65b9\u5f0f\u6765\u4f20\u8f93\u6587\u4ef6\uff0c\u5f53\u7136\u4e5f\u53ef\u4ee5\u901a\u8fc7\u76f4\u63a5\u7684socket\u8fde\u63a5\u3002<\/p>\n<p>\u652f\u6301\u533f\u540d\u4f20\u8f93\uff0c\u4ee5\u65b9\u4fbf\u8fdb\u884c\u7f51\u7ad9\u955c\u50cf\u3002<\/p>\n<p>rysnc \u7684\u5b98\u65b9\u7f51\u7ad9\uff1a<a href=\"http:\/\/rsync.samba.org\/\" target=\"_blank\"><a href=\"http:\/\/rsync.samba.org\/\">http:\/\/rsync.samba.org\/<\/a><\/a>\uff0c\u53ef\u4ee5\u4ece\u4e0a\u9762\u5f97\u5230\u6700\u65b0\u7684\u7248\u672c\u3002\u5173\u4e8ersync\u7b97\u6cd5\u7684\u4ecb\u7ecd\u70b9<a href=\"http:\/\/rsync.samba.org\/tech_report\/node2.html\" target=\"_blank\">\u8fd9\u91cc<\/a>\uff0c\u8fd8\u6709<a href=\"http:\/\/coolshell.cn\/articles\/7425.html\" target=\"_blank\">\u9648\u7693blog<\/a>.<\/p>\n<h2><a name=\"t1\"><\/a>rsync\u7684\u4f7f\u7528<\/h2>\n<p>Rsync\u7684\u547d\u4ee4\u683c\u5f0f\u53ef\u4ee5\u4e3a\u4ee5\u4e0b\u516d\u79cd\uff1a<\/p>\n<p>rsync [OPTION]&#8230; SRC DEST<\/p>\n<p>rsync [OPTION]&#8230; SRC [USER@]HOST:DEST<\/p>\n<p>rsync [OPTION]&#8230; [USER@]HOST:SRC DEST<\/p>\n<p>rsync [OPTION]&#8230; [USER@]HOST::SRC DEST<\/p>\n<p>rsync [OPTION]&#8230; SRC [USER@]HOST::DEST<\/p>\n<p>rsync [OPTION]&#8230; rsync:\/\/[USER@]HOST[:PORT]\/SRC [DEST]<\/p>\n<p>rsync\u6709\u516d\u79cd\u4e0d\u540c\u7684\u5de5\u4f5c\u6a21\u5f0f\uff1a<\/p>\n<ol>\n<li>\u62f7\u8d1d\u672c\u5730\u6587\u4ef6\uff1b\u5f53SRC\u548cDEST\u8def\u5f84\u4fe1\u606f\u90fd\u4e0d\u5305\u542b\u6709\u5355\u4e2a\u5192\u53f7&#8221;:&#8221;\u5206\u9694\u7b26\u65f6\u5c31\u542f\u52a8\u8fd9\u79cd\u5de5\u4f5c\u6a21\u5f0f\u3002<\/li>\n<\/ol>\n<p>2.\u4f7f\u7528\u4e00\u4e2a\u8fdc\u7a0bshell\u7a0b\u5e8f\uff08\u5982rsh\u3001ssh\uff09\u6765\u5b9e\u73b0\u5c06\u672c\u5730\u673a\u5668\u7684\u5185\u5bb9\u62f7\u8d1d\u5230\u8fdc\u7a0b\u673a\u5668\u3002\u5f53DEST<\/p>\n<p>\u8def\u5f84\u5730\u5740\u5305\u542b\u5355\u4e2a\u5192\u53f7&#8221;:&#8221;\u5206\u9694\u7b26\u65f6\u542f\u52a8\u8be5\u6a21\u5f0f\u3002<\/p>\n<p>3.\u4f7f\u7528\u4e00\u4e2a\u8fdc\u7a0bshell\u7a0b\u5e8f\uff08\u5982rsh\u3001ssh\uff09\u6765\u5b9e\u73b0\u5c06\u8fdc\u7a0b\u673a\u5668\u7684\u5185\u5bb9\u62f7\u8d1d\u5230\u672c\u5730\u673a\u5668\u3002\u5f53SRC<\/p>\n<p>\u5730\u5740\u8def\u5f84\u5305\u542b\u5355\u4e2a\u5192\u53f7&#8221;:&#8221;\u5206\u9694\u7b26\u65f6\u542f\u52a8\u8be5\u6a21\u5f0f\u3002<\/p>\n<ol start=\"4\">\n<li>\n<p>\u4ece\u8fdc\u7a0brsync\u670d\u52a1\u5668\u4e2d\u62f7\u8d1d\u6587\u4ef6\u5230\u672c\u5730\u673a\u3002\u5f53SRC\u8def\u5f84\u4fe1\u606f\u5305\u542b&#8221;::&#8221;\u5206\u9694\u7b26\u65f6\u542f\u52a8\u8be5\u6a21\u5f0f\u3002<\/p>\n<\/li>\n<li>\n<p>\u4ece\u672c\u5730\u673a\u5668\u62f7\u8d1d\u6587\u4ef6\u5230\u8fdc\u7a0brsync\u670d\u52a1\u5668\u4e2d\u3002\u5f53DEST\u8def\u5f84\u4fe1\u606f\u5305\u542b&#8221;::&#8221;\u5206\u9694\u7b26\u65f6\u542f\u52a8\u8be5\u6a21\u5f0f\u3002<\/p>\n<\/li>\n<li>\n<p>\u5217\u8fdc\u7a0b\u673a\u7684\u6587\u4ef6\u5217\u8868\u3002\u8fd9\u7c7b\u4f3c\u4e8ersync\u4f20\u8f93\uff0c\u4e0d\u8fc7\u53ea\u8981\u5728\u547d\u4ee4\u4e2d\u7701\u7565\u6389\u672c\u5730\u673a\u4fe1\u606f\u5373\u53ef\u3002<\/p>\n<\/li>\n<\/ol>\n<p>\u53ef\u4ee5man rsync \u53c2\u8003 rsync \u6587\u6863\uff0c\u4e86\u89e3\u8be6\u7ec6\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u4e0b\u9762\u89e3\u6790\u4e00\u4e9b\u53c2\u6570\u7684\u4f7f\u7528\uff1a<\/p>\n<p>rsync\u53c2\u6570\u7684\u5177\u4f53\u89e3\u91ca\u5982\u4e0b\uff1a<\/p>\n<p>-v, &#8211;verbose \u8be6\u7ec6\u6a21\u5f0f\u8f93\u51fa<\/p>\n<p>-q, &#8211;quiet \u7cbe\u7b80\u8f93\u51fa\u6a21\u5f0f<\/p>\n<p>-c, &#8211;checksum \u6253\u5f00\u6821\u9a8c\u5f00\u5173\uff0c\u5f3a\u5236\u5bf9\u6587\u4ef6\u4f20\u8f93\u8fdb\u884c\u6821\u9a8c<\/p>\n<p>-a, &#8211;archive \u5f52\u6863\u6a21\u5f0f\uff0c\u8868\u793a\u4ee5\u9012\u5f52\u65b9\u5f0f\u4f20\u8f93\u6587\u4ef6\uff0c\u5e76\u4fdd\u6301\u6240\u6709\u6587\u4ef6\u5c5e\u6027\uff0c\u7b49\u4e8e-rlptgoD<\/p>\n<p>-r, &#8211;recursive \u5bf9\u5b50\u76ee\u5f55\u4ee5\u9012\u5f52\u6a21\u5f0f\u5904\u7406<\/p>\n<p>-R, &#8211;relative \u4f7f\u7528\u76f8\u5bf9\u8def\u5f84\u4fe1\u606f<\/p>\n<p>-b, &#8211;backup \u521b\u5efa\u5907\u4efd\uff0c\u4e5f\u5c31\u662f\u5bf9\u4e8e\u76ee\u7684\u5df2\u7ecf\u5b58\u5728\u6709\u540c\u6837\u7684\u6587\u4ef6\u540d\u65f6\uff0c\u5c06\u8001\u7684\u6587\u4ef6\u91cd\u65b0\u547d\u540d\u4e3a~filename\u3002\u53ef\u4ee5\u4f7f\u7528&#8211;suffix\u9009\u9879\u6765\u6307\u5b9a\u4e0d\u540c\u7684\u5907\u4efd\u6587\u4ef6\u524d\u7f00\u3002<\/p>\n<p>&#8211;backup-dir \u5c06\u5907\u4efd\u6587\u4ef6(\u5982~filename)\u5b58\u653e\u5728\u5728\u76ee\u5f55\u4e0b\u3002<\/p>\n<p>-suffix=SUFFIX \u5b9a\u4e49\u5907\u4efd\u6587\u4ef6\u524d\u7f00<\/p>\n<p>-u, &#8211;update \u4ec5\u4ec5\u8fdb\u884c\u66f4\u65b0\uff0c\u4e5f\u5c31\u662f\u8df3\u8fc7\u6240\u6709\u5df2\u7ecf\u5b58\u5728\u4e8eDST\uff0c\u5e76\u4e14\u6587\u4ef6\u65f6\u95f4\u665a\u4e8e\u8981\u5907\u4efd\u7684\u6587\u4ef6\u3002(\u4e0d\u8986\u76d6\u66f4\u65b0\u7684\u6587\u4ef6)<\/p>\n<p>-l, &#8211;links \u4fdd\u7559\u8f6f\u94fe\u7ed3<\/p>\n<p>-L, &#8211;copy-links \u60f3\u5bf9\u5f85\u5e38\u89c4\u6587\u4ef6\u4e00\u6837\u5904\u7406\u8f6f\u94fe\u7ed3<\/p>\n<p>&#8211;copy-unsafe-links \u4ec5\u4ec5\u62f7\u8d1d\u6307\u5411SRC\u8def\u5f84\u76ee\u5f55\u6811\u4ee5\u5916\u7684\u94fe\u7ed3<\/p>\n<p>&#8211;safe-links \u5ffd\u7565\u6307\u5411SRC\u8def\u5f84\u76ee\u5f55\u6811\u4ee5\u5916\u7684\u94fe\u7ed3<\/p>\n<p>-H, &#8211;hard-links \u4fdd\u7559\u786c\u94fe\u7ed3<\/p>\n<p>-p, &#8211;perms \u4fdd\u6301\u6587\u4ef6\u6743\u9650<\/p>\n<p>-o, &#8211;owner \u4fdd\u6301\u6587\u4ef6\u5c5e\u4e3b\u4fe1\u606f<\/p>\n<p>-g, &#8211;group \u4fdd\u6301\u6587\u4ef6\u5c5e\u7ec4\u4fe1\u606f<\/p>\n<p>-D, &#8211;devices \u4fdd\u6301\u8bbe\u5907\u6587\u4ef6\u4fe1\u606f<\/p>\n<p>-t, &#8211;times \u4fdd\u6301\u6587\u4ef6\u65f6\u95f4\u4fe1\u606f<\/p>\n<p>-S, &#8211;sparse \u5bf9\u7a00\u758f\u6587\u4ef6\u8fdb\u884c\u7279\u6b8a\u5904\u7406\u4ee5\u8282\u7701DST\u7684\u7a7a\u95f4<\/p>\n<p>-n, &#8211;dry-run\u73b0\u5b9e\u54ea\u4e9b\u6587\u4ef6\u5c06\u88ab\u4f20\u8f93<\/p>\n<p>-W, &#8211;whole-file \u62f7\u8d1d\u6587\u4ef6\uff0c\u4e0d\u8fdb\u884c\u589e\u91cf\u68c0\u6d4b<\/p>\n<p>-x, &#8211;one-file-system \u4e0d\u8981\u8de8\u8d8a\u6587\u4ef6\u7cfb\u7edf\u8fb9\u754c<\/p>\n<p>-B, &#8211;block-size=SIZE \u68c0\u9a8c\u7b97\u6cd5\u4f7f\u7528\u7684\u5757\u5c3a\u5bf8\uff0c\u9ed8\u8ba4\u662f700\u5b57\u8282<\/p>\n<p>-e, &#8211;rsh=COMMAND \u6307\u5b9a\u4f7f\u7528rsh\u3001ssh\u65b9\u5f0f\u8fdb\u884c\u6570\u636e\u540c\u6b65<\/p>\n<p>&#8211;rsync-path=PATH \u6307\u5b9a\u8fdc\u7a0b\u670d\u52a1\u5668\u4e0a\u7684rsync\u547d\u4ee4\u6240\u5728\u8def\u5f84\u4fe1\u606f<\/p>\n<p>-C, &#8211;cvs-exclude \u4f7f\u7528\u548cCVS\u4e00\u6837\u7684\u65b9\u6cd5\u81ea\u52a8\u5ffd\u7565\u6587\u4ef6\uff0c\u7528\u6765\u6392\u9664\u90a3\u4e9b\u4e0d\u5e0c\u671b\u4f20\u8f93\u7684\u6587\u4ef6<\/p>\n<p>&#8211;existing \u4ec5\u4ec5\u66f4\u65b0\u90a3\u4e9b\u5df2\u7ecf\u5b58\u5728\u4e8eDST\u7684\u6587\u4ef6\uff0c\u800c\u4e0d\u5907\u4efd\u90a3\u4e9b\u65b0\u521b\u5efa\u7684\u6587\u4ef6<\/p>\n<p>&#8211;delete \u5220\u9664\u90a3\u4e9bDST\u4e2dSRC\u6ca1\u6709\u7684\u6587\u4ef6<\/p>\n<p>&#8211;delete-excluded \u540c\u6837\u5220\u9664\u63a5\u6536\u7aef\u90a3\u4e9b\u88ab\u8be5\u9009\u9879\u6307\u5b9a\u6392\u9664\u7684\u6587\u4ef6<\/p>\n<p>&#8211;delete-after \u4f20\u8f93\u7ed3\u675f\u4ee5\u540e\u518d\u5220\u9664<\/p>\n<p>&#8211;ignore-errors \u53ca\u65f6\u51fa\u73b0IO\u9519\u8bef\u4e5f\u8fdb\u884c\u5220\u9664<\/p>\n<p>&#8211;max-delete=NUM \u6700\u591a\u5220\u9664NUM\u4e2a\u6587\u4ef6<\/p>\n<p>&#8211;partial \u4fdd\u7559\u90a3\u4e9b\u56e0\u6545\u6ca1\u6709\u5b8c\u5168\u4f20\u8f93\u7684\u6587\u4ef6\uff0c\u4ee5\u662f\u52a0\u5feb\u968f\u540e\u7684\u518d\u6b21\u4f20\u8f93<\/p>\n<p>&#8211;force \u5f3a\u5236\u5220\u9664\u76ee\u5f55\uff0c\u5373\u4f7f\u4e0d\u4e3a\u7a7a<\/p>\n<p>&#8211;numeric-ids \u4e0d\u5c06\u6570\u5b57\u7684\u7528\u6237\u548c\u7ec4ID\u5339\u914d\u4e3a\u7528\u6237\u540d\u548c\u7ec4\u540d<\/p>\n<p>&#8211;timeout=TIME IP\u8d85\u65f6\u65f6\u95f4\uff0c\u5355\u4f4d\u4e3a\u79d2<\/p>\n<p>-I, &#8211;ignore-times \u4e0d\u8df3\u8fc7\u90a3\u4e9b\u6709\u540c\u6837\u7684\u65f6\u95f4\u548c\u957f\u5ea6\u7684\u6587\u4ef6<\/p>\n<p>&#8211;size-only \u5f53\u51b3\u5b9a\u662f\u5426\u8981\u5907\u4efd\u6587\u4ef6\u65f6\uff0c\u4ec5\u4ec5\u5bdf\u770b\u6587\u4ef6\u5927\u5c0f\u800c\u4e0d\u8003\u8651\u6587\u4ef6\u65f6\u95f4<\/p>\n<p>&#8211;modify-window=NUM \u51b3\u5b9a\u6587\u4ef6\u662f\u5426\u65f6\u95f4\u76f8\u540c\u65f6\u4f7f\u7528\u7684\u65f6\u95f4\u6233\u7a97\u53e3\uff0c\u9ed8\u8ba4\u4e3a0<\/p>\n<p>-T &#8211;temp-dir=DIR \u5728DIR\u4e2d\u521b\u5efa\u4e34\u65f6\u6587\u4ef6<\/p>\n<p>&#8211;compare-dest=DIR \u540c\u6837\u6bd4\u8f83DIR\u4e2d\u7684\u6587\u4ef6\u6765\u51b3\u5b9a\u662f\u5426\u9700\u8981\u5907\u4efd<\/p>\n<p>-P \u7b49\u540c\u4e8e &#8211;partial<\/p>\n<p>&#8211;progress \u663e\u793a\u5907\u4efd\u8fc7\u7a0b<\/p>\n<p>-z, &#8211;compress \u5bf9\u5907\u4efd\u7684\u6587\u4ef6\u5728\u4f20\u8f93\u65f6\u8fdb\u884c\u538b\u7f29\u5904\u7406<\/p>\n<p>&#8211;exclude=PATTERN \u6307\u5b9a\u6392\u9664\u4e0d\u9700\u8981\u4f20\u8f93\u7684\u6587\u4ef6\u6a21\u5f0f<\/p>\n<p>&#8211;include=PATTERN \u6307\u5b9a\u4e0d\u6392\u9664\u800c\u9700\u8981\u4f20\u8f93\u7684\u6587\u4ef6\u6a21\u5f0f<\/p>\n<p>&#8211;exclude-from=FILE \u6392\u9664FILE\u4e2d\u6307\u5b9a\u6a21\u5f0f\u7684\u6587\u4ef6<\/p>\n<p>&#8211;include-from=FILE \u4e0d\u6392\u9664FILE\u6307\u5b9a\u6a21\u5f0f\u5339\u914d\u7684\u6587\u4ef6<\/p>\n<p>&#8211;version \u6253\u5370\u7248\u672c\u4fe1\u606f<\/p>\n<p>\u7b49\u7b49&#8230;<\/p>\n<p>\u4e0b\u9762\u4e3e\u4f8b\u8bf4\u660ersync\u7684\u516d\u79cd\u4e0d\u540c\u5de5\u4f5c\u6a21\u5f0f:<\/p>\n<p>1)\u62f7\u8d1d\u672c\u5730\u6587\u4ef6\u3002\u5f53SRC\u548cDES\u8def\u5f84\u4fe1\u606f\u90fd\u4e0d\u5305\u542b\u6709\u5355\u4e2a\u5192\u53f7&#8221;:&#8221;\u5206\u9694\u7b26\u65f6\u5c31\u542f\u52a8\u8fd9\u79cd\u5de5\u4f5c\u6a21\u5f0f\u3002\n\u5982\uff1arsync -a\u00a0 .\/test.c\u00a0 \/backup<\/p>\n<p>2)\u4f7f\u7528\u4e00\u4e2a\u8fdc\u7a0bshell\u7a0b\u5e8f(\u5982rsh\u3001ssh)\u6765\u5b9e\u73b0\u5c06\u672c\u5730\u673a\u5668\u7684\u5185\u5bb9\u62f7\u8d1d\u5230\u8fdc\u7a0b\u673a\u5668\u3002\u5f53DES\u8def\u5f84\u5730\u5740\u5305\u542b\u5355\u4e2a\u5192\u53f7&#8221;:&#8221;\u5206\u9694\u7b26\u65f6\u542f\u52a8\u8be5\u6a21\u5f0f\u3002<\/p>\n<p>\u5982\uff1arsync -avz\u00a0 test.c\u00a0 user@172.16.0.11:\/home\/user\/src<\/p>\n<p>3)\u4f7f\u7528\u4e00\u4e2a\u8fdc\u7a0bshell\u7a0b\u5e8f(\u5982rsh\u3001ssh)\u6765\u5b9e\u73b0\u5c06\u8fdc\u7a0b\u673a\u5668\u7684\u5185\u5bb9\u62f7\u8d1d\u5230\u672c\u5730\u673a\u5668\u3002\u5f53SRC\u5730\u5740\u8def\u5f84\u5305\u542b\u5355\u4e2a\u5192\u53f7&#8221;:&#8221;\u5206\u9694\u7b26\u65f6\u542f\u52a8\u8be5\u6a21\u5f0f\u3002<\/p>\n<p>\u5982\uff1arsync -avz user@172.16.0.11:\/home\/user\/src\u00a0 .\/src<\/p>\n<p>4)\u4ece\u8fdc\u7a0brsync\u670d\u52a1\u5668\u4e2d\u62f7\u8d1d\u6587\u4ef6\u5230\u672c\u5730\u673a\u3002\u5f53SRC\u8def\u5f84\u4fe1\u606f\u5305\u542b&#8221;::&#8221;\u5206\u9694\u7b26\u65f6\u542f\u52a8\u8be5\u6a21\u5f0f\u3002<\/p>\n<p>\u5982\uff1arsync -av user@172.16.0.11::www\u00a0 \/databack<\/p>\n<p>5)\u4ece\u672c\u5730\u673a\u5668\u62f7\u8d1d\u6587\u4ef6\u5230\u8fdc\u7a0brsync\u670d\u52a1\u5668\u4e2d\u3002\u5f53DES\u8def\u5f84\u4fe1\u606f\u5305\u542b&#8221;::&#8221;\u5206\u9694\u7b26\u65f6\u542f\u52a8\u8be5\u6a21\u5f0f\u3002<\/p>\n<p>\u5982\uff1arsync -av \/databack user@172.16.0.11::www<\/p>\n<p>6)\u5217\u8fdc\u7a0b\u673a\u7684\u6587\u4ef6\u5217\u8868\u3002\u8fd9\u7c7b\u4f3c\u4e8ersync\u4f20\u8f93\uff0c\u4e0d\u8fc7\u53ea\u8981\u5728\u547d\u4ee4\u4e2d\u7701\u7565\u6389\u672c\u5730\u673a\u4fe1\u606f\u5373\u53ef\u3002<\/p>\n<p>\u5982\uff1arsync -v rsync:\/\/172.16.78.192\u00a0 \/www<\/p>\n<h2><a name=\"t2\"><\/a>\u5e38\u89c1\u95ee\u9898\u4e3e\u4f8b:<\/h2>\n<p>ssh\u7aef\u53e3\u66f4\u6539\u540ersync\u7684\u7528\u6cd5<\/p>\n<p>rsync\u6709\u4e24\u79cd\u5e38\u7528\u7684\u8ba4\u8bc1\u65b9\u5f0f\uff0c\u4e00\u79cd\u4e3arsync-daemon\u65b9\u5f0f\uff0c\u53e6\u5916\u4e00\u79cd\u5219\u662fssh\u3002<\/p>\n<p>ssh\u65b9\u5f0f\u6bd4\u8f83\u7f3a\u4e4f\u7075\u6d3b\u6027 \u4e00\u822c\u4e3a\u9996\u9009\uff0c\u4f46\u5f53\u8fdc\u7aef\u670d\u52a1\u5668\u7684ssh\u9ed8\u8ba4\u7aef\u53e3\u88ab\u4fee\u6539\u540e\uff0crsync\u65f6\u627e\u4e0d\u5230\u4e00\u4e2a\u5408\u9002\u7684\u65b9\u6cd5\u6765\u8f93\u5165\u5bf9\u65b9ssh\u670d\u52a1\u7aef\u53e3\u53f7\u3002<\/p>\n<p>\u6bd4\u5982\u73b0\u5728\u5411\u673a\u5668 172.16.0.172 \u4f20\u9001\u6587\u4ef6\uff0c\u4f46\u6b64\u65f6172.16.0.172\u7684ssh\u7aef\u53e3\u5df2\u7ecf\u4e0d\u662f \u9ed8\u8ba4\u768422 \u7aef\u53e3\u3002<\/p>\n<p>\u952e\u5165\u547d\u4ee4 rsync test.c ustc@172.16.0.172:\/home\/ustc\u00a0 \u51fa\u73b0\u5982\u4e0b\u7684\u9519\u8bef:<\/p>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/nick.txtcc.com\/wp-content\/uploads\/remote_image\/2016\/12\/080539Ftt.jpg\" alt=\"\" width=\"634\" height=\"85\" \/>\n<p>\u6211\u4eec\u6ce8\u610f\u5230rsync\u4e2d\u7684\u547d\u4ee4 \u53c2\u6570\u00a0 -e, &#8211;rsh=COMMAND \u6307\u5b9a\u4f7f\u7528rsh\u3001ssh\u65b9\u5f0f\u8fdb\u884c\u6570\u636e\u540c\u6b65\u3002<\/p>\n<p>\u53c2\u6570\u7684\u4f5c\u7528\u662f\u53ef\u4ee5\u4f7f\u7528\u6237\u81ea\u7531\u9009\u62e9\u6b32\u4f7f\u7528\u7684shell\u7a0b\u5e8f\u6765\u8fde\u63a5\u8fdc\u7aef\u670d\u52a1\u5668\uff0c\u5f53\u7136\u4e5f\u53ef\u4ee5\u8bbe\u7f6e\u6210\u4f7f\u7528\u9ed8\u8ba4\u7684ssh\u6765\u8fde\u63a5\uff0c\u4f46\u662f\u8fd9\u6837\u6211\u4eec\u5c31\u53ef\u4ee5\u52a0\u5165ssh\u7684\u53c2\u6570\u4e86\u3002<\/p>\n<p>\u73b0\u5728\u547d\u4ee4\u53ef\u4ee5\u8fd9\u6837\u5199\u4e86: rsync\u00a0 -e\u00a0 &#8216;ssh -p 3333&#8217;\u00a0 test.c\u00a0 ustc@172.16.0.172:\/home\/ustc<\/p>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/nick.txtcc.com\/wp-content\/uploads\/remote_image\/2016\/12\/080540iwn.jpg\" alt=\"\" width=\"631\" height=\"65\" \/>\n<p>\u53ef\u89c1\u8fd9\u662f \u6587\u4ef6\u4f20\u9001\u4fee\u6539ssh\u7aef\u53e3\u540e\u7684\u673a\u5668\u4e0a\u6210\u529f,\u4e0a\u9762\u8bed\u53e5\u4e2d\u4f7f\u7528\u4e86\u5355\u5f15\u53f7\uff0c\u76ee\u7684\u662f\u4e3a\u4e86\u4f7f\u5f15\u53f7\u5185\u7684\u53c2\u6570\u4e3a\u5f15\u53f7\u5185\u7684\u547d\u4ee4\u6240\u7528\u3002\u6ca1\u6709\u5f15\u53f7\u7684\u8bdd\u7cfb\u7edf\u5c31\u4f1a<\/p>\n<p>\u8bc6\u522b-p\u662f\u7ed9rsync\u7684\u4e00\u4e2a\u53c2\u6570\u4e86\u3002<\/p>\n<p>\u66f4\u591a\u4f8b\u5b50\u3002\u3002\u3002<\/p>\n<p>\u53c2\u8003\uff1a<\/p>\n<p><a href=\"http:\/\/blog.csdn.net\/jackdai\/article\/details\/460460\">http:\/\/blog.csdn.net\/jackdai\/article\/details\/460460<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>##\u573a\u666f\n\u670d\u52a1\u5668 A 192.168.1.1\n\u670d\u52a1\u5668 B 192.168.1.2\n\u8981\u5c06 A \u670d\u52a1\u5668\u7684 \/data\/logs \u76ee\u5f55\u540c\u6b65\u5230 B \u670d\u52a1\u5668\u7684 \/home\/logs \u4e0b<\/p>\n<p>##\u6267\u884c\u73af\u5883\n\u64cd\u4f5c\u7cfb\u7edf\uff1a centos 6.2<\/p>\n<p>##\u914d\u7f6e\n\u6211\u4eec\u5c06\u4f7f\u7528 rsync \u7684 daemon \u65b9\u5f0f\u6765\u5b8c\u6210\u4efb\u52a1\n\u767b\u5f55\u5230 A \u670d\u52a1\u5668,\u6267\u884c <code>vim \/etc\/rsyncd.conf<\/code>\n\u6dfb\u52a0<\/p>\n<pre><code>uid = root\ngid = root\nmax connections = 4\npid file = \/var\/run\/rsyncd.pid\n&lt;span class=&quot;operator&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;lock&lt;\/span&gt; &lt;span class=&quot;keyword&quot;&gt;file&lt;\/span&gt; = \/&lt;span class=&quot;keyword&quot;&gt;var&lt;\/span&gt;\/run\/rsync.&lt;span class=&quot;keyword&quot;&gt;lock&lt;\/span&gt;\n&lt;span class=&quot;keyword&quot;&gt;log&lt;\/span&gt; &lt;span class=&quot;keyword&quot;&gt;file&lt;\/span&gt; = \/&lt;span class=&quot;keyword&quot;&gt;var&lt;\/span&gt;\/&lt;span class=&quot;keyword&quot;&gt;log&lt;\/span&gt;\/rsyncd.&lt;span class=&quot;keyword&quot;&gt;log&lt;\/span&gt;\n\n[&lt;span class=&quot;keyword&quot;&gt;logs&lt;\/span&gt;]\n&lt;span class=&quot;keyword&quot;&gt;path&lt;\/span&gt; = \/&lt;span class=&quot;keyword&quot;&gt;data&lt;\/span&gt;\/&lt;span class=&quot;keyword&quot;&gt;logs&lt;\/span&gt;\n&lt;span class=&quot;keyword&quot;&gt;ignore&lt;\/span&gt; &lt;span class=&quot;keyword&quot;&gt;errors&lt;\/span&gt;\n&lt;span class=&quot;keyword&quot;&gt;read&lt;\/span&gt; &lt;span class=&quot;keyword&quot;&gt;only&lt;\/span&gt; = &lt;span class=&quot;literal&quot;&gt;true&lt;\/span&gt;\n&lt;span class=&quot;keyword&quot;&gt;list&lt;\/span&gt; = &lt;span class=&quot;literal&quot;&gt;true&lt;\/span&gt;\nauth &lt;span class=&quot;keyword&quot;&gt;users&lt;\/span&gt; = &lt;span class=&quot;keyword&quot;&gt;backup&lt;\/span&gt;\nsecrets &lt;span class=&quot;keyword&quot;&gt;file&lt;\/span&gt; = \/etc\/rsyncd.pwd&lt;\/span&gt;\n<\/code><\/pre>\n<p>\u4fdd\u5b58\u6587\u4ef6\uff0c\u6267\u884c<code>vim \/etc\/rsyncd.pwd<\/code> \uff0c\u6dfb\u52a0<\/p>\n<pre><code>&lt;span class=&quot;label&quot;&gt;backup:&lt;\/span&gt;dahouduan.com\n<\/code><\/pre>\n<p>\u4fdd\u5b58\u9000\u51fa\uff0c\u6267\u884c <code>chmod 600 \/etc\/rsyncd.pwd<\/code>\n\u542f\u52a8 rsync \u670d\u52a1 \u6267\u884c <code>rsync --daemon<\/code>\n\u767b\u5f55 B \u670d\u52a1\u5668 \uff0c\u6267\u884c <code>vim \/etc\/rsyncd.pwd<\/code> \uff0c\u6dfb\u52a0<\/p>\n<pre><code>&lt;span class=&quot;tag&quot;&gt;dahouduan&lt;\/span&gt;\n&lt;span class=&quot;class&quot;&gt;.com&lt;\/span&gt;\n<\/code><\/pre>\n<p>\u4fdd\u5b58\u9000\u51fa\uff0c\u6267\u884c <code>chmod 600 \/etc\/rsyncd.pwd<\/code>\n\u597d\u4e86\uff0c\u914d\u7f6e\u5df2\u7ecf\u5b8c\u6210\u4e86\uff0c\u73b0\u5728 A \u670d\u52a1\u5668\u4e3a\u670d\u52a1\u7aef B \u670d\u52a1\u5668\u4e3a\u5ba2\u6237\u7aef\uff0c\u73b0\u5728\u5c31\u53ef\u4ee5\u5728 B \u670d\u52a1\u5668\u4e0a\u6267\u884c\u540c\u6b65\u64cd\u4f5c\u4e86<\/p>\n<h2 id=\"\u914d\u7f6e\u8bf4\u660e\">\u914d\u7f6e\u8bf4\u660e<\/h2>\n<p>uid = root #\u8bbe\u7f6e\u6267\u884crsync\u7684\u672c\u5730\u7528\u6237\ngid = root #\u8bbe\u7f6e\u6267\u884crsync\u7684\u672c\u5730\u7ec4\nmax connections = 4 #\u6700\u5927\u540c\u65f6\u8fde\u63a5\u6570\npid file = \/var\/run\/rsyncd.pid #\u6307\u5b9arsync\u670d\u52a1\u8fdb\u7a0b\u7684pid file\nlock file = \/var\/run\/rsync.lock #\u6307\u5b9arsync\u670d\u52a1\u7aef\u9501\u5b9a\u6587\u4ef6log file = \/var\/log\/rsyncd.log #\u6307\u5b9arsync\u7684log\u8f93\u51fa\u8def\u5f84<\/p>\n<p>[logs] #\u6a21\u5757\u8bbe\u5b9a\uff0c\u53ef\u8bbe\u7f6e\u591a\u4e2a\u6a21\u5757\npath = \/data\/logs #\u540c\u6b65\u6587\u4ef6\u7684\u771f\u5b9e\u8def\u5f84\nignore errors\nread only = true #\u662f\u5426\u53ea\u8bfb\nlist = true\nauth users = backup #\u8eab\u4efd\u9a8c\u8bc1\u7528\u6237\u3002\u8fd9\u4e0d\u662f\u7cfb\u7edf\u7528\u6237\uff0c\u800c\u662frsync\u670d\u52a1\u81ea\u5b9a\u7684\nsecrets file = \/etc\/rsyncd.pwd #\u5f53\u524d\u6a21\u5757\u7684\u5bc6\u7801\u6587\u4ef6<\/p>\n<h2 id=\"\u5f00\u59cb\u540c\u6b65\">\u5f00\u59cb\u540c\u6b65<\/h2>\n<p>\u767b\u5f55 B \u670d\u52a1\u5668\uff0c\u6267\u884c<\/p>\n<pre><code>rsync -avzP --password-file=\/etc\/rsyncd.pwd backup@&lt;span class=&quot;number&quot;&gt;192.168&lt;\/span&gt;\n&lt;span class=&quot;number&quot;&gt;.1&lt;\/span&gt;\n&lt;span class=&quot;number&quot;&gt;.1&lt;\/span&gt;::logs  \/home\/logs\n<\/code><\/pre>\n<p>so easy\uff01<\/p>\n<h2 id=\"\u6ce8\u610f\">\u6ce8\u610f<\/h2>\n<p>1.\u5982\u679c \/home\/\u4e0b logs \u76ee\u5f55\u4e0d\u5b58\u5728\u5c06\u4f1a\u521b\u5efa\uff0c\u5982\u679c\u5df2\u7ecf\u5b58\u5728\u4e86\uff0c \u4f1a\u5c06 A \u673a\u5668\u4e0a\u7684 \/data\/logs \u76ee\u5f55\u4e0b\u7684\u5185\u5bb9\u540c\u6b65\u5230 B \u673a\u5668\u4e0a\u7684 \/home\/logs\/ \u4e0b\n2.\u5047\u5982 A \u673a\u5668\u4e0a\u6709\u4e00\u4e2a\u6587\u4ef6 \/home\/logs\/1.txt , \u5728\u7b2c\u4e8c\u6b21\u6267\u884c\u540c\u6b65\u65f6\u6ca1\u6709\u4fee\u6539\uff0c\u5219\u4e0d\u4f1a\u540c\u6b65\n3.\u5047\u5982 B \u673a\u5668\u4e0a\u6709\u4e00\u4e2a\u6587\u4ef6 \/home\/logs\/2.txt , A \u4e0a\u6ca1\u6709\uff0c\u540c\u6b65\u65f6\u4e0d\u4f1a\u88ab\u5220\u9664\n4.\u5982\u679c B \u673a\u5668\u4e0a\u6709\u4e00\u4e2a\u6587\u4ef6 \/home\/logs\/1.txt \u88ab\u4fee\u6539\u4e86\uff0c\u540c\u6b65\u65f6\u4f1a\u88ab A \u4e0a\u5bf9\u5e94\u7684\u6587\u4ef6\u8986\u76d6<\/p>\n<h2 id=\"\u6269\u5c55\">\u6269\u5c55<\/h2>\n<p>\u5982\u679c\u8981\u540c\u6b65\u522b\u7684\u76ee\u5f55\uff0c\u53ea\u9700\u8981\u4fee\u6539 A \u670d\u52a1\u5668\u4e0a\u7684 <code>\/etc\/rsyncd.conf<\/code> \u5c06 logs \u90e8\u5206\u4fee\u6539\u6216\u8005\u590d\u5236\u4e00\u4efd\uff0c\u6539\u6210\u4f60\u60f3\u540c\u6b65\u7684\u76ee\u5f55\u5c31\u53ef\u4ee5\u4e86\uff0c<\/p>\n<h2 id=\"One_more_thing\">One more thing<\/h2>\n<p>\u4e0b\u9762\u662f rsync \u7684\u8bed\u6cd5\u8bf4\u660e\uff1a\nrsync [-avrlptgoD] [-e ssh] [user@host:\/dir] [\/local\/path]\n-v \uff1a\u89c2\u5bdf\u6a21\u5f0f\uff0c\u53ef\u4ee5\u5217\u51fa\u66f4\u591a\u7684\u4fe1\u606f\uff1b\n-q \uff1a\u4e0e -v \u76f8\u53cd\uff0c\u5b89\u9759\u6a21\u5f0f\uff0c\u8f93\u51fa\u7684\u4fe1\u606f\u6bd4\u8f83\u5c11\uff1b\n-r \uff1a\u9012\u5f52\u590d\u5236\uff01\u53ef\u4ee5\u9488\u5bf9\u300e\u76ee\u5f55\u300f\u6765\u5904\u7406\uff01\u5f88\u91cd\u8981\uff01\n-u \uff1a\u4ec5\u66f4\u65b0 (update)\uff0c\u4e0d\u4f1a\u8986\u76d6\u76ee\u6807\u7684\u65b0\u6863\u6848\uff1b\n-l \uff1a\u590d\u5236\u8fde\u7ed3\u6587\u4ef6\u7684\u5c5e\u6027\uff0c\u800c\u975e\u8fde\u7ed3\u7684\u76ee\u6807\u6e90\u6587\u4ef6\u5185\u5bb9\uff1b\n-p \uff1a\u590d\u5236\u65f6\uff0c\u8fde\u540c\u5c5e\u6027 (permission) \u4e5f\u4fdd\u5b58\u4e0d\u53d8\uff01\n-g \uff1a\u4fdd\u5b58\u6e90\u6587\u4ef6\u7684\u62e5\u6709\u7fa4\u7ec4\uff1b\n-o \uff1a\u4fdd\u5b58\u6e90\u6587\u4ef6\u7684\u62e5\u6709\u4eba\uff1b\n-D \uff1a\u4fdd\u5b58\u6e90\u6587\u4ef6\u7684\u88c5\u7f6e\u5c5e\u6027 (device)\n-t \uff1a\u4fdd\u5b58\u6e90\u6587\u4ef6\u7684\u65f6\u95f4\u53c2\u6570\uff1b\n-I \uff1a\u5ffd\u7565\u66f4\u65b0\u65f6\u95f4 (mtime) \u7684\u5c5e\u6027\uff0c\u6863\u6848\u6bd4\u5bf9\u4e0a\u4f1a\u6bd4\u8f83\u5feb\u901f\uff1b\n-z \uff1a\u52a0\u4e0a\u538b\u7f29\u7684\u53c2\u6570\uff01\n-e \uff1a\u4f7f\u7528\u7684\u4fe1\u9053\u534f\u8bae\uff0c\u4f8b\u5982\u4f7f\u7528 ssh \u901a\u9053\uff0c\u5219 -e ssh\n-a \uff1a\u76f8\u5f53\u4e8e -rlptgoD \uff0c\u6240\u4ee5\u8fd9\u4e2a -a \u662f\u6700\u5e38\u7528\u7684\u53c2\u6570\u4e86\uff01<\/p>","protected":false},"excerpt":{"rendered":"<p>rsync \u4ecb\u7ecd rsync\u662f\u7c7bunix\u7cfb\u7edf\u4e0b\u7684\u6570\u636e\u955c\u50cf\u5907\u4efd\u5de5\u5177\u2014\u2014remote sync\u3002 rsync\u662f\u4e00\u4e2a\u529f\u80fd\u975e\u5e38\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u5176\u547d\u4ee4\u4e5f\u6709\u5f88\u591a\u529f\u80fd\u7279\u8272\u9009\u9879\uff0c\u6211\u4eec\u4e0b\u9762\u5c31\u5bf9\u5b83\u7684\u9009\u9879\u4e00\u4e00\u8fdb\u884c\u5206\u6790\u8bf4\u660e\u3002 \u5b83&#46;&#46;&#46;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[440,449],"class_list":["post-1491","post","type-post","status-publish","format-standard","hentry","category-linux","tag-linux","tag-rsync"],"_links":{"self":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1491","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/comments?post=1491"}],"version-history":[{"count":1,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1491\/revisions"}],"predecessor-version":[{"id":1494,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1491\/revisions\/1494"}],"wp:attachment":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/media?parent=1491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/categories?post=1491"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/tags?post=1491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}