Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

share|improve this question

3 Answers 3

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
share|improve this answer
    
Dear geirha, thank you very much. This is exactly what I was looking for. I don't know anything about bash-scripting. Now I've a reliable backup! Thanks again. –  chris Jun 16 '11 at 5:37

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[@]}"
share|improve this answer
    
Well, I copied the whole script from wiki.ubuntuusers.de/… I don't know how to handle all the other options so I'll try Rajish's reply next time. Won't it work? –  chris Jun 13 '11 at 17:12
    
You need to lose the outer quotes on the last --exclude there. –  geirha Jun 13 '11 at 20:26
1  
@chris I'm afraid that script is quite badly written, so it's not a good script to use as a template. –  geirha Jun 13 '11 at 20:36
    
Thank you for all the answers. When I use an array like in glenn's or geirha's reply, what do I write in line 53 for example? $RSYNC -e "$S" -avR $FROMSSH:$SOURCE "${RSYNCCONF[@]}" $TARGET$TODAY $INC >> $LOG 2>&1 Simply replace $RSYNCCONF with the array? –  chris Jun 13 '11 at 23:15
    
'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. –  chris Jun 14 '11 at 22:57

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/ "
share|improve this answer
    
Thank you for replying quickly. –  chris Jun 13 '11 at 15:27
    
You can't put syntactical quotes inside quotes. An array is the only sane way. –  geirha Jun 13 '11 at 20:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.