~maria-captains/maria/10.0-flashback

Viewing all changes in revision 3510.

  • Committer: Lixun Peng
  • Date: 2013-04-02 11:45:28 UTC
  • Revision ID: p.linux@163.com-20130402114528-lljg93etrbdhidhn
FLASHBACK FEATURE

How to use this feature?
I added several new arguments for mysqlbinlog: (binlog_format must be ROW)
--flashback (-B), it will let mysqlbinlog to work on FLASHBACK mode.
--table (-T), it likes -d, but this argument is for tables.
--review, it will let mysqlbinlog print the SQL for reviewing. Reviewing feature will create a new "review" table to record the data that will be modified by 
FLASHBACK feature. If you aren't special the --review-dbname/tablename, "review" table will created on current DB, and the table name will be "__"+original_table_name. And for getting the original table struct, mysqlbinlog need to connect mysql, so --user/--host/--password is necessary if needed.
--review-dbname, the DB that you want to store the review table.
--review-tablename, the TABLE that you want to store the original data before modified. Only if you set -T, this argument is useful.

For example:
I have a table "t" in database "test", we can compare the output with --flashback and without.
#client/mysqlbinlog /data/mysqldata_10.0/binlog/mysql-bin.000001 -vv -d test -T t --start-datetime="2013-03-27 14:54:00"  > /tmp/1.sql
#client/mysqlbinlog /data/mysqldata_10.0/binlog/mysql-bin.000001 -vv -uroot -d test -T t --start-datetime="2013-03-27 14:54:00" -B --review > /tmp/2.sql

Then, importing the flashback output can flashback database/table to the special time.

How to implement Flashback:
1. mysqlbinlog tool can parse the binlog files and print them, so we can use the most of code in mysqlbinlog.
2. Changing the event type (INSERT -> DELETE; DELETE -> INSERT).
3. Exchanging the SET/WHERE part in UPDATE event (UPDATE table SET x=1 WHERE y=2 -> UPDATE table SET y=2 WHERE x=1).
4. Invert the events in binlog files, from end to beginning (binlog: e1,e2,e3... -> flashback_log: en...e3,e2,e1).


expand all expand all

Show diffs side-by-side

added added

removed removed

Lines of Context: