#!/bin/sh
BACKPATH=/server/backup
MYPASS=ruanganlove999
SOCKET=/data/3306/mysql.sock
MYCMD="mysql -u$MYUSER -P$MYPASS -S $SOCKET"
MYDUMP="mysqldump -u$MYUSER -p$MYPASS -S$SOCKET -x-B -F -R"
[ ! -d $BACKPATH ] && mkdir -p $BACKPATH
DBLIST=`$MYCMD -e "show databases;"|sed 1d|egrep -v "_schema|mysql"`
for dbname in $DBLIST
do
$MYDUMP$dbname|gzip >/server/backup/${dbname}_$(date +%F).sql.gz
done
======================================
简单脚本:
cat fenku.sh
for dbname in `mysql -uroot -pruanganlove999 -e"show databases;"|grep -Evi "database|infor|perfor"`
do
mysqldump-uroot -pruanganlove999 --events -B$dbname|gzip>/opt/bak/${dbname}_bak.sql.gz
done