rsync unexpected remote arg: [email protected]:/path

Server Fault Asked by PDiracDelta on July 21, 2020

I’m trying to use this rsync backup script on my server. However, I get the following error (when the script tries to execute the following command:

$ rsync -ar --delete -vvv -e 'ssh -i /root/.ssh/' --exclude='.*' [email protected]:/www/wp /mnt/hdd/LAV-backups/wp.0
Unexpected remote arg: [email protected]:/www/wp
rsync error: syntax or usage error (code 1) at main.c(1348) [sender=3.1.1]
[sender] _exit_cleanup(code=1, file=main.c, line=1348): about to call exit(1)

Strangely enough, everything works fine if I copy-paste* that into my terminal and press enter. It only goes wrong when it’s executed by the script.

What’s wrong here? How can I fix this?

*copy-paste = echo the line in the script, and then copy paste it after running the script once.

2 Answers

When using complex options which use quotes, don't use plain variables, but use arrays instead.

The following works me in a Bash backup script:

simple_options="-a -vi"
    --filter 'protect _before-*'
    --filter 'protect lost+found'
rsync ... $simple_options "${filters[@]}" ...

The script you link to seems to use only a plain variable:

    RSYNC_OPTS="-a --delete -q"

It seems you just added your ssh option to it, which produced the quoting mess that @roger-dueck pointed to in his comment.

Use a Bash array instead, and then use it inside double-quotes because your -e argument contains spaces:

RSYNC_OPTS=(-a --delete -q -e 'ssh -i /root/.ssh/')

Answered by mivk on July 21, 2020

What is the scripting language? Is it just a bash shell script? Keep an eye out for special characters in the scripting method of choice. It's possible something in your command is getting replaced.

If bash, store the whole string in a var and echo it out, is it the same? If its modified some special characters are seen and it gets modified. This gets me when running an escaped awk command in a bash script.

Unrelated, but rsync is best for maintaining data clones of source and dest directory. Probably not the best for backups in time. I'd recommend the following to maintain a clone that preserves properties and permissions, etc. rsync –avz –delete-after

-a (archive, preserve permissions of data) -v (verbose) -z (compress) -delete-after (waits until full file list is known prior to deleting data in dest directory that no longer exists in source)

Answered by MalformedPacket on July 21, 2020

Add your own answers!

Related Questions

Nginx: proxy remote content

1  Asked on January 5, 2022


Unable to start mysql service, no errors

1  Asked on January 5, 2022 by gilles-lesire


OpenSuse – Error adding repository

0  Asked on January 5, 2022


How to pause a send port and queue messages?

1  Asked on January 3, 2022 by jens-ehrich


Troubles monitoring a zimbra installation with nagios

1  Asked on January 3, 2022 by lorenzog


DNS queries fail from local machine running dnsmasq

2  Asked on January 3, 2022 by tommythekid


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir