{"id":177348,"date":"2020-05-01T10:44:07","date_gmt":"2020-05-01T02:44:07","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=177348"},"modified":"2020-04-20T09:47:39","modified_gmt":"2020-04-20T01:47:39","slug":"rsync-scp","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/rsync-scp.html","title":{"rendered":"rsync\u5b9e\u65f6\u540c\u6b65"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n \u4e0e\u4f20\u7edf\u7684cp\u3001tar\u5907\u4efd\u65b9\u5f0f\u76f8\u6bd4\uff0crsync\u5177\u6709\u5b89\u5168\u6027\u9ad8\u3001\u5907\u4efd\u8fc5\u901f\u3001\u652f\u6301\u589e\u91cf\u5907\u4efd\u7b49\u4f18\u70b9\uff0c\u901a\u8fc7rsync\u53ef\u4ee5\u89e3\u51b3\u5bf9\u5b9e\u65f6\u6027\u8981\u6c42\u4e0d\u9ad8\u7684\u6570\u636e\u5907\u4efd\u9700\u6c42\uff0c\u4f8b\u5982\u5b9a\u671f\u7684\u5907\u4efd\u6587\u4ef6\u670d\u52a1\u5668\u6570\u636e\u5230\u8fdc\u7aef\u670d\u52a1\u5668\uff0c\u5bf9\u672c\u5730\u78c1\u76d8\u5b9a\u671f\u505a\u6570\u636e\u955c\u50cf\u7b49\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"
\n192.168.0.1 \u6e90\u670d\u52a1\u5668 \u6709\u76ee\u5f55 \/opt\/test\/<\/p>\n

192.168.0.2 \u76ee\u6807\u670d\u52a1\u5668 \u6709\u76ee\u5f55 \/opt\/bak\/test\/<\/p>\n

\u5b9e\u73b0\u7684\u76ee\u7684\u5c31\u662f\u4fdd\u6301\u8fd9\u4e24\u4e2a\u670d\u52a1\u5668\u67d0\u4e2a\u6587\u4ef6\u76ee\u5f55\u4fdd\u6301\u5b9e\u65f6\u540c\u6b65<\/p>\n

\u5b9e\u73b0\u65b9\u5f0f\uff1a \u901a\u8fc7rsync+inotify-tools\u7ed3\u5408\u6765\u5b9e\u73b0<\/p>\n

\u51c6\u5907\u5de5\u4f5c\uff1a<\/strong><\/div>\n

\u9996\u5148\u8981\u7ed9\u4e24\u53f0\u673a\u5668\u6dfb\u52a0\u4fe1\u4efb\u5173\u7cfb\uff0c\u5177\u4f53\u65b9\u6cd5\u5df2\u7ecf\u5728\u524d\u9762\u7684\u6587\u7ae0\u4ecb\u7ecd\u8fc7\u4e86<\/p>\n

\u8be6\u60c5\u67e5\u770b\uff1a linux\u6dfb\u52a0\u4fe1\u4efb\u5173\u7cfb\u514d\u5bc6\u7801\u767b\u5f55<\/p>\n

\u9700\u8981\u5b89\u88c5\u8f6f\u4ef6\uff1a<\/p>\n

1. rsync \u540c\u6b65\u8f6f\u4ef6<\/strong><\/div>\n

\u5728 \u6e90\u670d\u52a1\u5668 \u548c \u76ee\u6807\u670d\u52a1\u5668 \u90fd\u9700\u8981\u5b89\u88c5<\/p>\n

\u6e90\u670d\u52a1\u5668\uff1a \u662frsync\u5ba2\u6237\u7aef\uff0c\u4e0d\u9700\u8981\u914d\u7f6e<\/p>\n

\u76ee\u6807\u670d\u52a1\u5668\uff1a \u662frsync\u670d\u52a1\u5668\u7aef\uff0c\u9700\u8981\u914d\u7f6e\/etc\/rsyncd.conf\u91cc\u7684\u5185\u5bb9<\/p>\n

2. inotify-tools \u5de5\u5177<\/strong><\/div>\n

\u8be5\u5de5\u5177\u4e3a\u6587\u4ef6\u5b9e\u65f6\u76d1\u63a7\u5de5\u5177\uff0c\u9700\u8981linux\u64cd\u4f5c\u7cfb\u7edf\u5185\u6838\u652f\u6301\uff0c\u5185\u6838\u652f\u6301\u9700\u8981\u81f3\u5c11\u7248\u672c\u4e3a2.6.13<\/p>\n

\u68c0\u67e5\u64cd\u4f5c\u7cfb\u7edf\u662f\u5426\u652f\u6301\uff0c\u6267\u884c\u5982\u4e0b\uff1a<\/p>\n

uname -r \u67e5\u770b\u7248\u672c
\n \u8fd4\u56de\uff1a
\n2.6.32-358.6.1.el6.x86_64
\n \u5219\u8868\u793a\u7248\u672c2.6.32 \u5927\u4e8e2.6.13\uff0c\u5219\u652f\u6301\u3002<\/p>\n

\u6267\u884c\uff1a<\/p>\n

\r\n    ll \/proc\/sys\/fs\/inotify\r\n    total 0 \r\n    -rw-r--r-- 1 root root 0 Oct 18 12:18 max_queued_events \r\n    -rw-r--r-- 1 root root 0 Oct 18 12:18 max_user_instances \r\n    -rw-r--r-- 1 root root 0 Oct 18 12:18 max_user_watches<\/pre>\n

\u6709\u4e09\u9879\u8f93\u51fa,\u5219\u8868\u793a\u9ed8\u8ba4\u652f\u6301inotify,\u53ef\u4ee5\u5b89\u88c5inotify-tools\u5de5\u5177.<\/p>\n

\u5982\u679c\u4e0d\u652f\u6301\uff0c\u9700\u8981\u91c7\u7528\u65b0\u7248\u672c\u7684linux\u64cd\u4f5c\u7cfb\u7edf<\/p>\n

\u7248\u672c\u8fbe\u5230\u8981\u6c42\uff0c\u5c31\u53ef\u4ee5\u5b89\u88c5\u4e86\u3002<\/p>\n

\u5b89\u88c5inotify-tools\u540e\u4f1a\u5728\u76f8\u5173\u5b89\u88c5\u76ee\u5f55\u4e0b\u751f\u6210\u5982\u4e0b\u4e24\u4e2a\u6587\u4ef6\uff1a<\/p>\n

ll \/usr\/local\/bin\/\r\n    total 88 \r\n    -rwxr-xr-x 1 root root 44327 Oct 10 15:32 inotifywait \r\n    -rwxr-xr-x 1 root root 41417 Oct 10 15:32 inotifywatch<\/pre>\n

\u5219\u8868\u793a\u5b89\u88c5\u6210\u529f\u3002<\/p>\n

\u6ce8\u610f\uff1a \u5728 \u6e90\u670d\u52a1\u5668\u4e0a\u9700\u8981\u5b89\u88c5\uff0c\u76ee\u6807\u670d\u52a1\u5668\u4e0a\u4e0d\u9700\u8981\u5b89\u88c5inotify\u3002<\/p>\n

3. \u76f8\u5173\u811a\u672c\uff1a<\/strong><\/div>\n

\u5728\u6e90\u670d\u52a1\u5668\u4e0a\u65b0\u5efa\u811a\u672c\uff1a<\/p>\n

inotify_bak.sh<\/p>\n

\r\n    #!\/bin\/bash \r\n    src=\/opt\/test\/\r\n    \/usr\/local\/bin\/inotifywait -mrq --timefmt '%d\/%m\/%y %H:%M' --format '%T %w%f%e' -e close_write,delete,create,attrib $src |  while read file\r\n    do\r\n          \/usr\/bin\/rsync -arzuq $src 192.168.0.1::www\/ \r\n          echo \"  ${file} was rsynced\" >>\/opt\/soft\/log\/rsync.log 2>&1 \r\n    done<\/pre>\n

\u8d4b\u4e88\u6267\u884c\u6743\u9650\uff1a chmod +x inotify_bak.sh<\/p>\n

\u7136\u540e\u6267\u884c\uff1anohup inotify_bak.sh & \u653e\u5165\u540e\u53f0\u6267\u884c<\/p>\n

4. \u5173\u4e8e\u542f\u52a8<\/strong><\/div>\n

\u76ee\u6807\u670d\u52a1\u5668\uff1a\u5148\u542f\u52a8rsync\u540e\u53f0\u670d\u52a1\uff1a \/usr\/bin\/rsync --daemon<\/p>\n

\u6765\u6e90\u670d\u52a1\u5668\uff1a \u6267\u884c inotify_bak.sh & <\/p>\n

5. \u6d4b\u8bd5\uff1a<\/strong><\/div>\n

\u5728\u6765\u6e90\u670d\u52a1\u5668\u76ee\u5f55\u4e2d\u65b0\u5efa\u76ee\u5f55\u548c\u6587\u4ef6\uff0cinotify_bak.sh\u811a\u672c\u4f1a\u68c0\u6d4b\u5230\uff0c\u7136\u540e\u540c\u6b65\u5230\u76ee\u6807\u670d\u52a1\u5668\u7684\u76f8\u5173\u76ee\u5f55\u4e0b<\/p>\n

\u53ef\u4ee5\u67e5\u770b\u65e5\u5fd7\u6587\u4ef6\uff1a \/opt\/soft\/log\/rsync.log \u547d\u4ee4\u5982\u4e0b\uff1a\u89c2\u5bdf\u5b9e\u65f6\u540c\u6b65\u7684\u60c5\u51b5\u3002<\/p>\n

\r\n    tail -f  \/opt\/soft\/log\/rsync.log\r\n\u9519\u8bef\u89e3\u51b3\uff1a\r\n\r\n\/usr\/local\/bin\/inotifywait: error while loading shared libraries: libinotifytools.so.0: cannot open shared object file: No such file or directory\r\n<\/pre>\n

\u8fd9\u662f\u56e0\u4e3a\u627e\u4e0d\u5230\u5e93\u6587\u4ef6\u7684\u539f\u56e0\uff0c\u505a\u4e00\u4e2a\u8f6f\u8fde\u63a5\u5c31\u597d\u4e86<\/p>\n

\r\nln -s \/usr\/local\/lib\/libinotifytools.so.0 \/usr\/lib64\/libinotifytools.so.0<\/pre>\n","protected":false},"excerpt":{"rendered":"

192.168.0.1 \u6e90\u670d\u52a1\u5668 \u6709\u76ee\u5f55 \/opt\/test\/ 192.168.0.2 \u76ee\u6807\u670d\u52a1\u5668 \u6709\u76ee\u5f55 \/ […]<\/p>\n","protected":false},"author":1469,"featured_media":177354,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-177348","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/177348","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1469"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=177348"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/177348\/revisions"}],"predecessor-version":[{"id":177355,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/177348\/revisions\/177355"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/177354"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=177348"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=177348"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=177348"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}