rsync command for multi files and dirs from remote server
Benjamin R. Haskell
rsync at benizi.com
Sun Sep 18 21:43:10 MDT 2011
[reversing t
On Sun, 18 Sep 2011, Kevin Korb wrote:
> On 09/18/11 23:06, Benjamin R. Haskell wrote:
>> On Sun, 18 Sep 2011, Noah wrote:
>>
>>> Hi there,
>>>
>>> okay so I have a port knocker installed on my remote server so I am
>>> trying to bundle a bunch of directories in a single ssh session that
>>> rsync establishes. so far all the rsync examples I have seen
>>> require a new ssh session for each directory.
>>>
>>> is there anyway to get something like this into one line and
>>> therefore one ssh session. Clues on this?
>>
>> Try the ControlMaster=auto option to SSH with an appropriate
>> ControlPath setting.
>>
>> Example of usage at: (Googled: SSH multiplex)
>> http://www.linuxjournal.com/content/speed-multiple-ssh-connections-same-server
>>
>>
>> As an '-e' argument, it'd be:
>>
>> -e 'ssh [...etc...] -o ControlMaster=auto -o
>> ControlPath=~/.ssh/master-%r@%h:%p [...etc...]'
>>
>
> BTW, you can specify all that stuff in ~/.ssh/config and save your
> fingers some wear.
The link I posted showed it in config format. I was providing an
alternative, since the OP's already doing weird acrobatics with -e:
>>> -e 'ssh -p <port> -o ServerAliveInternal=10'
But, as you point out, this is probably better placed in an
~/.ssh/config:
Host rsync-reverse
HostName hostname.net
User root
Port <port>
ServerAliveInternal 10
ControlMaster auto
ControlPath ~/.ssh/master-%r@%h:%p
Then, the commands from before:
>>> /usr/bin/rsync -avrz --human-readable --progress --update --perms --ignore-existing -e 'ssh -p <port> -o ServerAliveInterval=10' --delete --relative root@<hostname.net>:/etc '/shares/internal/<dir>/'
>>> /usr/bin/rsync -avrz --human-readable --progress --update --perms --ignore-existing -e 'ssh -p <port> -o ServerAliveInterval=10' --delete --relative root@<hostname.net>:/root '/shares/internal/<dir>/'
1. don't need the '-e' option ('ssh' is the default, and the options
will come from ~/.ssh/config)
2. can use the Host specified above to shorten the source
3. don't need the redundant '-r' and '--perms' (-a includes both)
/usr/bin/rsync -avz --human-readable --progress --update --ignore-existing --delete --relative rsync-reverse:/etc '/shares/internal/<dir>/'
/usr/bin/rsync -avz --human-readable --progress --update --ignore-existing --delete --relative rsync-reverse:/root '/shares/internal/<dir>/'
And, if the sources are really /etc and /root, you can just
combine them into the following (and the --relative is redundant because
it's based at the root directory):
/usr/bin/rsync -avz --human-readable --progress --update
--ignore-existing --delete --relative rsync-reverse:'/etc /root'
'/shares/internal/<dir>/'
(in which case you might not even need the ControlMaster/ControlPath
stuff.)
--
Best,
Ben
More information about the rsync
mailing list