- 论坛徽章:
- 0
|
mysql Server version: 5.1.51-log wjlcn_a 上备份: log 日志: [wjlcn@wjlcn_a 3306]$ ll total 1832 -rw-rw---- 1 wjlcn wjlcn 215 Sep 1 15:04 general.log -rw-rw---- 1 wjlcn wjlcn 5932 Sep 7 15:18 mysql-bin.000010 -rw-rw---- 1 wjlcn wjlcn 284 Sep 7 15:45 mysql-bin.000011 -rw-rw---- 1 wjlcn wjlcn 528 Sep 7 15:18 mysql-bin.index -rw-rw---- 1 wjlcn wjlcn 3253 Sep 7 15:18 mysqld.err -rw-rw---- 1 wjlcn wjlcn 3451 Sep 7 15:18 slowquery.log
[wjlcn@wjlcn_a backup]$ mysqldump -uroot -S/home/wjlcn/app/mysql/tmp/3306/mysql.sock -p --flush-logs --master-data=2 --hex-blob -R -f --all-databases > wjlcntest.sql
[wjlcn@wjlcn_a backup]$ ls wjlcntest.sql
备份后: [wjlcn@wjlcn_a 3306]$ ll total 1836 -rw-rw---- 1 wjlcn wjlcn 215 Sep 1 15:04 general.log -rw-rw---- 1 wjlcn wjlcn 327 Sep 7 18:03 mysql-bin.000011 -rw-rw---- 1 wjlcn wjlcn 106 Sep 7 18:03 mysql-bin.000012 -rw-rw---- 1 wjlcn wjlcn 576 Sep 7 18:03 mysql-bin.index -rw-rw---- 1 wjlcn wjlcn 3253 Sep 7 15:18 mysqld.err -rw-rw---- 1 wjlcn wjlcn 3906 Sep 7 18:03 slowquery.log
在wjlcn_a插入一些数据: mysql> insert into a values(20,curdate()); mysql> insert into a values(21,curdate()); mysql> insert into a values(22,curdate()); mysql> insert into a values(23,curdate()); mysql> insert into a values(24,curdate()+1);
mysql> select * from a; +----+------------+ | id | date | +----+------------+ | 15 | 2011-08-08 | | 16 | 2011-08-08 | | 17 | 2011-08-08 | | 18 | 2011-08-08 | | 19 | 0000-00-00 | | 20 | 2011-09-07 | | 21 | 2011-09-07 | | 22 | 2011-09-07 | | 23 | 2011-09-07 | | 24 | 2011-09-08 | +----+------------+ 10 rows in set (0.00 sec)
插入的数据记录在mysql-bin.000012
**********************************************
还原: 将备份传到wjlcn_b上: [wjlcn@wjlcn_d backup]$ mysql -uroot -S/home/wjlcn/app/mysql/tmp/3306/mysql.sock -p < wjlcntest.sql 还原备份后插入的数据: [wjlcn@wjlcn_d backup]$ mysqlbinlog mysql-bin.000012 | mysql -uroot -S/home/wjlcn/app/mysql/tmp/3306/mysql.sock -p
查看还原的后的数据库: mysql> select * from a; +----+------------+ | id | date | +----+------------+ | 15 | 2011-08-08 | | 16 | 2011-08-08 | | 17 | 2011-08-08 | | 18 | 2011-08-08 | | 19 | 0000-00-00 | | 20 | 2011-09-07 | | 21 | 2011-09-07 | | 22 | 2011-09-07 | | 23 | 2011-09-07 | | 24 | 2011-09-08 | +----+------------+ 10 rows in set (0.02 sec)
完成!
******************************************** 恢复指定时间段的binlog:
查询需要恢复的时间段: [wjlcn@wjlcn_d backup]$ date -d '1970-01-01 UTC 1315390158 seconds' Wed Sep 7 18:09:18 CST 2011
[wjlcn@wjlcn_d backup]$ date -d '1970-01-01 UTC 1315390169 seconds' Wed Sep 7 18:09:29 CST 2011 用mysqlbinlog恢复: mysqlbinlog --start-date="2011-09-07 18:09:15" --stop-date="2011-09-07 18:09:30" mysql-bin.000012| mysql -uroot -S/home/wjlcn/app/mysql/tmp/3306/mysql.sock -p
或者用mysqlbinlog导出指定时间的log: mysqlbinlog --start-date="2011-09-07 18:09:15" --stop-date="2011-09-07 18:09:30" mysql-bin.000012 > wjl.sql
wjlcn 2011-09-07
|
|