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/id_rsa_LAV.pub' --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.
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"
filters=(
--filter 'protect _before-*'
--filter 'protect lost+found'
-F
)
#...
rsync ... $simple_options "${filters[@]}" ...
The script you link to seems to use only a plain variable:
RSYNC_OPTS="-a --delete -q"
#...
rsync $RSYNC_OPTS $SOURCE_PATH/. $BACKUP_PATH/$SOURCE_BASE.0/.
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/id_rsa_LAV.pub')
rsync "${RSYNC_OPTS[@]}" $SOURCE_PATH/. $BACKUP_PATH/$SOURCE_BASE.0/.
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
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP