Search code examples
rsync

rsync multiple remote directories to local machine preserving directory paths


Would I be able to use rsync as such:

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

or would i have to do something else?


Solution

  • Directly from the rsync man page:

    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}
    

    This means your example should have a space added before the second path:

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

    I'd suggest you first try it with the -n or --dry-run option, so you see what will be done, before the copy (and possible deletions) are actually performed.