web-dev-qa-db-ja.com

ディレクトリパスを保持したローカルマシンへの複数のリモートディレクトリのrsync

Rsyncを次のように使用できますか?

rsync -e ssh [email protected]:/path/to/file:/path/to/second/file/ /local/directory/

または私は何か他のことをしなければなりませんか?

40
Pred

rsync manページから直接:

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}

これは、2番目のパスの前にスペースを追加する必要があることを意味します。

rsync -e ssh [email protected]:/path/to/file :/path/to/second/file/ /local/directory/

最初に-nまたは--dry-runオプションで試してみることをお勧めします。コピー(および削除の可能性)が実際に実行される前に、何が行われるかを確認できます。

52
Tonin

@toninの実際の例です。ライブサーバーから特定のディレクトリをダウンロードする

rsync -av [email protected]:/var/www/html/cls  \
:/var/www/html/index.php \
:/var/www/html/header.inc \
:/var/www/html/version.inc.php \
:/var/www/html/style.css \
:/var/www/html/accounts \
:/var/www/html/admin \
:/var/www/html/api \
:/var/www/html/config \
:/var/www/html/main \
:/var/www/html/reports .
4
zzapper