{"id":140639,"date":"2019-03-27T10:25:43","date_gmt":"2019-03-27T02:25:43","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=140639"},"modified":"2019-03-25T09:27:07","modified_gmt":"2019-03-25T01:27:07","slug":"linux-copy-servers","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-copy-servers.html","title":{"rendered":"Linux :\u590d\u5236\u6587\u4ef6\/\u6587\u4ef6\u5939\u5230\u8fdc\u7a0b\u670d\u52a1\u5668"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u4ece\u4e00\u4e2a\u670d\u52a1\u5668\u590d\u5236\u6587\u4ef6\u5230\u53e6\u4e00\u4e2a\u670d\u52a1\u5668\uff0c\u6216\u8005\u4ece\u672c\u5730\u5230\u8fdc\u7a0b\u590d\u5236\u662f Linux \u7ba1\u7406\u5458\u7684\u65e5\u5e38\u4efb\u52a1\u4e4b\u4e00\u3002<\/p>\n

\u6211\u89c9\u5f97\u4e0d\u4f1a\u6709\u4eba\u4e0d\u540c\u610f\uff0c\u56e0\u4e3a\u65e0\u8bba\u5728\u54ea\u91cc\u8fd9\u90fd\u662f\u4f60\u7684\u65e5\u5e38\u64cd\u4f5c\u4e4b\u4e00\u3002\u6709\u5f88\u591a\u529e\u6cd5\u90fd\u80fd\u5904\u7406\u8fd9\u4e2a\u4efb\u52a1\uff0c\u6211\u4eec\u8bd5\u7740\u52a0\u4ee5\u6982\u62ec\u3002\u4f60\u53ef\u4ee5\u6311\u4e00\u4e2a\u559c\u6b22\u7684\u65b9\u6cd5\u3002\u5f53\u7136\uff0c\u770b\u770b\u5176\u4ed6\u547d\u4ee4\u4e5f\u80fd\u5728\u522b\u7684\u5730\u65b9\u5e2e\u5230\u4f60\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"
\n\u6211\u5df2\u7ecf\u5728\u81ea\u5df1\u7684\u73af\u5883\u4e0b\u6d4b\u8bd5\u8fc7\u6240\u6709\u7684\u547d\u4ee4\u548c\u811a\u672c\u4e86\uff0c\u56e0\u6b64\u4f60\u53ef\u4ee5\u76f4\u63a5\u7528\u5230\u65e5\u5e38\u5de5\u4f5c\u5f53\u4e2d\u3002<\/p>\n

\u901a\u5e38\u5927\u5bb6\u90fd\u503e\u5411 scp\uff0c\u56e0\u4e3a\u5b83\u662f\u6587\u4ef6\u590d\u5236\u7684\u539f\u751f\u547d\u4ee4native command\u4e4b\u4e00\u3002\u4f46\u672c\u6587\u6240\u5217\u51fa\u7684\u5176\u5b83\u547d\u4ee4\u4e5f\u5f88\u597d\u7528\uff0c\u5efa\u8bae\u4f60\u5c1d\u8bd5\u4e00\u4e0b\u3002<\/p>\n

\u6587\u4ef6\u590d\u5236\u53ef\u4ee5\u8f7b\u6613\u5730\u7528\u4ee5\u4e0b\u56db\u79cd\u65b9\u6cd5\u3002<\/p>\n

scp\uff1a\u5728\u7f51\u7edc\u4e0a\u7684\u4e24\u4e2a\u4e3b\u673a\u4e4b\u95f4\u590d\u5236\u6587\u4ef6\uff0c\u5b83\u4f7f\u7528 ssh \u505a\u6587\u4ef6\u4f20\u8f93\uff0c\u5e76\u4f7f\u7528\u76f8\u540c\u7684\u8ba4\u8bc1\u65b9\u5f0f\uff0c\u5177\u6709\u76f8\u540c\u7684\u5b89\u5168\u6027\u3002
\nrsync\uff1a\u662f\u4e00\u4e2a\u65e2\u5feb\u901f\u53c8\u51fa\u4f17\u7684\u591a\u529f\u80fd\u6587\u4ef6\u590d\u5236\u5de5\u5177\u3002\u5b83\u80fd\u672c\u5730\u590d\u5236\u3001\u901a\u8fc7\u8fdc\u7a0b shell \u5728\u5176\u5b83\u4e3b\u673a\u4e4b\u95f4\u590d\u5236\uff0c\u6216\u8005\u4e0e\u8fdc\u7a0b\u7684 rsync \u5b88\u62a4\u8fdb\u7a0bdaemon \u4e4b\u95f4\u590d\u5236\u3002
\npscp\uff1a\u662f\u4e00\u4e2a\u5e76\u884c\u590d\u5236\u6587\u4ef6\u5230\u591a\u4e2a\u4e3b\u673a\u4e0a\u7684\u7a0b\u5e8f\u3002\u5b83\u63d0\u4f9b\u4e86\u8bf8\u591a\u7279\u6027\uff0c\u4f8b\u5982\u4e3a scp \u914d\u7f6e\u514d\u5bc6\u4f20\u8f93\uff0c\u4fdd\u5b58\u8f93\u51fa\u5230\u6587\u4ef6\uff0c\u4ee5\u53ca\u8d85\u65f6\u63a7\u5236\u3002
\nprsync\uff1a\u4e5f\u662f\u4e00\u4e2a\u5e76\u884c\u590d\u5236\u6587\u4ef6\u5230\u591a\u4e2a\u4e3b\u673a\u4e0a\u7684\u7a0b\u5e8f\u3002\u5b83\u4e5f\u63d0\u4f9b\u4e86\u8bf8\u591a\u7279\u6027\uff0c\u4f8b\u5982\u4e3a ssh \u914d\u7f6e\u514d\u5bc6\u4f20\u8f93\uff0c\u4fdd\u5b58\u8f93\u51fa\u5230 \u6587\u4ef6\uff0c\u4ee5\u53ca\u8d85\u65f6\u63a7\u5236\u3002<\/p>\n

\u65b9\u5f0f 1\uff1a\u5982\u4f55\u5728 Linux \u4e0a\u4f7f\u7528 scp \u547d\u4ee4\u4ece\u672c\u5730\u7cfb\u7edf\u5411\u8fdc\u7a0b\u7cfb\u7edf\u590d\u5236\u6587\u4ef6\/\u6587\u4ef6\u5939\uff1f<\/strong><\/div>\n

scp<\/code> \u547d\u4ee4\u53ef\u4ee5\u8ba9\u6211\u4eec\u4ece\u672c\u5730\u7cfb\u7edf\u590d\u5236\u6587\u4ef6\/\u6587\u4ef6\u5939\u5230\u8fdc\u7a0b\u7cfb\u7edf\u4e0a\u3002<\/p>\n

\u6211\u4f1a\u628a output.txt \u6587\u4ef6\u4ece\u672c\u5730\u7cfb\u7edf\u590d\u5236\u5230 2g.CentOS.com \u8fdc\u7a0b\u7cfb\u7edf\u7684 \/opt\/backup \u6587\u4ef6\u5939\u4e0b\u3002<\/p>\n

# scp output.txt root@2g.CentOS.com:\/opt\/backup\r\n\r\noutput.txt                                                                                              100% 2468    2.4KB\/s  00:00<\/pre>\n
\u4ece\u672c\u5730\u7cfb\u7edf\u590d\u5236\u4e24\u4e2a\u6587\u4ef6 output.txt \u548c passwd-up.sh \u5230\u8fdc\u7a0b\u7cfb\u7edf 2g.CentOs.com \u7684 \/opt\/backup \u6587\u4ef6\u5939\u4e0b\u3002<\/strong><\/span><\/div>\n
# scp output.txt passwd-up.sh root@2g.CentOS.com:\/opt\/backup\r\n\r\noutput.txt 100% 2468 2.4KB\/s 00:00\r\npasswd-up.sh 100% 877 0.9KB\/s 00:00<\/pre>\n
\u4ece\u672c\u5730\u7cfb\u7edf\u590d\u5236 shell-script \u6587\u4ef6\u5939\u5230\u8fdc\u7a0b\u7cfb\u7edf 2g.CentOs.com \u7684 \/opt\/back \u6587\u4ef6\u5939\u4e0b\u3002<\/strong><\/span><\/div>\n

\u8fd9\u4f1a\u8fde\u540cshell-script \u6587\u4ef6\u5939\u4e0b\u6240\u6709\u7684\u6587\u4ef6\u4e00\u540c\u590d\u5236\u5230\/opt\/back \u4e0b\u3002<\/p>\n

# scp -r \/home\/daygeek\/2g\/shell-script\/ root@:\/opt\/backup\/\r\n\r\noutput.txt 100% 2468 2.4KB\/s 00:00\r\novh.sh      100% 76 0.1KB\/s 00:00\r\npasswd-up.sh 100% 877 0.9KB\/s 00:00\r\npasswd-up1.sh 100% 7 0.0KB\/s 00:00\r\nserver-list.txt 100% 23 0.0KB\/s 00:00<\/pre>\n
\u65b9\u5f0f 2\uff1a\u5982\u4f55\u5728 Linux \u4e0a\u4f7f\u7528 scp \u547d\u4ee4\u548c Shell \u811a\u672c\u590d\u5236\u6587\u4ef6\/\u6587\u4ef6\u5939\u5230\u591a\u4e2a\u8fdc\u7a0b\u7cfb\u7edf\u4e0a\uff1f<\/strong><\/div>\n

\u5982\u679c\u4f60\u60f3\u590d\u5236\u540c\u4e00\u4e2a\u6587\u4ef6\u5230\u591a\u4e2a\u8fdc\u7a0b\u670d\u52a1\u5668\u4e0a\uff0c\u90a3\u5c31\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u5982\u4e0b\u9762\u90a3\u6837\u7684\u5c0f shell \u811a\u672c\u3002<\/p>\n

\u5e76\u4e14\uff0c\u9700\u8981\u5c06\u670d\u52a1\u5668\u6dfb\u52a0\u8fdb server-list.txt \u6587\u4ef6\u3002\u786e\u4fdd\u6dfb\u52a0\u6210\u529f\u540e\uff0c\u6bcf\u4e2a\u670d\u52a1\u5668\u5e94\u5f53\u5355\u72ec\u4e00\u884c\u3002<\/p>\n

\u6700\u7ec8\uff0c\u4f60\u60f3\u8981\u7684\u811a\u672c\u5c31\u50cf\u4e0b\u9762\u8fd9\u6837\uff1a<\/strong><\/span><\/div>\n
# file-copy.sh\r\n\r\n#!\/bin\/sh\r\nfor server in `more server-list.txt`\r\ndo\r\n  scp \/home\/daygeek\/2g\/shell-script\/output.txt root@$server:\/opt\/backup\r\ndone<\/pre>\n
\u5b8c\u6210\u4e4b\u540e\uff0c\u7ed9 file-copy.sh \u6587\u4ef6\u8bbe\u7f6e\u53ef\u6267\u884c\u6743\u9650\u3002<\/strong><\/span><\/div>\n
# chmod +x file-copy.sh<\/pre>\n
\u6700\u540e\u8fd0\u884c\u811a\u672c\u5b8c\u6210\u590d\u5236\u3002<\/strong><\/span><\/div>\n
# .\/file-copy.sh\r\n\r\noutput.txt 100% 2468 2.4KB\/s 00:00\r\noutput.txt 100% 2468 2.4KB\/s 00:00<\/pre>\n
\u4f7f\u7528\u4e0b\u9762\u7684\u811a\u672c\u53ef\u4ee5\u590d\u5236\u591a\u4e2a\u6587\u4ef6\u5230\u591a\u4e2a\u8fdc\u7a0b\u670d\u52a1\u5668\u4e0a\u3002<\/strong><\/span><\/div>\n
# file-copy.sh\r\n\r\n#!\/bin\/sh\r\nfor server in `more server-list.txt`\r\ndo\r\n  scp \/home\/daygeek\/2g\/shell-script\/output.txt passwd-up.sh root@$server:\/opt\/backup\r\ndone<\/pre>\n
\u4e0b\u9762\u7ed3\u679c\u663e\u793a\u6240\u6709\u7684\u4e24\u4e2a\u6587\u4ef6\u90fd\u590d\u5236\u5230\u4e24\u4e2a\u670d\u52a1\u5668\u4e0a\u3002<\/strong><\/span><\/div>\n
# .\/file-cp.sh\r\n\r\noutput.txt 100% 2468 2.4KB\/s 00:00\r\npasswd-up.sh 100% 877 0.9KB\/s 00:00\r\noutput.txt 100% 2468 2.4KB\/s 00:00\r\npasswd-up.sh 100% 877 0.9KB\/s 00:00<\/pre>\n
\u4f7f\u7528\u4e0b\u9762\u7684\u811a\u672c\u9012\u5f52\u5730\u590d\u5236\u6587\u4ef6\u5939\u5230\u591a\u4e2a\u8fdc\u7a0b\u670d\u52a1\u5668\u4e0a\u3002<\/strong><\/span><\/div>\n
# file-copy.sh\r\n\r\n#!\/bin\/sh\r\nfor server in `more server-list.txt`\r\ndo\r\n  scp -r \/home\/daygeek\/2g\/shell-script\/ root@$server:\/opt\/backup\r\ndone<\/pre>\n
\u4e0a\u8ff0\u811a\u672c\u7684\u8f93\u51fa\u3002<\/strong><\/span><\/div>\n
# .\/file-cp.sh\r\n\r\noutput.txt 100% 2468 2.4KB\/s 00:00\r\novh.sh      100% 76 0.1KB\/s 00:00\r\npasswd-up.sh 100% 877 0.9KB\/s 00:00\r\npasswd-up1.sh 100% 7 0.0KB\/s 00:00\r\nserver-list.txt 100% 23 0.0KB\/s 00:00\r\n\r\noutput.txt 100% 2468 2.4KB\/s 00:00\r\novh.sh      100% 76 0.1KB\/s 00:00\r\npasswd-up.sh 100% 877 0.9KB\/s 00:00\r\npasswd-up1.sh 100% 7 0.0KB\/s 00:00\r\nserver-list.txt 100% 23 0.0KB\/s 00:00<\/pre>\n
\u65b9\u5f0f 3\uff1a\u5982\u4f55\u5728 Linux \u4e0a\u4f7f\u7528 pscp \u547d\u4ee4\u590d\u5236\u6587\u4ef6\/\u6587\u4ef6\u5939\u5230\u591a\u4e2a\u8fdc\u7a0b\u7cfb\u7edf\u4e0a\uff1f<\/strong><\/div>\n

pscp<\/code>\u547d\u4ee4\u53ef\u4ee5\u76f4\u63a5\u8ba9\u6211\u4eec\u590d\u5236\u6587\u4ef6\u5230\u591a\u4e2a\u8fdc\u7a0b\u670d\u52a1\u5668\u4e0a\u3002<\/p>\n

\u4f7f\u7528\u4e0b\u9762\u7684 pscp \u547d\u4ee4\u590d\u5236\u5355\u4e2a\u6587\u4ef6\u5230\u8fdc\u7a0b\u670d\u52a1\u5668\u3002<\/strong><\/span><\/div>\n
# pscp.pssh -H 2g.CentOS.com \/home\/daygeek\/2g\/shell-script\/output.txt \/opt\/backup\r\n\r\n[1] 18:46:11 [SUCCESS] 2g.CentOS.com<\/pre>\n
\u4f7f\u7528\u4e0b\u9762\u7684 pscp \u547d\u4ee4\u590d\u5236\u591a\u4e2a\u6587\u4ef6\u5230\u8fdc\u7a0b\u670d\u52a1\u5668\u3002<\/strong><\/span><\/div>\n
# pscp.pssh -H 2g.CentOS.com \/home\/daygeek\/2g\/shell-script\/output.txt ovh.sh \/opt\/backup\r\n\r\n[1] 18:47:48 [SUCCESS] 2g.CentOS.com<\/pre>\n
\u4f7f\u7528\u4e0b\u9762\u7684 pscp \u547d\u4ee4\u9012\u5f52\u5730\u590d\u5236\u6574\u4e2a\u6587\u4ef6\u5939\u5230\u8fdc\u7a0b\u670d\u52a1\u5668\u3002<\/strong><\/span><\/div>\n
# pscp.pssh -H 2g.CentOS.com -r \/home\/daygeek\/2g\/shell-script\/ \/opt\/backup\r\n\r\n[1] 18:48:46 [SUCCESS] 2g.CentOS.com<\/pre>\n
\u4f7f\u7528\u4e0b\u9762\u7684 pscp \u547d\u4ee4\u4f7f\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u590d\u5236\u5355\u4e2a\u6587\u4ef6\u5230\u591a\u4e2a\u8fdc\u7a0b\u670d\u52a1\u5668\u3002<\/strong><\/span><\/div>\n
# pscp.pssh -h server-list.txt \/home\/daygeek\/2g\/shell-script\/output.txt \/opt\/backup\r\n\r\n[1] 18:49:48 [SUCCESS] 2g.CentOS.com\r\n[2] 18:49:48 [SUCCESS] 2g.Debian.com<\/pre>\n
\u4f7f\u7528\u4e0b\u9762\u7684 pscp \u547d\u4ee4\u590d\u5236\u591a\u4e2a\u6587\u4ef6\u5230\u591a\u4e2a\u8fdc\u7a0b\u670d\u52a1\u5668\u3002<\/strong><\/span><\/div>\n
# pscp.pssh -h server-list.txt \/home\/daygeek\/2g\/shell-script\/output.txt passwd-up.sh \/opt\/backup\r\n\r\n[1] 18:50:30 [SUCCESS] 2g.Debian.com\r\n[2] 18:50:30 [SUCCESS] 2g.CentOS.com<\/pre>\n

\n\u4f7f\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u9012\u5f52\u5730\u590d\u5236\u6587\u4ef6\u5939\u5230\u591a\u4e2a\u8fdc\u7a0b\u670d\u52a1\u5668\u3002<\/strong><\/span><\/div>\n
# pscp.pssh -h server-list.txt -r \/home\/daygeek\/2g\/shell-script\/ \/opt\/backup\r\n\r\n[1] 18:51:31 [SUCCESS] 2g.Debian.com\r\n[2] 18:51:31 [SUCCESS] 2g.CentOS.com<\/pre>\n","protected":false},"excerpt":{"rendered":"

\u6211\u5df2\u7ecf\u5728\u81ea\u5df1\u7684\u73af\u5883\u4e0b\u6d4b\u8bd5\u8fc7\u6240\u6709\u7684\u547d\u4ee4\u548c\u811a\u672c\u4e86\uff0c\u56e0\u6b64\u4f60\u53ef\u4ee5\u76f4\u63a5\u7528\u5230\u65e5\u5e38\u5de5\u4f5c\u5f53\u4e2d\u3002 \u901a\u5e38\u5927\u5bb6\u90fd\u503e\u5411 scp\uff0c\u56e0\u4e3a\u5b83 […]<\/p>\n","protected":false},"author":1893,"featured_media":140642,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-140639","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\/140639","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\/1893"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=140639"}],"version-history":[{"count":1,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/140639\/revisions"}],"predecessor-version":[{"id":140649,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/140639\/revisions\/140649"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/140642"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=140639"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=140639"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=140639"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}