恢复一个库的方法一:
[root@testdb1 ~]# grep -nr '^CREATE DATABASE' all_bak.sql
22:CREATE DATABASE /*!32312 IF NOT EXISTS*/ `testdb` /*!40100 DEFAULT CHARACTER SET utf8 */;
2321:CREATE DATABASE /*!32312 IF NOT EXISTS*/ `scottdb` /*!40100 DEFAULT CHARACTER SET utf8 */;
2337:CREATE DATABASE /*!32312 IF NOT EXISTS*/ `mysql` /*!40100 DEFAULT CHARACTER SET utf8 */;
sed -n '22,2320p' all_bak.sql > restore_db_basedata.sql
再把 restore_db_basedata.sql 文件中的CREATE DATABASE和 USE 语句注释
sed -i 's/^CREATE DATABASE/-- CREATE DATABASE/g' restore_db_basedata.sql
sed -i 's/^USE `testdb`/-- USE `testdb`/g' restore_db_basedata.sql
方法二:
sed -n '/^-- Current Database: `testdb`/,/^-- Current Database: `/p' all_bak.sql > restore_db_basedata_2.sql
从全备份中只恢复 operlog_20180620 表
从备份查询恢复表的表结构
sed -e'/./{H;$!d;}' -e 'x;/CREATE TABLE `operlog_20180620`/!d;q' trade_log_20180627100605.sql
从备份查询出表的表数据
grep 'INSERT INTO `operlog_20180626`' trade_log_20180627100605.sql >data.sql