rsync多个远程目录到本地机器保留目录路径

Pre*_*red 42 rsync

我可以这样使用rsync:

rsync -e ssh root@remote.com:/path/to/file:/path/to/second/file/ /local/directory/
Run Code Online (Sandbox Code Playgroud)

还是我必须做别的事?

Ton*_*nin 54

直接来自rsync手册页:

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}
Run Code Online (Sandbox Code Playgroud)

这意味着您的示例应在第二个路径之前添加空格:

rsync -e ssh root@remote.com:/path/to/file :/path/to/second/file/ /local/directory/
Run Code Online (Sandbox Code Playgroud)

我建议你首先使用-nor --dry-run选项进行尝试,这样你就可以在实际执行复制(和可能的删除)之前看到将要做什么.

  • 对于后代:对于旧版本的rsync,显然不是这样,例如OSX 10.9似乎附带的rsync 2.6.9; 该版本希望你做`rsync -av host:'file1 file2'`,当文件名中也有空格时,它会变得很尴尬.(幸运的是,自制软件有一个更新的版本.) (22认同)

zza*_*per 5

只是@tonin的实际示例。从实时服务器下载特定目录

rsync -av root@123.124.137.147:/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 .
Run Code Online (Sandbox Code Playgroud)

  • @tcurdt 添加 `-e 'ssh -p <port>'` 以连接到非默认 ssh 端口 (2认同)