SSH経由でrsyncを使用してリモートから複数のファイルをコピーする


8

を使用してリモートマシンから複数のファイルをコピーしたいrsync。そこで、次のコマンドを使用します。

rsync -Pav -e 'ssh -i sshkey' user@remotemachine:/home/user/file1.zip file2.zip file3.zip  .

次のエラーが表示されます

予期しないローカルarg:file2.zip argがリモートファイル/ディレクトリの場合は、その前にコロン(:)を付けます。rsyncエラー:main.c(1362)での構文または使用法のエラー(コード1)[Receiver = 3.1.0]

回答:


10

すべてのリモートファイルは、rsyncの1つの引数である必要があります。したがって、すべてのリモートファイルを一重引用符で囲みます。

rsync -Pav -e 'ssh -i sshkey' 'user@remotemachine:/home/user/file1.zip file2.zip file3.zip' .

ところで、アスタリスクを使用してこれを行うこともできます(アスタリスクはリモートシェルによって解決されます)。

rsync -Pav -e 'ssh -i sshkey' 'user@remotemachine:/home/user/*.zip' .

1
アレキサンダー大王のためにそれは素晴らしい働きをします
スーパークリッシュ

9

これはかなり古いですが、受け入れられた答えは少し厳格です-複数のファイルがrsyncへの単一の引数であるとは限りません。からman rsync

ADVANCED USAGE
       The  syntax  for  requesting  multiple  files  from a remote host is done by specifying additional remote-host args in the same style as the first, or with the hostname omitted.  For
       instance, all these work:

              rsync -av host:file1 :file2 host:file{3,4} /dest/
              rsync -av host::modname/file{1,2} host::modname/file3 /dest/
              rsync -av host::modname/file1 ::modname/file{3,4}

OPのコマンドは

rsync -Pav -e 'ssh -i sshkey' user@remotemachine:/home/user/file1.zip :/home/user/file2.zip :/home/user/file3.zip  .

これは古いバージョンのrsyncでは不可能ですが、すべての主要なディストリビューションでは、数年前からこれがいくつかあると思います。

弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.