Ssh – way to send custom arguments to an rsync server

rsyncssh

I have a backup server that clients use with rsync over SSH. The server is configured to run a custom shell script that wraps the invocation of the rsync server side. The client side is unaware of this and can issue any valid rsync command-line.

I would like to pass some arguments from the client into that shell script. Something like

$ rsync -av -customarg1 value1 -customarg2 value2 file1 file2 user@server

The client-side rsync rejects any arguments that it doesn't know, as does ssh (via rsync -e). The best I have come up with is to pass arguments as fake server-side file specs that the script extracts from the server-side command-line prior to executing it to launch the rsync server. i.e a command like

$ rsync -av file1 file2 user@server:some/path\;customarg1=value1\;customarg2=value2

would provide two arguments and then behave as if the command was

$ rsync -av file1 file2 user@server:some/path

(This uses the fact that SSH sets a number of environment variables including $SSH_ORIGINAL_COMMAND which contains the command issued by the ssh client (i.e the rsync server command launched by the rsync client) regardless of what the ssh server is configured to execute (i.e. the custom shell script))

Best Answer

Perhaps you could use the -M option (long version --remote-option), which does not seem to be checked by the client rsync. -M-xxxx is passed to the remote with the -M stripped off as -xxxx. You can easily play with this using -M-M-xxxx, which is ignored by client and remote:

rsync -av -M-M-myvar=val /tmp/test/ remote:test/

If your server front-end recognises and removes the resulting flags before calling rsync, you get what you needed.

You can play further with --rsync-path which allows you to run any script. It will get the remote args concatenated. Eg

rsync -a -M-myvar=val --rsync-path='echo hello >/tmp/out; ./mysync' /tmp/test/ remote:test/

will run on the remote something like

echo hello >/tmp/out
./mysync --server -logDtpre.iLsfx -myvar=val . test/
Related Question