Is there a way to send custom arguments to an rsync server?

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/

This isn't exactly pretty, but it could all be hidden away in a script:

SSH can send arbitrary environment variables across the tunnel; both the client and server need to be configured to allow it. The client is easily done with the -o option; the server you'd have to do in your sshd_config file. Accepting arbitrary ones is a bad idea, but something like this should work:

BACKUP_PROVIDER_VAR1=val1 rsync -e 'ssh -o SendEnv=BACKUP_PROVIDER_*' …

You'd then need to put a AcceptEnv LANG LC_* BACKUP_PROVIDER_* in your sshd_config (which, so far as I know, could be limited to only a certain user/group with a Match block). Actually, you probably don't need LANG or LC_* from your backup clients, so you'd just want your own custom env vars.

Tags:

Ssh

Rsync