备份相关存储过程,含有创建数据库create databaseName ;use databaseName;
[root@d-mysql205 shell]# cat dbBak_R.sh
#!/bin/bash
bakPath=/root/mysqlbak/`date +%F`
mkdir -p ${bakPath}
for db in `mysql -uroot -e "show databases;"|grep ytfym`
do
mysqldump -uroot -R -B $db >${bakPath}/${db}.sql
done
加B恢复
[root@d-mysql205 shell]# cat cover_B_db.sh
#!/bin/bash
#bakdir=/root/MYSQL
#bakdir=/root/mysqlbak/2020-04-09
bakdir=$1
for db in `ls ${bakdir}|awk -F. '{print $1}'`
do
mysql -uroot <<EOF
drop database if exists $db;
source $bakdir/$db.sql
EOF
done
[
没有B选项的恢复
root@d-mysql205 shell]# cat cover_db.sh
#!/bin/bash
bakdir=$1
for db in `ls ${bakdir}|awk -F. '{print $1}'`
do
mysql -uroot <<EOF
drop database if exists $db;
create database $db;
use $db;
source $bakdir/$db.sql
EOF
done