backup-mydb.sh

backup-mydb.sh
#!/bin/sh

# shell script to backup all mysql db to disk(/var/lib/mysql)
#
# last update: 2009-11-09

# edit to your needs
PROGNAME=$0
ROOTPW="0000"
DUMPFILE="/var/lib/mysql/alldb"

# check current state RO or RW, force RW if not
mount | egrep "ROOT_FS.+rw,"
if [ $? -ne 0 ] ; then
        rw=0
        /usr/local/sbin/remountrw
else
        rw=1
fi

# protect dumpfile from error
set -e

mysqldump --add-drop-table --quote-names -u root -p$ROOTPW --all-databases | gzip -c > $DUMPFILE.tmp
r=$?
if [ "$r" != "0" ] ; then
        logger "$PROGNAME - db dump failed!"
        exit 1
fi

sync

# shift the current dump to backup dump
[ -f $DUMPFILE.current ] && mv -f $DUMPFILE.current $DUMPFILE.bak
mv -f $DUMPFILE.tmp $DUMPFILE.current
sync

# return to previous state
[ "$rw" = "0" ] && /usr/local/sbin/remountro
voyage/backup-mydb.sh.txt · Last modified: 2010-06-10 12:02 by admin
Back to top
GNU Free Documentation License 1.3
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0