84
84
opt_lock_all_tables= false,
85
85
opt_set_charset= false, opt_dump_date= true,
86
86
opt_autocommit= false, opt_disable_keys= true, opt_xml= false,
87
opt_delete_master_logs= false, tty_password= false,
88
88
opt_single_transaction= false, opt_comments= false,
89
89
opt_compact= false, opt_hex_blob= false,
90
90
opt_order_by_primary=false, opt_ignore= false,
91
91
opt_complete_insert= false, opt_drop_database= false,
92
92
opt_replace_into= false,
93
93
opt_routines= false,
94
opt_slave_apply= false,
95
opt_include_master_host_port= false,
96
94
opt_alltspcs= false;
97
95
static bool debug_info_flag= false, debug_check_flag= false;
98
96
static uint32_t show_progress_size= 0;
176
168
{"allow-keywords", OPT_KEYWORDS,
177
169
"Allow creation of column names that are keywords.", (char**) &opt_keywords,
178
170
(char**) &opt_keywords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
179
{"apply-slave-statements", OPT_DRIZZLEDUMP_SLAVE_APPLY,
180
"Adds 'STOP SLAVE' prior to 'CHANGE MASTER' and 'START SLAVE' to bottom of dump.",
181
(char**) &opt_slave_apply, (char**) &opt_slave_apply, 0, GET_BOOL, NO_ARG,
183
171
{"comments", 'i', "Write additional information.",
184
172
(char**) &opt_comments, (char**) &opt_comments, 0, GET_BOOL, NO_ARG,
185
173
1, 0, 0, 0, 0, 0},
217
205
{"delayed-insert", OPT_DELAYED, "Insert rows with INSERT DELAYED; ",
218
206
(char**) &opt_delayed, (char**) &opt_delayed, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
220
{"delete-master-logs", OPT_DELETE_MASTER_LOGS,
221
"Delete logs on master after backup. This automatically enables --master-data.",
222
(char**) &opt_delete_master_logs, (char**) &opt_delete_master_logs, 0,
223
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
224
208
{"disable-keys", 'K',
225
209
"'ALTER TABLE tb_name DISABLE KEYS; and 'ALTER TABLE tb_name ENABLE KEYS; will be put in the output.", (char**) &opt_disable_keys,
226
210
(char**) &opt_disable_keys, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
227
{"dump-slave", OPT_DRIZZLEDUMP_SLAVE_DATA,
228
"This causes the binary log position and filename of the master to be "
229
"appended to the dumped data output. Setting the value to 1, will print"
230
"it as a CHANGE MASTER command in the dumped data output; if equal"
231
" to 2, that command will be prefixed with a comment symbol. "
232
"This option will turn --lock-all-tables on, unless "
233
"--single-transaction is specified too (in which case a "
234
"global read lock is only taken a short time at the beginning of the dump "
235
"- don't forget to read about --single-transaction below). In all cases "
236
"any action on logs will happen at the exact moment of the dump."
237
"Option automatically turns --lock-tables off.",
238
(char**) &opt_slave_data, (char**) &opt_slave_data, 0,
239
GET_UINT, OPT_ARG, 0, 0, DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL, 0, 0, 0},
240
211
{"extended-insert", 'e',
241
212
"Allows utilization of the new, much faster INSERT syntax.",
242
213
(char**) &extended_insert, (char**) &extended_insert, 0, GET_BOOL, NO_ARG,
252
223
(char**) &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
253
224
{"fields-escaped-by", OPT_ESC, "Fields in the i.file are escaped by ...",
254
225
(char**) &escaped, (char**) &escaped, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
255
{"first-slave", 'x', "Deprecated, renamed to --lock-all-tables.",
256
(char**) &opt_lock_all_tables, (char**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
258
226
{"flush-logs", 'F', "Flush logs file in server before starting dump. "
259
227
"Note that if you dump many databases at once (using the option "
260
228
"--databases= or --all-databases), the logs will be flushed for "
261
229
"each database dumped. The exception is when using --lock-all-tables "
263
230
"in this case the logs will be flushed only once, corresponding "
264
231
"to the moment all tables are locked. So if you want your dump and "
265
232
"the log flush to happen at the same exact moment you should use "
266
"--lock-all-tables or --master-data with --flush-logs",
233
"--lock-all-tables or --flush-logs",
267
234
(char**) &flush_logs, (char**) &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
269
236
{"force", 'f', "Continue even if we get an sql-error.",
281
248
"use the directive multiple times, once for each table. Each table must "
282
249
"be specified with both database and table names, e.g. --ignore-table=database.table",
283
250
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
284
{"include-master-host-port", OPT_DRIZZLEDUMP_INCLUDE_MASTER_HOST_PORT,
285
"Adds 'MASTER_HOST=<host>, MASTER_PORT=<port>' to 'CHANGE MASTER TO..' in dump produced with --dump-slave.",
286
(char**) &opt_include_master_host_port,
287
(char**) &opt_include_master_host_port,
290
251
{"insert-ignore", OPT_INSERT_IGNORE, "Insert rows with INSERT IGNORE.",
291
252
(char**) &opt_ignore, (char**) &opt_ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
298
259
"dump. Automatically turns --single-transaction and --lock-tables off.",
299
260
(char**) &opt_lock_all_tables, (char**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
300
261
0, 0, 0, 0, 0, 0},
301
{"master-data", OPT_MASTER_DATA,
302
"This causes the binary log position and filename to be appended to the "
303
"output. If equal to 1, will print it as a CHANGE MASTER command; if equal"
304
" to 2, that command will be prefixed with a comment symbol. "
305
"This option will turn --lock-all-tables on, unless "
306
"--single-transaction is specified too (in which case a "
307
"global read lock is only taken a short time at the beginning of the dump "
308
"- don't forget to read about --single-transaction below). In all cases "
309
"any action on logs will happen at the exact moment of the dump."
310
"Option automatically turns --lock-tables off.",
311
(char**) &opt_master_data, (char**) &opt_master_data, 0,
312
GET_UINT, OPT_ARG, 0, 0, DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL, 0, 0, 0},
313
262
{"no-autocommit", OPT_AUTOCOMMIT,
314
263
"Wrap tables with autocommit/commit statements.",
315
264
(char**) &opt_autocommit, (char**) &opt_autocommit, 0, GET_BOOL, NO_ARG,
351
300
{"routines", 'R', "Dump stored routines (functions and procedures).",
352
301
(char**) &opt_routines, (char**) &opt_routines, 0, GET_BOOL,
353
302
NO_ARG, 0, 0, 0, 0, 0, 0},
355
Note that the combination --single-transaction --master-data
356
will give bullet-proof binlog position only if server >=4.1.3. That's the
357
old "FLUSH TABLES WITH READ LOCK does not block commit" fixed bug.
359
303
{"single-transaction", OPT_TRANSACTION,
360
304
"Creates a consistent snapshot by dumping all tables in a single "
361
305
"transaction. Works ONLY for tables stored in storage engines which "
362
306
"support multiversioning (currently only InnoDB does); the dump is NOT "
363
307
"guaranteed to be consistent for other storage engines. "
364
308
"While a --single-transaction dump is in process, to ensure a valid "
365
"dump file (correct table contents and binary log position), no other "
309
"dump file (correct table contents), no other "
366
310
"connection should use the following statements: ALTER TABLE, DROP "
367
311
"TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not "
368
312
"isolated from them. Option automatically turns off --lock-tables.",
2624
2544
} /* dump_selected_tables */
2627
static int do_show_master_status(drizzle_con_st *drizzle_con)
2630
drizzle_result_st master;
2631
const char *comment_prefix=
2632
(opt_master_data == DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL) ? "-- " : "";
2633
if (drizzleclient_query_with_error_report(drizzle_con, &master, "SHOW MASTER STATUS", false))
2639
row= drizzle_row_next(&master);
2640
if (row && row[0] && row[1])
2642
/* SHOW MASTER STATUS reports file and position */
2644
fprintf(md_result_file,
2645
"\n--\n-- Position to start replication or point-in-time "
2646
"recovery from\n--\n\n");
2647
fprintf(md_result_file,
2648
"%sCHANGE MASTER TO MASTER_LOG_FILE='%s', MASTER_LOG_POS=%s;\n",
2649
comment_prefix, row[0], row[1]);
2650
check_io(md_result_file);
2652
else if (!ignore_errors)
2654
/* SHOW MASTER STATUS reports nothing and --force is not enabled */
2655
my_printf_error(0, _("Error: Binlogging on server not active"),
2657
drizzle_result_free(&master);
2658
maybe_exit(EX_DRIZZLEERR);
2661
drizzle_result_free(&master);
2666
static int do_stop_slave_sql(drizzle_con_st *drizzle_con)
2668
drizzle_result_st slave;
2669
/* We need to check if the slave sql is running in the first place */
2670
if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS", false))
2674
drizzle_row_t row= drizzle_row_next(&slave);
2677
/* if SLAVE SQL is not running, we don't stop it */
2678
if (!strcmp(row[11],"No"))
2680
drizzle_result_free(&slave);
2681
/* Silently assume that they don't have the slave running */
2686
drizzle_result_free(&slave);
2688
/* now, stop slave if running */
2689
if (drizzleclient_query_with_error_report(drizzle_con, &slave, "STOP SLAVE SQL_THREAD", false))
2691
drizzle_result_free(&slave);
2696
static int add_stop_slave(void)
2699
fprintf(md_result_file,
2700
"\n--\n-- stop slave statement to make a recovery dump)\n--\n\n");
2701
fprintf(md_result_file, "STOP SLAVE;\n");
2705
static int add_slave_statements(void)
2708
fprintf(md_result_file,
2709
"\n--\n-- start slave statement to make a recovery dump)\n--\n\n");
2710
fprintf(md_result_file, "START SLAVE;\n");
2714
static int do_show_slave_status(drizzle_con_st *drizzle_con)
2716
drizzle_result_st slave;
2717
const char *comment_prefix=
2718
(opt_slave_data == DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL) ? "-- " : "";
2719
if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS", false))
2723
/* SHOW SLAVE STATUS reports nothing and --force is not enabled */
2724
my_printf_error(0, _("Error: Slave not set up"), MYF(0));
2730
drizzle_row_t row= drizzle_row_next(&slave);
2731
if (row && row[9] && row[21])
2733
/* SHOW MASTER STATUS reports file and position */
2735
fprintf(md_result_file,
2736
"\n--\n-- Position to start replication or point-in-time "
2737
"recovery from (the master of this slave)\n--\n\n");
2739
fprintf(md_result_file, "%sCHANGE MASTER TO ", comment_prefix);
2741
if (opt_include_master_host_port)
2744
fprintf(md_result_file, "MASTER_HOST='%s', ", row[1]);
2746
fprintf(md_result_file, "MASTER_PORT='%s', ", row[3]);
2748
fprintf(md_result_file,
2749
"MASTER_LOG_FILE='%s', MASTER_LOG_POS=%s;\n", row[9], row[21]);
2751
check_io(md_result_file);
2753
drizzle_result_free(&slave);
2758
static int do_start_slave_sql(drizzle_con_st *drizzle_con)
2760
drizzle_result_st slave;
2761
/* We need to check if the slave sql is stopped in the first place */
2762
if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS", false))
2766
drizzle_row_t row= drizzle_row_next(&slave);
2769
/* if SLAVE SQL is not running, we don't start it */
2770
if (!strcmp(row[11],"Yes"))
2772
drizzle_result_free(&slave);
2773
/* Silently assume that they don't have the slave running */
2777
drizzle_result_free(&slave);
2780
/* now, start slave if stopped */
2781
if (drizzleclient_query_with_error_report(drizzle_con, &slave, "START SLAVE", false))
2783
my_printf_error(0, _("Error: Unable to start slave"), MYF(0));
2786
drizzle_result_free(&slave);
2792
2546
static int do_flush_tables_read_lock(drizzle_con_st *drizzle_con)
2805
2559
"FLUSH TABLES WITH READ LOCK", false) );
2809
2562
static int do_unlock_tables(drizzle_con_st *drizzle_con)
2811
2564
return drizzleclient_query_with_error_report(drizzle_con, 0, "UNLOCK TABLES", false);
2814
static int get_bin_log_name(drizzle_con_st *drizzle_con,
2815
char* buff_log_name, uint32_t buff_len)
2817
drizzle_result_st res;
2820
if (drizzleclient_query_with_error_report(drizzle_con, &res, "SHOW MASTER STATUS", false))
2823
if (!(row= drizzle_row_next(&res)))
2825
drizzle_result_free(&res);
2829
Only one row is returned, and the first column is the name of the
2832
strncpy(buff_log_name, row[0], buff_len - 1);
2834
drizzle_result_free(&res);
2838
static int purge_bin_logs_to(drizzle_con_st *drizzle_con, char* log_name)
2841
string str= "PURGE BINARY LOGS TO '";
2842
str.append(log_name);
2844
drizzle_result_st res;
2845
err= drizzleclient_query_with_error_report(drizzle_con, &res, str.c_str(),
2849
drizzle_result_free(&res);
2854
2567
static int start_transaction(drizzle_con_st *drizzle_con)
2856
2569
return (drizzleclient_query_with_error_report(drizzle_con, 0,
3165
2877
write_header(md_result_file, *argv);
3167
if (opt_slave_data && do_stop_slave_sql(&dcon))
3170
if ((opt_lock_all_tables || opt_master_data) &&
3171
do_flush_tables_read_lock(&dcon))
2879
if ((opt_lock_all_tables) && do_flush_tables_read_lock(&dcon))
3173
2881
if (opt_single_transaction && start_transaction(&dcon))
3175
if (opt_delete_master_logs)
3177
if (drizzleclient_query_with_error_report(&dcon, &result, "FLUSH LOGS", false))
3179
drizzle_result_free(&result);
3180
if (get_bin_log_name(&dcon, bin_log_name, sizeof(bin_log_name)))
3184
if (opt_lock_all_tables || opt_master_data)
2883
if (opt_lock_all_tables)
3186
2885
if (drizzleclient_query_with_error_report(&dcon, &result, "FLUSH LOGS", false))
3188
2887
drizzle_result_free(&result);
3189
2888
flush_logs= 0; /* not anymore; that would not be sensible */
3191
/* Add 'STOP SLAVE to beginning of dump */
3192
if (opt_slave_apply && add_stop_slave())
3194
if (opt_master_data && do_show_master_status(&dcon))
3196
if (opt_slave_data && do_show_slave_status(&dcon))
3198
2890
if (opt_single_transaction && do_unlock_tables(&dcon)) /* unlock but no commit! */