mysql備份每個庫下面每個表
阿新 • • 發佈:2017-05-12
mysql備份每個庫下面每個表 for db_name in $DBS
do
mkdir -p $BACKUPDIR/$DATE/$db_name
tables=`mysql -u$MYUSER -p$MYPASS -Bse "use $db_name;show tables"`
for table_name in $tables
do
mysqldump -u$MYUSER -p$MYPASS -h$HOST --single-transaction --master-data=2 $db_name $table_name >$BACKUPDIR/$DATE/$db_name/$table_name.sql
done
done
#!/bin/bash
MYUSER="root"
MYPASS="123456"
HOST="localhost"
BACKUPDIR="/backup_mysql"
DATE=`date -I`
RETENTION=20
#MYSQLDATA="/var/lib/mysql"
[ ! -d $BACKUPDIR/$DATE ] && mkdir -p $BACKUPDIR/$DATE
DBS=`mysql -u$MYUSER -p$MYPASS -Bse "show databases"|grep -v "information_schema" |grep -v "test"`
do
mkdir -p $BACKUPDIR/$DATE/$db_name
tables=`mysql -u$MYUSER -p$MYPASS -Bse "use $db_name;show tables"`
for table_name in $tables
do
mysqldump -u$MYUSER -p$MYPASS -h$HOST --single-transaction --master-data=2 $db_name $table_name >$BACKUPDIR/$DATE/$db_name/$table_name.sql
done
mysql備份每個庫下面每個表