{"id":94083,"date":"2024-04-22T06:38:11","date_gmt":"2024-04-21T22:38:11","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=94083"},"modified":"2024-04-22T06:38:11","modified_gmt":"2024-04-21T22:38:11","slug":"scp-recursion","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/scp-recursion.html","title":{"rendered":"SCP\u4f7f\u7528\u6280\u5de7-\u9012\u5f52\u6392\u9664\u6587\u4ef6"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nQ\uff1a\u6211\u9700\u8981\u5c06\u6240\u6709\u5305\u542b *.c \u6587\u4ef6\u7684\u6587\u4ef6\u5939\u4ece\u540d\u4e3a hostA \u7684\u672c\u5730\u7b14\u8bb0\u672c\u590d\u5236\u5230 hostB\u3002\u6211\u4f7f\u7528\u7684\u662f\u4e0b\u9762\u7684 scp \u547d\u4ee4\uff0c\u4f46\u4e0d\u77e5\u9053\u5982\u4f55\u6392\u9664\u7279\u5b9a\u7684\u6587\u4ef6\uff08\u5982 *.out\uff09\uff1a$ scp -r ~\/projects\/ user@hostB:\/home\/delta\/projects\/\u3002\u5982\u4f55\u544a\u8bc9 scp \u547d\u4ee4\u5728 Linux\/Unix \u547d\u4ee4\u884c\u4e2d\u6392\u9664\u7279\u5b9a\u7684\u6587\u4ef6\u6216\u76ee\u5f55\uff1f\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u4eba\u4eec\u53ef\u4ee5\u4f7f\u7528 scp \u547d\u4ee4\u5728\u7f51\u7edc\u4e3b\u673a\u4e4b\u95f4\u5b89\u5168\u5730\u590d\u5236\u6587\u4ef6\u3002\u5b83\u4f7f\u7528 ssh \u8fdb\u884c\u6570\u636e\u4f20\u8f93\u548c\u8eab\u4efd\u9a8c\u8bc1\u3002\u5178\u578b\u7684\u8bed\u6cd5\u662f\uff1a<\/p>\n

scp file1 user@host:\/path\/to\/dest\/\r\nscp -r \/path\/to\/source\/ user@host:\/path\/to\/dest\/\r\n<\/pre>\n
scp \u6392\u9664\u6587\u4ef6<\/strong><\/div>\n

\u6211\u4e0d\u8ba4\u4e3a\u4f60\u53ef\u4ee5\u5728\u4f7f\u7528 scp \u547d\u4ee4\u65f6\u8fc7\u6ee4\u6216\u6392\u9664\u6587\u4ef6\u3002\u4f46\u662f\uff0c\u6709\u4e00\u4e2a\u5f88\u597d\u7684\u89e3\u51b3\u65b9\u6cd5\u6765\u6392\u9664\u6587\u4ef6\u5e76\u4f7f\u7528 ssh \u5b89\u5168\u5730\u590d\u5236\u5b83\u3002\u672c\u9875\u9762\u8bf4\u660e\u5982\u4f55\u5728\u4f7f\u7528 scp \u9012\u5f52\u590d\u5236\u76ee\u5f55\u65f6\u8fc7\u6ee4\u6216\u6392\u9664\u6587\u4ef6\u3002<\/p>\n

\u5982\u4f55\u4f7f\u7528 rsync \u547d\u4ee4\u6392\u9664\u6587\u4ef6<\/strong><\/div>\n

\u8bed\u6cd5\u662f\uff1a<\/p>\n

rsync av -e ssh --exclude='*.out' \/path\/to\/source\/ user@hostB:\/path\/to\/dest\/<\/pre>\n

\u8fd9\u91cc\uff1a<\/p>\n

    \n
  1. -a \uff1a\u9012\u5f52\u5230\u76ee\u5f55\uff0c\u5373\u590d\u5236\u6240\u6709\u6587\u4ef6\u548c\u5b50\u76ee\u5f55\u3002\u53e6\u5916\uff0c\u6253\u5f00\u5f52\u6863\u6a21\u5f0f\u548c\u6240\u6709\u5176\u4ed6\u9009\u9879\uff08\u76f8\u5f53\u4e8e -rlptgoD\uff09<\/li>\n
  2. -v \uff1a\u8be6\u7ec6\u8f93\u51fa<\/li>\n
  3. -e ssh \uff1a\u4f7f\u7528 ssh \u4f5c\u4e3a\u8fdc\u7a0b shell\uff0c\u8fd9\u6837\u6240\u6709\u7684\u4e1c\u897f\u90fd\u88ab\u52a0\u5bc6<\/li>\n
  4. --exclude='*.out' \uff1a\u6392\u9664\u5339\u914d\u6a21\u5f0f\u7684\u6587\u4ef6\uff0c\u4f8b\u5982 *.out \u6216 *.c \u7b49\u3002<\/li>\n<\/ol>\n
    rsync \u547d\u4ee4\u7684\u4f8b\u5b50<\/strong><\/div>\n

    \u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u4ece ~\/virt\/ \u76ee\u5f55\u9012\u5f52\u5730\u590d\u5236\u6240\u6709\u6587\u4ef6\uff0c\u4f46\u6392\u9664\u6240\u6709 *.new \u6587\u4ef6\uff1a<\/p>\n

    \t\r\n$ rsync -av -e ssh --exclude='*.new' ~\/virt\/ root@centos7:\/tmp\r\n<\/pre>\n

    \u793a\u4f8b\u8f93\u51fa\uff1a<\/p>\n

    \"\"<\/p>\n

    Scp exclude files but using rsync exclude command<\/em><\/p>\n

    \u5982\u679c\u8fdc\u7a0b\u670d\u52a1\u5668\u4e0a\u627e\u4e0d\u5230 rsync\uff0c\u90a3\u4e48 rsync \u547d\u4ee4\u5c06\u5931\u8d25\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u8bf7\u5c1d\u8bd5\u4f7f\u7528\u4ee5\u4e0b scp \u547d\u4ee4\uff0c\u8be5\u547d\u4ee4\u5728\u5f53\u524d\u76ee\u5f55\u4e2d\u4f7f\u7528 bash shell \u6a21\u5f0f\u5339\u914d \uff08\u5b83\u4e0d\u80fd\u4e0e -r \u9009\u9879\u4e00\u8d77\u4f7f\u7528\uff09\uff1a<\/p>\n

    $ ls<\/pre>\n

    \u793a\u4f8b\u8f93\u51fa\uff1a<\/p>\n

    centos71.log centos71.qcow2 centos71.qcow2.new centos71.v2.qcow2.new meta-data user-data<\/pre>\n

    \u590d\u5236\u9664 .new \u4e4b\u5916\u7684\u5f53\u524d\u76ee\u5f55\u4e2d\u7684\u6240\u6709\u5185\u5bb9\uff1a<\/p>\n

    $ shopt -s extglob\r\n$ scp !(*.new) root@centos7:\/tmp\/\r\n<\/pre>\n

    \u793a\u4f8b\u8f93\u51fa\uff1a<\/p>\n

    centos71.log 100 % 4262 1.3MB\/s 00:00\r\ncentos71.qcow2 100 % 836MB 32.7MB\/s 00: 25\r\nmeta-data 100 % 47 18.5KB\/s 00:00\r\nuser-data 100 % 1543 569.7KB\/s 00:00\r\n<\/pre>\n

    \u6709\u5173\u66f4\u591a\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605\u4ee5\u4e0b\u624b\u518c\u9875\uff1a<\/p>\n

    $ rsync -av -e ssh --exclude='*.new' ~\/virt\/ root@centos7:\/tmp<\/pre>\n
    \n

    via: https:\/\/www.cyberciti.biz\/faq\/scp-exclude-files-when-using-command-recursively-on-unix-linux\/<\/a><\/p>\n

    \u4f5c\u8005\uff1aVivek Gite<\/a> \u8bd1\u8005\uff1ageekpi<\/a> \u6821\u5bf9\uff1awxy<\/a><\/p>\n

    \u672c\u6587\u7531 LCTT<\/a> \u539f\u521b\u7f16\u8bd1\uff0cLinux\u4e2d\u56fd<\/a> \u8363\u8a89\u63a8\u51fa<\/p>\n

    \n

    \u539f\u6587\u6765\u81ea\uff1ahttps:\/\/linux.cn\/article-9292-1.html<\/a><\/p>\n

    \u672c\u6587\u5730\u5740\uff1a http:\/\/lrxjmw.cn\/scp-recursion.html<\/a>\u7f16\u8f91\uff1a\u674e\u5e05\uff0c\u5ba1\u6838\u5458\uff1a\u9004\u589e\u5b9d<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

    \u5bfc\u8bfb Q\uff1a\u6211\u9700\u8981\u5c06\u6240\u6709\u5305\u542b *.c \u6587\u4ef6\u7684\u6587\u4ef6\u5939\u4ece\u540d\u4e3a hostA \u7684\u672c\u5730\u7b14\u8bb0\u672c\u590d\u5236\u5230 hostB\u3002\u6211\u4f7f\u7528\u7684\u662f […]<\/p>\n","protected":false},"author":63,"featured_media":94091,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-94083","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\/94083","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\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=94083"}],"version-history":[{"count":6,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/94083\/revisions"}],"predecessor-version":[{"id":291043,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/94083\/revisions\/291043"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/94091"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=94083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=94083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=94083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}