diff options
author | unknown <dkatz@damien-katzs-computer.local> | 2007-05-27 11:50:10 -0400 |
---|---|---|
committer | unknown <dkatz@damien-katzs-computer.local> | 2007-05-27 11:50:10 -0400 |
commit | e010e1c240af8688721305b4e2901f395256a876 (patch) | |
tree | 7799724b408a2e407997d161e235417579fcfbcd /client | |
parent | de108e05f9b7204ce572527765952c29b5fde289 (diff) | |
download | mariadb-git-e010e1c240af8688721305b4e2901f395256a876.tar.gz |
Bug #24733 RESET MASTER run before dump with --delete-master-logs
fixed by using flush logs, dumping, then doing PURGE MASTER LOGS TO 'binfile', instead
of deleting the log files at the beginning.
NOTE: previously the delete-master-logs would reset the log names back to
filename.00001. Now the trailing number doesn't get reset. This may need to be
documented.
client/mysqldump.c:
changed the code the --delete-master-logs option is used from this:
take locks
delete bin logs
do dump (if this is a lock-based dump)
release locks
do dump (if this is a consistent-read-dump)
to this:
take locks
flush logs
remember the name of the new log
do dump (if this is a lock-based dump)
release locks
do dump (if this is a consistent-read-dump)
fflush output sql file if specified, to ensure the backup is commited to disk
--- yes, dump succeeded ---
do PURGE MASTER LOGS TO up to the new log
Diffstat (limited to 'client')
-rw-r--r-- | client/mysqldump.c | 57 |
1 files changed, 53 insertions, 4 deletions
diff --git a/client/mysqldump.c b/client/mysqldump.c index f1e6a825257..b334e8d9a11 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -3268,10 +3268,41 @@ static int do_unlock_tables(MYSQL *mysql_con) return mysql_query_with_error_report(mysql_con, 0, "UNLOCK TABLES"); } +static int get_bin_log_name(MYSQL *mysql_con, + char* buff_log_name, uint buff_len) +{ + MYSQL_RES *res; + MYSQL_ROW row; + + if (mysql_query(mysql, "SHOW MASTER STATUS") || + !(res= mysql_store_result(mysql))) + return 1; + + if (!(row= mysql_fetch_row(res))) + { + mysql_free_result(res); + return 1; + } + /* + Only one row is returned, and the first column is the name of the + active log. + */ + strmake(buff_log_name, row[0], buff_len - 1); -static int do_reset_master(MYSQL *mysql_con) + mysql_free_result(res); + return 0; +} + +static int purge_bin_logs_to(MYSQL *mysql_con, char* log_name) { - return mysql_query_with_error_report(mysql_con, 0, "RESET MASTER"); + DYNAMIC_STRING str; + int err; + init_dynamic_string_checked(&str, "PURGE BINARY LOGS TO '", 1024, 1024); + dynstr_append_checked(&str, log_name); + dynstr_append_checked(&str, "'"); + err = mysql_query_with_error_report(mysql_con, 0, str.str); + dynstr_free(&str); + return err; } @@ -3795,6 +3826,7 @@ static void dynstr_realloc_checked(DYNAMIC_STRING *str, ulong additional_size) int main(int argc, char **argv) { + char bin_log_name[FN_REFLEN]; int exit_code; MY_INIT("mysqldump"); @@ -3831,8 +3863,13 @@ int main(int argc, char **argv) goto err; if (opt_single_transaction && start_transaction(mysql)) goto err; - if (opt_delete_master_logs && do_reset_master(mysql)) - goto err; + if (opt_delete_master_logs) + { + if (mysql_refresh(mysql, REFRESH_LOG) || + get_bin_log_name(mysql, bin_log_name, sizeof(bin_log_name))) + goto err; + flush_logs= 0; + } if (opt_lock_all_tables || opt_master_data) { if (flush_logs && mysql_refresh(mysql, REFRESH_LOG)) @@ -3856,6 +3893,18 @@ int main(int argc, char **argv) /* One or more databases, all tables */ dump_databases(argv); } + + /* ensure dumped data flushed */ + if (md_result_file && fflush(md_result_file)) + { + if (!first_error) + first_error= EX_MYSQLERR; + goto err; + } + /* everything successful, purge the old logs files */ + if (opt_delete_master_logs && purge_bin_logs_to(mysql, bin_log_name)) + goto err; + #ifdef HAVE_SMEM my_free(shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR)); #endif |