Jul 05

#!/bin/bash
#destination directory named with daily date
DIR=”/var/backup/mysql/$(date +%m%d%Y)”
if [ -d $DIR ]; then
    echo “Dir $DIR exists”;
else
    echo “Creating $DIR”;
    mkdir $DIR
fi

USER=”root”
ROOT_PASSWORD=”root_password”

#get list of databases
LIST=`mysql -u $USER -p$ROOT_PASSWORD -e”show databases” -s |egrep -v ‘Database|information_schema|mysql|temp’`

for DB in $LIST; do
    BFILE=$DB-backup-$(date +%m%d%Y).sql
    mysqldump -u $USER -p$ROOT_PASSWORD $DB > $DIR/$BFILE
    echo $BFILE
done

#in the end we make a general backup for safety
#all databases backup in one sql file
BFILE=mysql_ALL_DB_backup-$(date +%m%d%Y).sql
mysqldump -A -u $USER -p$ROOT_PASSWORD > “$DIR/$BFILE”

written by MG \\ tags: , ,

One Ping to “MySql: how to backup individual databases”

  1. Bookmarks about Mysql Says:

    […] – bookmarked by 1 members originally found by TAJIG on 2008-10-20 MySql: how to backup individual databases script http://mugurel.sumanariu.ro/mysql/mysql-how-to-backup-individual-databases-script/ – bookmarked by […]


Leave a Reply

*