I'm trying to write a bash script for a snapshot backup with rsync to a server.
The command I want to invoke is
rsync -aPh -e ssh --rsync-path='sudo rsync' --link-dest=../last /home/username/files remoteuser@server:/srv/backups/snapshots/username/snapshot_xxx
my script looks like
OPT="-aPh -e ssh --rsync-path='sudo rsync'"
LINK="--link-dest=../last/"
SRC="/home/username/files/"
SNAP="remoteuser@server:/srv/backups/snapshots/username/"
date=`date "+%Y-%b-%d_%T"`
# Run rsync to create snapshot
rsync $OPT $LINK $SRC ${SNAP}$date
running this script with bash -x the command I'm getting is
rsync -aPh -e ssh '--rsync-path='\''sudo' 'rsync'\''' --link-dest=../last /home/username/files remoteuser@server:/srv/backups/snapshots/username/snapshot_xxx
which leads to the following errors:
bash: -c: line 0: unexpected EOF while looking for matching `''
bash: -c: line 1: syntax error: unexpected end of file
How do I prevent bash from inserting the extra single quotes and escaped single quotes?
-c
would not be used – steeldriver Nov 03 '19 at 19:44