directory name with space and bash
I'd like to exclude the directories "temp" and "Ubuntu One/" from backup. What is the correct escaping of the space????
RSYNCCONF="--delete --exclude=.* --exclude=temp/"
Thanks in advance!
- Chris
Edit/PS:
excludes=( ".*" temp/ "Ubuntu One/" )' 'RSYNCCONF="${excludes[@]/#/--exclude=}"
and
$RSYNC -e "$S" -avR $FROMSSH:$SOURCE ${RSYNCCONF[@]} $TARGET$TODAY $INC >> $LOG 2>&1
didn't work. I'd really appreciate any advice.
This is the script: http://wiki.ubuntuusers.de/_attachment?target=Skripte%2FBackup_mit_RSYNC%2Fbackup.sh
If you're building up options in a string, you'll run into problems when you try to use it (rsync "$RSYNCCONF"
).
Better to use an array -- when you dereference the array, each element will be properly handled by the shell:
RSYNCCONF=( --delete '--exclude=.*' --exclude=temp/ '--exclude="Ubuntu One/"' )
rsync "${RSYNCCONF[@]}"
Put it into single quotes:
RSYNCCONF="--delete --exclude=.* --exclude=temp/ --exclude='Ubuntu One/' "
or put a backslash before the space:
RSYNCCONF="--delete --exclude=.* --exclude=temp/ --exclude=Ubuntu\\ One/ "
Here's one way of doing it.
excludes=( ".*" temp/ "Ubuntu One/" )
rsync --delete "${excludes[@]/#/--exclude=}"
Note that the above uses bash syntax, so it won't work with sh. Also, the quotes are vital, do not omit them.
See http://mywiki.wooledge.org/WordSplitting for an explanation of why putting more than one argument into a string variable is wrong.
EDIT: From the pastebin in your comments, this seems to be what you want.
#!/bin/bash
source=/home/chris/
backupdir=/media/alteplatte/backups
backupname=$(date +%Y-%m-%d)-cd
excludes=( ".*" temp/ "Ubuntu One/" )
linkdest=$backupdir/link
if [[ -d $backupdir ]]; then
rsync -av ${linkdest:+"--link-dest=$linkdest"} --delete \
"${excludes[@]/#/--exclude=}" "$source" "$backupdir/$backupname"
else
echo "$0: $backupdir: Not a directory, make sure the filesystem is mounted" >&2
exit 1
fi