Results 1 to 2 of 2

Thread: Mysql backup Error

  1. #1
    Join Date
    Mar 2009
    Beans
    213

    Mysql backup Error

    Hi i have used the below script for the backup of the mysql database

    i got to error am new for the shell script

    Errors:
    sh /home/blaze/backupmysql.sh
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
    /home/blaze/backupmysql.sh: 54: Syntax error: "then" unexpected (expecting "done")


    Mysql Database backup using the Shell Script

    #!/bin/bash

    MyUSER="root" #USERNAME
    MyPASS="XXX" #PASSWORD
    MyHOST="localhost" # HOSTNAME


    MYSQL="$(which mysql)"
    MYSQLDUMP="$(which mysqldump)"
    CHOWN="$(which chown)"
    CHMOD="$(which chmod)"
    GZIP="$(which gzip)"

    # Backup Dest directory,change this if you have some other location
    DEST="/backup"

    #Main directory where backup will be stored
    MBD="$DEST/mysql"

    # Get hostname
    HOST="$(hostname)"

    # Get data in dd-mm-yyyy format

    NOW="$(date+"%d-%m-%y")"

    # File to store current backup file
    FILE=""

    #store list of databases
    DBS=""

    # DO Not BACKUP these databases
    IGGY="test"

    [ ! -d $MBD ] && mkdir -p $MBD | | :

    #Only root can access it!
    $CHOWN 0.0 -R $DEST
    $CHMOD 0600 $DEST

    # Get all database list first

    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="$MBD/$db.$HOST.$NOW.gz"

    $MYSQLDUMP -u $MyUSER -h $MyHOST -p$MyPASS $db | $GZIP -9 > $FILE

    fi
    done

  2. #2
    Join Date
    Aug 2010
    Location
    Wales
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Mysql backup Error

    if["$IGGY" != ""];
    do you need a space
    Code:
    if[ "$IGGY" != "" ];
    and double brackets may work better
    Code:
    if [[ "$IGGY" != "" ]];
    just a thought
    Perseverance will succeed (usually)
    ubuntu user -32597 - linux user - 526569
    Wireless Info Script
    Blog

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •