Script throwing unexpected operator when using mysqldump

Posted by Astron on Stack Overflow See other posts from Stack Overflow or by Astron
Published on 2011-03-20T11:59:56Z Indexed on 2011/03/20 16:09 UTC
Read the original article Hit count: 327

Filed under:
|
|
|
|

A portion of a script I use to backup MySQL databases has stopped working correctly after upgrading a Debian box to 6.0 Squeeze. I have tested the backup code via CLI and it works fine. I believe it is in the selection of the databases before the backup occurs, possibly something to do with the $skipdb variable. If there is a better way to perform the function then I'm will to try something new. Any insight would be greatly appreciated.

$ sudo ./script.sh
[: 138: information_schema: unexpected operator
[: 138: -1: unexpected operator
[: 138: mysql: unexpected operator
[: 138: -1: unexpected operator

Using bash -x script here is one of the iterations:

+ for db in '$DBS'
+ skipdb=-1
+ '[' test '!=' '' ']'
+ for i in '$IGGY'
+ '[' mysql == test ']'
+ :
+ '[' -1 == -1 ']'
++ /bin/date +%F
+ FILE=/backups/hostname.2011-03-20.mysql.mysql.tar.gz
+ '[' no = yes ']'
+ /usr/bin/mysqldump --single-transaction -u root -h localhost '-ppassword' mysql
+ /bin/tar -czvf /backups/hostname.2011-03-20.mysql.mysql.tar.gz mysql.sql
mysql.sql
+ rm -f mysql.sql

Here is the code.

if [ $MYSQL_UP = "yes" ]; then
echo "MySQL DUMP" >> /tmp/update.log
echo "--------------------------------" >> /tmp/update.log
DBS="$($MYSQL -u $MyUSER -h $MyHOST -p"$MyPASS" -Bse 'show databases')"
for db in $DBS
do
    skipdb=-1
    if [ "$IGGY" != "" ] ;
    then
        for i in $IGGY
        do
            [ "$db" == "$i" ] && skipdb=1 || :
        done
    fi
    if [ "$skipdb" == "-1" ] ;
    then
        FILE="$DEST$HOST.`$DATE +"%F"`.$db.mysql.tar.gz"
        if [ $ENCRYPT = "yes" ]; then
            $MYSQLDUMP -u $MyUSER -h $MyHOST -p"$MyPASS" $db > $db.sql && $TAR -czvf - $db.sql | $OPENSSL enc -aes-256-cbc -salt -out $FILE.enc -k $ENC_PASS && rm -f $db.sql
        else
            $MYSQLDUMP --single-transaction -u $MyUSER -h $MyHOST -p"$MyPASS" $db > $db.sql && $TAR -czvf $FILE $db.sql && rm -f $db.sql
        fi
    fi
done

fi

© Stack Overflow or respective owner

Related posts about mysql

Related posts about shell