I'm creating a function to perform a full-system backup using rsync
on my various devices. In order to troubleshoot, I've enabled set -x
to see what the command is actually doing. There appear to be extraneous single quotes surrounding the --exclude={...}
portion which is preventing it from working properly. Any ideas what might be causing this?
My function:
function system-backup {
u_excl=(\"/dev/*\", \"/proc/*\", \"/sys/*\", \"/tmp/*\", \"/run/*\", \"/mnt/*\", \"/media/*\", \"/lost+found\")
source=$HOSTNAME
sourcedir='/'
dest='192.168.1.51:'
# determine additional folders to exclude and other options
if [ $HOSTNAME == my-pc ]; then
u_excl+=(,\"/home/*\")
fi
excl=$(printf {"%s" "${u_excl[@]}"})
( set -x; sudo rsync -aAXHv --delete --exclude={"$excl"} "$sourcedir" "$dest"'/mnt/external/bkps/'"$source"'_bkp' )
}
export -f system-backup
And my output:
$ system-backup
+ sudo rsync -aAXHv '--exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found","/home/*"}' / 192.168.1.51:/mnt/external/bkps/my-pc_bkp