#!/bin/sh # # $Header: /CVSROOT/public/scylla-charybdis/md5backup/bin/sc-mysql.sh,v 1.7 2005/02/20 15:43:09 tino Exp $ # # $Log: sc-mysql.sh,v $ # Revision 1.7 2005/02/20 15:43:09 tino # commit for release # # Revision 1.6 2004/10/05 02:04:03 tino # Generally improved to work more seamlessly # # Revision 1.5 2004/09/29 23:32:44 tino # many minor and mini fixes, sc-loop.sh should work again # # Revision 1.4 2004/07/05 18:11:24 tino # some more logging in bin/sc-*.sh # # Revision 1.3 2004/07/03 12:55:03 tino # working version commit # # Revision 1.2 2004/05/15 14:42:47 tino # updated # # Revision 1.1 2004/05/04 05:11:01 tino # sc-backup.sh: backup via scylla+charybis; dobackup.sh convenience script # Do not look in the path, it can be contaminated to catch the PW DUMP=/usr/bin/mysqldump [ ! -x "$DUMP" ] && DUMP=/usr/local/bin/mysqldump TARG="$1" if [ -z "$TARG" ] then echo "Usage: `basename "$0"` /base/path [mysql-root-pw]" >&2 exit 1 fi # This test now extremely dirty, but it works ;) # Return 0 only if directory missing and mysql is not installed. # Else return 1 if something is missing. if [ ! -d "$TARG/mysql" ] then if [ -x "$DUMP" ] then echo "Mysql installed but mysql dump not enabled!" >&2 exit 1 fi echo "Mysql not installed and dump not enabled, skipping" >&2 exit 0 fi log() { loga="$1" shift printf "%s: $loga\n" "`date +'%Y-%m-%d %H:%M:%S'`" "$@" >> "tmp/log.$TARG" } [ -d "$TARG/mysql" ] || mkdir "$TARG/mysql" || exit 1 TODAY="`date +%Y%m%d-%H%M%S`" SUB="`expr "$TODAY" : '\(......\)'`" OUT="$TARG/mysql/$SUB/`hostname -f`-$TODAY.sql" mkdir "$TARG/mysql/$SUB" 2>/dev/null echo "Backing up mysql database." MYPW="$2" if [ -z "$MYPW" ] then read -esp "Please enter your mysql root password:" MYPW || exit 1 fi # I really dislike to see passwords on the command line. # They shall not be seen in environment either. # However as mysql insists of reading it from the tty # we have no other choice. That's really bad design of mysql! "$DUMP" -q -a -A -c -e -F -hlocalhost -uroot --password="$MYPW" > "$OUT" && bzip2 -9 "$OUT" && log "mysql dumped, %d bytes" `wc -c < "$OUT.bz2"`