#!/bin/bash
# sonia 16-nov-05
# backup each mysql db into a different file, rather than one big file
# as with --all-databases - will make restores easier
USER="root"
PASSWORD="secret"
OUTPUTDIR="/var/lib/bacula"
MYSQLDUMP="/usr/bin/mysqldump"
MYSQL="/usr/bin/mysql"
# clean up any old backups - save space
rm "OUTPUTDIR/*bak" > /dev/null 2>&1
# get a list of databases
databases=`$MYSQL --user=$USER --password=$PASSWORD
-e "SHOW DATABASES;" | tr -d "| " | grep -v Database`
# dump each database in turn
for db in $databases; do
echo $db
$MYSQLDUMP --force --opt --user=$USER --password=$PASSWORD
--databases $db > "$OUTPUTDIR/$db.bak"
done
16 November 2005
Backup multiple MySQL databases into separate files
4 Comments »
RSS feed for comments on this post. TrackBack URI
Very nice script, thanks for posting it.
Comment by Eddie Thieda — 6 March 2009 @ 06:51
Very nice and works first time.
Comment by darian — 29 October 2009 @ 12:31
You’re welcome!
Comment by Sonia — 29 October 2009 @ 17:02
Hi,
Excellent.Nice article thanks for sharing.
Comment by Rahul — 19 November 2009 @ 05:31