duplicity-talk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [Duplicity-talk] Quotes in bash script


From: Moray Henderson
Subject: RE: [Duplicity-talk] Quotes in bash script
Date: Tue, 9 Nov 2010 12:04:27 +0000

I think I sent my previous reply from the wrong email address – which is just as well, because it wasn’t quite right.

 

I’ve run into this quote-removal thing a few times.  The most reliable method to get around it is to make EXC a bash array, rather than a simple variable.  If you want to preserve the wildcards when processing your for loop, then you may also need to disable wildcard expansion – otherwise if any files match that pattern while the loop is being processed, then name of the file will be added to the excludes list rather than the pattern.  Depending on exactly what you want, it may work just to disable shell wildcards (“file name globbing”) with set -f at the beginning of the script and not use an array variable.  However, this example illustrates both:

 

#!/bin/bash

 

EXCLUDES="**sess_** **civicrm/templates_c** **.no_delete**"

 

EXC=()

# Disable file name globbing

set -f

for EXCLUDE in ${EXCLUDES}; do

    EXC+=("--exclude" "$EXCLUDE")

done

# Enable file name globbing

set +f

 

duplicity --encrypt-key=${ENCKEY} "address@hidden" ${DOPTS} ${SOURCE} ${DESTINATION}

 

Referencing the array with the subscript @ expands it to all members of the array, and when enclosed in double-quotes each element becomes double-quoted.  See Arrays in man bash for details.

 

 

Moray.
"To err is human.  To purr, feline"

 

 

From: address@hidden [mailto:address@hidden On Behalf Of Martin Basting
Sent: 09 November 2010 10:58
To: address@hidden
Subject: [Duplicity-talk] Quotes in bash script

 

Hello,

We have the following script:

#!/bin/bash

# name of logfile
TODAY=`date +%F`
#Which gnupg key to use for backup
ENCKEY="OurKEY"
# special duplicity options
DOPTS="--asynchronous-upload --verbosity=3"
# which servers to backup. Include vars below
SERVERS="nlweb"
# How many days to keep the backup
DKEEP="30"
# some emails settings
FROM="address@hidden"
TO="address@hidden"
SMTP="smtp.provider.com"

for SERVER in $SERVERS; do
    # some vars which need server name
    SUBJECT="${SERVER} backup log"
    LOGFILE="/tmp/$TODAY-${SERVER}-backup.log"
    GLOGFILE=${LOGFILE}.gz
    # Remove old logfiles
    rm $LOGFILE $GLOGFILE
    # All output to logfile
    exec 3>&1 4>&2 >$LOGFILE 2>&1


        case "$SERVER" in

        nlweb)
                EXCLUDES="**sess_** **civicrm/templates_c** **.no_delete**"
                SOURCE="/media/nlweb"
                DESTINATION="file:///media/backupsets/nlweb"
        ;;

        nldc01)
                EXCLUDES=""
                SOURCE="/media/nldc01"
                DESTINATION="file:///media/backupsets/nldc01"
        ;;

        nlexchange)
                EXCLUDES=""
                SOURCE="/media/nlexchange/backup"
                DESTINATION="file:///media/backupsets/nlexchange"
        ;;

        esac

    # generate excludes
        for EXCLUDE in $EXCLUDES; do
                EXC="$EXC --exclude $EXCLUDE"
        done

        duplicity --encrypt-key=${ENCKEY} ${EXC} ${DOPTS} ${SOURCE} ${DESTINATION}
        duplicity remove-older-than ${DKEEP} ${DESTINATION}
        gzip $LOGFILE
        email -r $SMTP -s "$SUBJECT" -f "$FROM" -b -a "$GLOGFILE" "$TO"

done

For some reason it ignores the quotes for the excludes. So it does not exclude our excludes. If we run the syntax manually it just runs it.
Does anyone has an idea how to get this script working?

Kind Regards,

Martin


reply via email to

[Prev in Thread] Current Thread [Next in Thread]