If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
#!/bin/sh
# MySQL hostname
DBHOST='hostname'
# MySQL username
DBUSER='user'
# MySQL password
DBPASSWD='password'
# directory to dump backups to
DESTDIR=/path/to/backup
# format todays date
TODAY=`date +%Y-%m-%d`
# create directory for todays backup if needed
if [ ! -e $DESTDIR/$TODAY ]; then
mkdir $DESTDIR/$TODAY
fi
# get all databases
DBS=`mysql -u$DBUSER -p$DBPASSWD -h$DBHOST -e"show databases"`
for DATABASE in $DBS
do
if [ $DATABASE != "Database" ]; then
# let's put date here too in case archives get moved around later on
FILENAME=$TODAY-$DATABASE.gz
mysqldump -u$DBUSER -p$DBPASSWD -h$DBHOST $DATABASE | gzip --best > $DESTDIR/$TODAY/$FILENAME
fi
done
exit 0