155
158
unordered_set<string> ignore_table;
157
static struct option my_long_options[] =
159
{"all", 'a', "Deprecated. Use --create-options instead.",
160
(char**) &create_options, (char**) &create_options, 0, GET_BOOL, NO_ARG, 1,
162
{"all-databases", 'A',
163
"Dump all the databases. This will be same as --databases with all databases selected.",
164
(char**) &opt_alldbs, (char**) &opt_alldbs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
166
{"all-tablespaces", 'Y',
167
"Dump all the tablespaces.",
168
(char**) &opt_alltspcs, (char**) &opt_alltspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
170
{"add-drop-database", OPT_DROP_DATABASE, "Add a 'DROP DATABASE' before each create.",
171
(char**) &opt_drop_database, (char**) &opt_drop_database, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
173
{"add-drop-table", OPT_DROP, "Add a 'drop table' before each create.",
174
(char**) &opt_drop, (char**) &opt_drop, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
176
{"allow-keywords", OPT_KEYWORDS,
177
"Allow creation of column names that are keywords.", (char**) &opt_keywords,
178
(char**) &opt_keywords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
179
{"comments", 'i', "Write additional information.",
180
(char**) &opt_comments, (char**) &opt_comments, 0, GET_BOOL, NO_ARG,
182
{"compatible", OPT_COMPATIBLE,
183
"Change the dump to be compatible with a given mode. By default tables are dumped in a format optimized for MySQL. Legal modes are: ansi, mysql323, mysql40, postgresql, oracle, mssql, db2, maxdb, no_key_options, no_table_options, no_field_options. One can use several modes separated by commas. Note: Requires DRIZZLE server version 4.1.0 or higher. This option is ignored with earlier server versions.",
184
(char**) &opt_compatible_mode_str, (char**) &opt_compatible_mode_str, 0,
185
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
186
{"compact", OPT_COMPACT,
187
"Give less verbose output (useful for debugging). Disables structure comments and header/footer constructs. Enables options --skip-add-drop-table --no-set-names --skip-disable-keys --skip-add-locks",
188
(char**) &opt_compact, (char**) &opt_compact, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
190
{"complete-insert", 'c', "Use complete insert statements.",
191
(char**) &opt_complete_insert, (char**) &opt_complete_insert, 0, GET_BOOL,
192
NO_ARG, 0, 0, 0, 0, 0, 0},
193
{"compress", 'C', "Use compression in server/client protocol.",
194
(char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
196
{"create-options", OPT_CREATE_OPTIONS,
197
"Include all DRIZZLE specific create options.",
198
(char**) &create_options, (char**) &create_options, 0, GET_BOOL, NO_ARG, 1,
201
"To dump several databases. Note the difference in usage; In this case no tables are given. All name arguments are regarded as databasenames. 'USE db_name;' will be included in the output.",
202
(char**) &opt_databases, (char**) &opt_databases, 0, GET_BOOL, NO_ARG, 0, 0,
204
{"delayed-insert", OPT_DELAYED, "Insert rows with INSERT DELAYED; ",
205
(char**) &opt_delayed, (char**) &opt_delayed, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
207
{"disable-keys", 'K',
208
"'ALTER TABLE tb_name DISABLE KEYS; and 'ALTER TABLE tb_name ENABLE KEYS; will be put in the output.", (char**) &opt_disable_keys,
209
(char**) &opt_disable_keys, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
210
{"extended-insert", 'e',
211
"Allows utilization of the new, much faster INSERT syntax.",
212
(char**) &extended_insert, (char**) &extended_insert, 0, GET_BOOL, NO_ARG,
214
{"fields-terminated-by", OPT_FTB,
215
"Fields in the textfile are terminated by ...", (char**) &fields_terminated,
216
(char**) &fields_terminated, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
217
{"fields-enclosed-by", OPT_ENC,
218
"Fields in the importfile are enclosed by ...", (char**) &enclosed,
219
(char**) &enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
220
{"fields-optionally-enclosed-by", OPT_O_ENC,
221
"Fields in the i.file are opt. enclosed by ...", (char**) &opt_enclosed,
222
(char**) &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
223
{"fields-escaped-by", OPT_ESC, "Fields in the i.file are escaped by ...",
224
(char**) &escaped, (char**) &escaped, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
225
{"flush-logs", 'F', "Flush logs file in server before starting dump. "
226
"Note that if you dump many databases at once (using the option "
227
"--databases= or --all-databases), the logs will be flushed for "
228
"each database dumped. The exception is when using --lock-all-tables "
229
"in this case the logs will be flushed only once, corresponding "
230
"to the moment all tables are locked. So if you want your dump and "
231
"the log flush to happen at the same exact moment you should use "
232
"--lock-all-tables or --flush-logs",
233
(char**) &flush_logs, (char**) &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
235
{"force", 'f', "Continue even if we get an sql-error.",
236
(char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG,
238
{"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG,
239
NO_ARG, 0, 0, 0, 0, 0, 0},
240
{"hex-blob", OPT_HEXBLOB, "Dump binary strings (BINARY, "
241
"VARBINARY, BLOB) in hexadecimal format.",
242
(char**) &opt_hex_blob, (char**) &opt_hex_blob, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
243
{"host", 'h', "Connect to host.", (char**) ¤t_host,
244
(char**) ¤t_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
245
{"ignore-table", OPT_IGNORE_TABLE,
246
"Do not dump the specified table. To specify more than one table to ignore, "
247
"use the directive multiple times, once for each table. Each table must "
248
"be specified with both database and table names, e.g. --ignore-table=database.table",
249
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
250
{"insert-ignore", OPT_INSERT_IGNORE, "Insert rows with INSERT IGNORE.",
251
(char**) &opt_ignore, (char**) &opt_ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
253
{"lines-terminated-by", OPT_LTB, "Lines in the i.file are terminated by ...",
254
(char**) &lines_terminated, (char**) &lines_terminated, 0, GET_STR,
255
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
256
{"lock-all-tables", 'x', "Locks all tables across all databases. This "
257
"is achieved by taking a global read lock for the duration of the whole "
258
"dump. Automatically turns --single-transaction and --lock-tables off.",
259
(char**) &opt_lock_all_tables, (char**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
261
{"mysql", 'm', N_("Use MySQL Protocol."),
262
(char**) &opt_mysql, (char**) &opt_mysql, 0, GET_BOOL, NO_ARG, 1, 0, 0,
264
{"no-autocommit", OPT_AUTOCOMMIT,
265
"Wrap tables with autocommit/commit statements.",
266
(char**) &opt_autocommit, (char**) &opt_autocommit, 0, GET_BOOL, NO_ARG,
268
{"no-create-db", 'n',
269
"'CREATE DATABASE IF NOT EXISTS db_name;' will not be put in the output. The above line will be added otherwise, if --databases or --all-databases option was given.}.",
270
(char**) &opt_create_db, (char**) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0,
272
{"no-create-info", 't', "Don't write table creation info.",
273
(char**) &opt_no_create_info, (char**) &opt_no_create_info, 0, GET_BOOL,
274
NO_ARG, 0, 0, 0, 0, 0, 0},
275
{"no-data", 'd', "No row information.", (char**) &opt_no_data,
276
(char**) &opt_no_data, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
277
{"no-set-names", 'N',
278
"Deprecated. Use --skip-set-charset instead.",
279
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
280
{"opt", OPT_OPTIMIZE,
281
"Same as --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys. Enabled by default, disable with --skip-opt.",
282
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
283
{"order-by-primary", OPT_ORDER_BY_PRIMARY,
284
"Sorts each table's rows by primary key, or first unique key, if such a key exists. Useful when dumping a MyISAM table to be loaded into an InnoDB table, but will make the dump itself take considerably longer.",
285
(char**) &opt_order_by_primary, (char**) &opt_order_by_primary, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
287
"Password to use when connecting to server. If password is not given it's solicited on the tty.",
288
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
289
{"port", 'p', "Port number to use for connection.",
290
0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
291
{"quick", 'q', "Don't buffer query, dump directly to stdout.",
292
(char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
293
{"quote-names",'Q', "Quote table and column names with backticks (`).",
294
(char**) &opt_quoted, (char**) &opt_quoted, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
296
{"replace", OPT_DRIZZLE_REPLACE_INTO, "Use REPLACE INTO instead of INSERT INTO.",
297
(char**) &opt_replace_into, (char**) &opt_replace_into, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
300
"Direct output to a given file. This option should be used in MSDOS, because it prevents new line '\\n' from being converted to '\\r\\n' (carriage return + line feed).",
301
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
302
{"routines", 'R', "Dump stored routines (functions and procedures).",
303
(char**) &opt_routines, (char**) &opt_routines, 0, GET_BOOL,
304
NO_ARG, 0, 0, 0, 0, 0, 0},
305
{"single-transaction", OPT_TRANSACTION,
306
"Creates a consistent snapshot by dumping all tables in a single "
307
"transaction. Works ONLY for tables stored in storage engines which "
308
"support multiversioning (currently only InnoDB does); the dump is NOT "
309
"guaranteed to be consistent for other storage engines. "
310
"While a --single-transaction dump is in process, to ensure a valid "
311
"dump file (correct table contents), no other "
312
"connection should use the following statements: ALTER TABLE, DROP "
313
"TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not "
314
"isolated from them. Option automatically turns off --lock-tables.",
315
(char**) &opt_single_transaction, (char**) &opt_single_transaction, 0,
316
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
317
{"dump-date", OPT_DUMP_DATE, "Put a dump date to the end of the output.",
318
(char**) &opt_dump_date, (char**) &opt_dump_date, 0,
319
GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
320
{"skip-opt", OPT_SKIP_OPTIMIZATION,
321
"Disable --opt. Disables --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys.",
322
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
324
"Creates tab separated textfile for each table to given path. (creates .sql and .txt files). NOTE: This only works if drizzledump is run on the same machine as the drizzled daemon.",
325
(char**) &path, (char**) &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
326
{"tables", OPT_TABLES, "Overrides option --databases (-B).",
327
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
328
{"show-progress-size", OPT_SHOW_PROGRESS_SIZE, N_("Number of rows before each output progress report (requires --verbose)."),
329
(char**) &show_progress_size, (char**) &show_progress_size, 0, GET_UINT32, REQUIRED_ARG,
330
10000, 0, 0, 0, 0, 0},
331
{"user", 'u', "User for login if not current user.",
332
(char**) ¤t_user, (char**) ¤t_user, 0, GET_STR, REQUIRED_ARG,
334
{"verbose", 'v', "Print info about the various stages.",
335
(char**) &verbose, (char**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
336
{"version",'V', "Output version information and exit.", 0, 0, 0,
337
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
338
{"where", 'w', "Dump only selected records; QUOTES mandatory!",
339
(char**) &where, (char**) &where, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
340
{"xml", 'X', "Dump a database as well formed XML.", 0, 0, 0, GET_NO_ARG,
341
NO_ARG, 0, 0, 0, 0, 0, 0},
342
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
345
static const char *load_default_groups[]= { "drizzledump","client",0 };
347
160
static void maybe_exit(int error);
348
161
static void die(int error, const char* reason, ...);
349
162
static void maybe_die(int error, const char* reason, ...);
2834
2444
int main(int argc, char **argv)
2837
2449
MY_INIT("drizzledump");
2838
2450
drizzle_result_st result;
2452
po::options_description commandline_options("Options used only in command line");
2453
commandline_options.add_options()
2454
("all-databases,A", po::value<bool>(&opt_alldbs)->default_value(false)->zero_tokens(),
2455
"Dump all the databases. This will be same as --databases with all databases selected.")
2456
("all-tablespaces,Y", po::value<bool>(&opt_alltspcs)->default_value(false)->zero_tokens(),
2457
"Dump all the tablespaces.")
2458
("complete-insert,c", po::value<bool>(&opt_complete_insert)->default_value(false)->zero_tokens(),
2459
"Use complete insert statements.")
2460
("compress,C", po::value<bool>(&opt_compress)->default_value(false)->zero_tokens(),
2461
"Use compression in server/client protocol.")
2462
("flush-logs,F", po::value<bool>(&flush_logs)->default_value(false)->zero_tokens(),
2463
"Flush logs file in server before starting dump. Note that if you dump many databases at once (using the option --databases= or --all-databases), the logs will be flushed for each database dumped. The exception is when using --lock-all-tables in this case the logs will be flushed only once, corresponding to the moment all tables are locked. So if you want your dump and the log flush to happen at the same exact moment you should use --lock-all-tables or --flush-logs")
2464
("force,f", po::value<bool>(&ignore_errors)->default_value(false)->zero_tokens(),
2465
"Continue even if we get an sql-error.")
2466
("help,?", "Display this help message and exit.")
2467
("lock-all-tables,x", po::value<bool>(&opt_lock_all_tables)->default_value(false)->zero_tokens(),
2468
"Locks all tables across all databases. This is achieved by taking a global read lock for the duration of the whole dump. Automatically turns --single-transaction and --lock-tables off.")
2469
("order-by-primary", po::value<bool>(&opt_order_by_primary)->default_value(false)->zero_tokens(),
2470
"Sorts each table's rows by primary key, or first unique key, if such a key exists. Useful when dumping a MyISAM table to be loaded into an InnoDB table, but will make the dump itself take considerably longer.")
2471
("routines,R", po::value<bool>(&opt_routines)->default_value(false)->zero_tokens(),
2472
"Dump stored routines (functions and procedures).")
2473
("single-transaction", po::value<bool>(&opt_single_transaction)->default_value(false)->zero_tokens(),
2474
"Creates a consistent snapshot by dumping all tables in a single transaction. Works ONLY for tables stored in storage engines which support multiversioning (currently only InnoDB does); the dump is NOT guaranteed to be consistent for other storage engines. While a --single-transaction dump is in process, to ensure a valid dump file (correct table contents), no other connection should use the following statements: ALTER TABLE, DROP TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not isolated from them. Option automatically turns off --lock-tables.")
2475
("opt", "Same as --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys. Enabled by default, disable with --skip-opt.")
2477
"Disable --opt. Disables --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys.")
2478
("tables", "Overrides option --databases (-B).")
2479
("show-progress-size", po::value<uint32_t>(&show_progress_size)->default_value(10000),
2480
N_("Number of rows before each output progress report (requires --verbose)."))
2481
("verbose,v", po::value<bool>(&verbose)->default_value(false)->zero_tokens(),
2482
"Print info about the various stages.")
2483
("version,V", "Output version information and exit.")
2484
("xml,X", "Dump a database as well formed XML.")
2485
("skip-comments", "Turn off Comments")
2486
("skip-create", "Turn off create-options")
2487
("skip-extended-insert", "Turn off extended-insert")
2488
("skip-dump-date", "Turn off dump-date")
2489
("no-defaults", "Do not read from the configuration files")
2492
po::options_description dump_options("Options specific to the drizzle client");
2493
dump_options.add_options()
2494
("add-drop-database", po::value<bool>(&opt_drop_database)->default_value(false)->zero_tokens(),
2495
"Add a 'DROP DATABASE' before each create.")
2496
("add-drop-table", po::value<bool>(&opt_drop)->default_value(true)->zero_tokens(),
2497
"Add a 'drop table' before each create.")
2498
("allow-keywords", po::value<bool>(&opt_keywords)->default_value(false)->zero_tokens(),
2499
"Allow creation of column names that are keywords.")
2500
("comments,i", po::value<bool>(&opt_comments)->default_value(true)->zero_tokens(),
2501
"Write additional information.")
2502
("compatible", po::value<string>(&opt_compatible_mode_str)->default_value(""),
2503
"Change the dump to be compatible with a given mode. By default tables are dumped in a format optimized for MySQL. Legal modes are: ansi, mysql323, mysql40, postgresql, oracle, mssql, db2, maxdb, no_key_options, no_table_options, no_field_options. One can use several modes separated by commas. Note: Requires DRIZZLE server version 4.1.0 or higher. This option is ignored with earlier server versions.")
2504
("compact", po::value<bool>(&opt_compact)->default_value(false)->zero_tokens(),
2505
"Give less verbose output (useful for debugging). Disables structure comments and header/footer constructs. Enables options --skip-add-drop-table --no-set-names --skip-disable-keys --skip-add-locks")
2506
("create-options", po::value<bool>(&create_options)->default_value(true)->zero_tokens(),
2507
"Include all DRIZZLE specific create options.")
2508
("dump-date", po::value<bool>(&opt_dump_date)->default_value(true)->zero_tokens(),
2509
"Put a dump date to the end of the output.")
2510
("databases,B", po::value<bool>(&opt_databases)->default_value(false)->zero_tokens(),
2511
"To dump several databases. Note the difference in usage; In this case no tables are given. All name arguments are regarded as databasenames. 'USE db_name;' will be included in the output.")
2512
("delayed-insert", po::value<bool>(&opt_delayed)->default_value(false)->zero_tokens(),
2513
"Insert rows with INSERT DELAYED; ")
2514
("disable-keys,K", po::value<bool>(&opt_disable_keys)->default_value(true)->zero_tokens(),
2515
"'ALTER TABLE tb_name DISABLE KEYS; and 'ALTER TABLE tb_name ENABLE KEYS; will be put in the output.")
2516
("extended-insert,e", po::value<bool>(&extended_insert)->default_value(true)->zero_tokens(),
2517
"Allows utilization of the new, much faster INSERT syntax.")
2518
("fields-terminated-by", po::value<string>(&fields_terminated)->default_value(""),
2519
"Fields in the textfile are terminated by ...")
2520
("fields-enclosed-by", po::value<string>(&enclosed)->default_value(""),
2521
"Fields in the importfile are enclosed by ...")
2522
("fields-optionally-enclosed-by", po::value<string>(&opt_enclosed)->default_value(""),
2523
"Fields in the i.file are opt. enclosed by ...")
2524
("fields-escaped-by", po::value<string>(&escaped)->default_value(""),
2525
"Fields in the i.file are escaped by ...")
2526
("hex-blob", po::value<bool>(&opt_hex_blob)->default_value(false)->zero_tokens(),
2527
"Dump binary strings (BINARY, VARBINARY, BLOB) in hexadecimal format.")
2528
("ignore-table", po::value<string>(),
2529
"Do not dump the specified table. To specify more than one table to ignore, use the directive multiple times, once for each table. Each table must be specified with both database and table names, e.g. --ignore-table=database.table")
2530
("insert-ignore", po::value<bool>(&opt_ignore)->default_value(false)->zero_tokens(),
2531
"Insert rows with INSERT IGNORE.")
2532
("lines-terminated-by", po::value<string>(&lines_terminated)->default_value(""),
2533
"Lines in the i.file are terminated by ...")
2534
("no-autocommit", po::value<bool>(&opt_autocommit)->default_value(false)->zero_tokens(),
2535
"Wrap tables with autocommit/commit statements.")
2536
("no-create-db,n", po::value<bool>(&opt_create_db)->default_value(false)->zero_tokens(),
2537
"'CREATE DATABASE IF NOT EXISTS db_name;' will not be put in the output. The above line will be added otherwise, if --databases or --all-databases option was given.}.")
2538
("no-create-info,t", po::value<bool>(&opt_no_create_info)->default_value(false)->zero_tokens(),
2539
"Don't write table creation info.")
2540
("no-data,d", po::value<bool>(&opt_no_data)->default_value(false)->zero_tokens(),
2541
"No row information.")
2542
("no-set-names,N", "Deprecated. Use --skip-set-charset instead.")
2543
("set-charset", po::value<bool>(&opt_set_charset)->default_value(false)->zero_tokens(),
2545
("quick,q", po::value<bool>(&quick)->default_value(true)->zero_tokens(),
2546
"Don't buffer query, dump directly to stdout.")
2547
("quote-names,Q", po::value<bool>(&opt_quoted)->default_value(true)->zero_tokens(),
2548
"Quote table and column names with backticks (`).")
2549
("replace", po::value<bool>(&opt_replace_into)->default_value(false)->zero_tokens(),
2550
"Use REPLACE INTO instead of INSERT INTO.")
2551
("result-file,r", po::value<string>(),
2552
"Direct output to a given file. This option should be used in MSDOS, because it prevents new line '\\n' from being converted to '\\r\\n' (carriage return + line feed).")
2553
("tab,T", po::value<string>(&path)->default_value(""),
2554
"Creates tab separated textfile for each table to given path. (creates .sql and .txt files). NOTE: This only works if drizzledump is run on the same machine as the drizzled daemon.")
2555
("where,w", po::value<string>(&where)->default_value(""),
2556
"Dump only selected records; QUOTES mandatory!")
2559
po::options_description client_options("Options specific to the client");
2560
client_options.add_options()
2561
("host,h", po::value<string>(¤t_host)->default_value("localhost"),
2563
("mysql,m", po::value<bool>(&opt_mysql)->default_value(true)->zero_tokens(),
2564
N_("Use MySQL Protocol."))
2565
("password,P", po::value<string>(&password)->default_value(PASSWORD_SENTINEL),
2566
"Password to use when connecting to server. If password is not given it's solicited on the tty.")
2567
("port,p", po::value<uint32_t>(&opt_drizzle_port)->default_value(0),
2568
"Port number to use for connection.")
2569
("user,u", po::value<string>(¤t_user)->default_value(""),
2570
"User for login if not current user.")
2571
("protocol",po::value<string>(),
2572
"The protocol of connection (tcp,socket,pipe,memory).")
2575
po::options_description hidden_options("Hidden Options");
2576
hidden_options.add_options()
2577
("database-used", po::value<vector<string> >(), "Used to select the database")
2578
("Table-used", po::value<vector<string> >(), "Used to select the tables")
2581
po::options_description all_options("Allowed Options + Hidden Options");
2582
all_options.add(commandline_options).add(dump_options).add(client_options).add(hidden_options);
2584
po::options_description long_options("Allowed Options");
2585
long_options.add(commandline_options).add(dump_options).add(client_options);
2587
std::string system_config_dir_dump(SYSCONFDIR);
2588
system_config_dir_dump.append("/drizzle/drizzledump.cnf");
2590
std::string system_config_dir_client(SYSCONFDIR);
2591
system_config_dir_client.append("/drizzle/client.cnf");
2593
po::positional_options_description p;
2594
p.add("database-used", 1);
2595
p.add("Table-used",-1);
2840
2597
compatible_mode_normal_str[0]= 0;
2842
exit_code= get_options(&argc, &argv);
2599
md_result_file= stdout;
2601
po::variables_map vm;
2603
po::store(po::command_line_parser(argc, argv).options(all_options).
2604
positional(p).extra_parser(parse_password_arg).run(), vm);
2606
if (! vm.count("no-defaults"))
2608
ifstream user_dump_ifs("~/.drizzle/drizzledump.cnf");
2609
po::store(parse_config_file(user_dump_ifs, dump_options), vm);
2611
ifstream system_dump_ifs(system_config_dir_dump.c_str());
2612
store(parse_config_file(system_dump_ifs, dump_options), vm);
2614
ifstream user_client_ifs("~/.drizzle/client.cnf");
2615
po::store(parse_config_file(user_client_ifs, client_options), vm);
2617
ifstream system_client_ifs(system_config_dir_client.c_str());
2618
po::store(parse_config_file(system_client_ifs, client_options), vm);
2623
if ( ! vm.count("database-used") && ! vm.count("Table-used") && ! opt_alldbs && path.empty())
2625
printf(_("Usage: %s [OPTIONS] database [tables]\n"), internal::my_progname);
2626
printf(_("OR %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n"),
2627
internal::my_progname);
2628
printf(_("OR %s [OPTIONS] --all-databases [OPTIONS]\n"), internal::my_progname);
2632
if (vm.count("port"))
2634
/* If the port number is > 65535 it is not a valid port
2635
* This also helps with potential data loss casting unsigned long to a
2638
if (opt_drizzle_port > 65535)
2640
fprintf(stderr, _("Value supplied for port is not valid.\n"));
2645
if(vm.count("password"))
2647
if (!opt_password.empty())
2648
opt_password.erase();
2649
if (password == PASSWORD_SENTINEL)
2655
opt_password= password;
2656
tty_password= false;
2664
if (vm.count("result-file"))
2666
if (!(md_result_file= fopen(vm["result-file"].as<string>().c_str(), "w")))
2670
if (vm.count("no-set-names"))
2677
opt_disable_keys= 0;
2679
if (vm["tab"].as<string>().length() >= FN_REFLEN)
2682
This check is made because the some the file functions below
2683
have FN_REFLEN sized stack allocated buffers and will cause
2684
a crash even if the input destination buffer is large enough
2687
fprintf(stderr, _("Input filename too long: %s"), vm["tab"].as<string>().c_str());
2688
exit(EXIT_ARGUMENT_INVALID);
2692
if (vm.count("version"))
2694
printf(_("%s Drizzle %s libdrizzle %s, for %s-%s (%s)\n"), internal::my_progname,
2695
VERSION, drizzle_version(), HOST_VENDOR, HOST_OS, HOST_CPU);
2698
if (vm.count("xml"))
2701
extended_insert= opt_drop= opt_disable_keys= opt_autocommit= opt_create_db= 0;
2704
if (vm.count("help"))
2706
printf(_("%s Drizzle %s libdrizzle %s, for %s-%s (%s)\n"), internal::my_progname,
2707
VERSION, drizzle_version(), HOST_VENDOR, HOST_OS, HOST_CPU);
2709
puts(_("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n"));
2710
puts(_("Dumps definitions and data from a Drizzle database server"));
2711
cout << long_options;
2712
printf(_("Usage: %s [OPTIONS] database [tables]\n"), internal::my_progname);
2713
printf(_("OR %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n"),
2714
internal::my_progname);
2715
printf(_("OR %s [OPTIONS] --all-databases [OPTIONS]\n"), internal::my_progname);
2719
if (vm.count("skip-opt"))
2721
extended_insert= opt_drop= quick= create_options= 0;
2722
opt_disable_keys= opt_set_charset= 0;
2727
opt_comments= opt_drop= opt_disable_keys= 0;
2731
if (vm.count("opt"))
2733
extended_insert= opt_drop= quick= create_options= 1;
2734
opt_disable_keys= opt_set_charset= 1;
2737
if (vm.count("tables"))
2739
opt_databases= false;
2742
if (vm.count("ignore-table"))
2744
if (!strchr(vm["ignore-table"].as<string>().c_str(), '.'))
2746
fprintf(stderr, _("Illegal use of option --ignore-table=<database>.<table>\n"));
2747
exit(EXIT_ARGUMENT_INVALID);
2749
string tmpptr(vm["ignore-table"].as<string>());
2750
ignore_table.insert(tmpptr);
2753
if (vm.count("skip-create"))
2755
opt_create_db= opt_no_create_info= create_options= false;
2758
if (vm.count("skip-comments"))
2760
opt_comments= false;
2763
if (vm.count("skip-extended-insert"))
2765
extended_insert= false;
2768
if (vm.count("skip-dump-date"))
2770
opt_dump_date= false;
2773
if (! opt_compatible_mode_str.empty())
2776
char *end= compatible_mode_normal_str;
2783
opt_compatible_mode= find_set(&compatible_mode_typelib,
2784
opt_compatible_mode_str.c_str(), opt_compatible_mode_str.length(),
2785
&err_ptr, &error_len);
2788
strncpy(buff, err_ptr, min((uint32_t)sizeof(buff), error_len+1));
2789
fprintf(stderr, _("Invalid mode to --compatible: %s\n"), buff);
2790
exit(EXIT_ARGUMENT_INVALID);
2792
mode= opt_compatible_mode;
2793
for (i= 0, mode= opt_compatible_mode; mode; mode>>= 1, i++)
2797
uint32_t len = strlen(compatible_mode_names[i]);
2798
end= strcpy(end, compatible_mode_names[i]) + len;
2799
end= strcpy(end, ",")+1;
2802
if (end!=compatible_mode_normal_str)
2807
exit_code= get_options();
2845
2810
free_resources();