mirror of
https://github.com/MariaDB/server.git
synced 2025-01-24 15:54:37 +01:00
d75d8631ed
==== Description ==== Flashback can rollback the instances/databases/tables to an old snapshot. It's implement on Server-Level by full image format binary logs (--binlog-row-image=FULL), so it supports all engines. Currently, it’s a feature inside mysqlbinlog tool (with --flashback arguments). Because the flashback binlog events will store in the memory, you should check if there is enough memory in your machine. ==== New Arguments to mysqlbinlog ==== --flashback (-B) It will let mysqlbinlog to work on FLASHBACK mode. ==== New Arguments to mysqld ==== --flashback Setup the server to use flashback. This enables binary log in row mode and will enable extra logging for DDL's needed by flashback feature ==== 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 -d test -T t --start-datetime="2013-03-27 14:54:00" -B > /tmp/2.sql Then, importing the output flashback file (/tmp/2.log), it can flashback your database/table to the special time (--start-datetime). And if you know the exact postion, "--start-postion" is also works, mysqlbinlog will output the flashback logs that can flashback to "--start-postion" position. ==== Implement ==== 1. As we know, if binlog_format is ROW (binlog-row-image=FULL in 10.1 and later), all columns value are store in the row event, so we can get the data before mis-operation. 2. Just do following things: 2.1 Change Event Type, INSERT->DELETE, DELETE->INSERT. For example: INSERT INTO t VALUES (...) ---> DELETE FROM t WHERE ... DELETE FROM t ... ---> INSERT INTO t VALUES (...) 2.2 For Update_Event, swapping the SET part and WHERE part. For example: UPDATE t SET cols1 = vals1 WHERE cols2 = vals2 ---> UPDATE t SET cols2 = vals2 WHERE cols1 = vals1 2.3 For Multi-Rows Event, reverse the rows sequence, from the last row to the first row. For example: DELETE FROM t WHERE id=1; DELETE FROM t WHERE id=2; ...; DELETE FROM t WHERE id=n; ---> DELETE FROM t WHERE id=n; ...; DELETE FROM t WHERE id=2; DELETE FROM t WHERE id=1; 2.4 Output those events from the last one to the first one which mis-operation happened. For example: |
||
---|---|---|
.. | ||
binlog_base64_flag.test | ||
binlog_bug23533.test | ||
binlog_bug36391-master.opt | ||
binlog_bug36391.test | ||
binlog_checkpoint.test | ||
binlog_checksum.test | ||
binlog_commit_wait.test | ||
binlog_database.test | ||
binlog_delete_and_flush_index-master.opt | ||
binlog_delete_and_flush_index.test | ||
binlog_dmls_on_tmp_tables_readonly.test | ||
binlog_drop_if_exists.test | ||
binlog_format_switch_in_tmp_table.test | ||
binlog_grant.test | ||
binlog_implicit_commit.test | ||
binlog_incident.test | ||
binlog_index-master.opt | ||
binlog_index.test | ||
binlog_innodb.test | ||
binlog_innodb_row.test | ||
binlog_ioerr.test | ||
binlog_killed.test | ||
binlog_killed_simulate-master.opt | ||
binlog_killed_simulate.test | ||
binlog_max_extension.test | ||
binlog_mdev342-master.opt | ||
binlog_mdev342.test | ||
binlog_mdev717.test | ||
binlog_mixed_cache_stat.test | ||
binlog_mixed_load_data.test | ||
binlog_mysqlbinlog-cp932-master.opt | ||
binlog_mysqlbinlog-cp932.test | ||
binlog_mysqlbinlog2-master.opt | ||
binlog_mysqlbinlog2.test | ||
binlog_mysqlbinlog_base64.test | ||
binlog_mysqlbinlog_row-master.opt | ||
binlog_mysqlbinlog_row.test | ||
binlog_mysqlbinlog_row_innodb-master.opt | ||
binlog_mysqlbinlog_row_innodb.test | ||
binlog_mysqlbinlog_row_myisam-master.opt | ||
binlog_mysqlbinlog_row_myisam.test | ||
binlog_mysqlbinlog_row_trans-master.opt | ||
binlog_mysqlbinlog_row_trans.test | ||
binlog_old_versions.test | ||
binlog_query_filter_rules-master.opt | ||
binlog_query_filter_rules.test | ||
binlog_row_annotate-master.opt | ||
binlog_row_annotate.test | ||
binlog_row_binlog-master.opt | ||
binlog_row_binlog.test | ||
binlog_row_cache_stat.test | ||
binlog_row_ctype_cp932.test | ||
binlog_row_ctype_ucs.test | ||
binlog_row_drop_tbl.test | ||
binlog_row_drop_tmp_tbl.test | ||
binlog_row_innodb_stat-master.opt | ||
binlog_row_insert_select.test | ||
binlog_row_mix_innodb_myisam-master.opt | ||
binlog_row_mix_innodb_myisam.test | ||
binlog_row_mysqlbinlog_db_filter.test | ||
binlog_row_mysqlbinlog_options-master.opt | ||
binlog_row_mysqlbinlog_options.test | ||
binlog_row_mysqlbinlog_verbose.test | ||
binlog_server_id.test | ||
binlog_sf.test | ||
binlog_spurious_ddl_errors-master.opt | ||
binlog_spurious_ddl_errors.test | ||
binlog_sql_mode.test | ||
binlog_start_comment.test | ||
binlog_statement_insert_delayed.test | ||
binlog_stm_binlog-master.opt | ||
binlog_stm_binlog.test | ||
binlog_stm_blackhole.test | ||
binlog_stm_cache_stat.test | ||
binlog_stm_ctype_cp932.test | ||
binlog_stm_ctype_ucs.test | ||
binlog_stm_do_db-master.opt | ||
binlog_stm_do_db.test | ||
binlog_stm_drop_tbl.test | ||
binlog_stm_drop_tmp_tbl.test | ||
binlog_stm_innodb_stat-master.opt | ||
binlog_stm_insert_select.test | ||
binlog_stm_mix_innodb_myisam-master.opt | ||
binlog_stm_mix_innodb_myisam.test | ||
binlog_stm_ps.test | ||
binlog_stm_row.test | ||
binlog_stm_unsafe_warning-master.opt | ||
binlog_stm_unsafe_warning.test | ||
binlog_stm_user_variables.test | ||
binlog_switch_inside_trans.test | ||
binlog_tmp_table.test | ||
binlog_trigger.test | ||
binlog_truncate_innodb-master.opt | ||
binlog_truncate_innodb.test | ||
binlog_truncate_kill.test | ||
binlog_truncate_myisam.test | ||
binlog_unsafe-master.opt | ||
binlog_unsafe.test | ||
binlog_variables_log_bin-master.opt | ||
binlog_variables_log_bin.test | ||
binlog_variables_log_bin_index-master.opt | ||
binlog_variables_log_bin_index.test | ||
binlog_variables_relay_log-master.opt | ||
binlog_variables_relay_log.test | ||
binlog_variables_relay_log_index-master.opt | ||
binlog_variables_relay_log_index.test | ||
binlog_write_error.test | ||
binlog_xa_recover-master.opt | ||
binlog_xa_recover.test | ||
flashback-master.opt | ||
flashback.test | ||
load_data_stm_view.test | ||
temptable_uservar_disconnect-7938.test |