101
102
static bool opt_dump_date= true;
102
103
static bool opt_autocommit= false;
103
104
static bool opt_disable_keys= true;
104
static bool opt_xml= false;
105
static bool tty_password= false;
106
106
static bool opt_single_transaction= false;
107
static bool opt_comments= false;
108
static bool opt_compact= false;
107
static bool opt_comments;
108
static bool opt_compact;
109
109
static bool opt_hex_blob= false;
110
110
static bool opt_order_by_primary=false;
111
111
static bool opt_ignore= false;
112
112
static bool opt_complete_insert= false;
113
static bool opt_drop_database= false;
113
static bool opt_drop_database;
114
114
static bool opt_replace_into= false;
115
static bool opt_routines= false;
116
115
static bool opt_alltspcs= false;
117
116
static uint32_t show_progress_size= 0;
118
117
static uint64_t total_rows= 0;
119
118
static drizzle_st drizzle;
120
119
static drizzle_con_st dcon;
121
120
static string insert_pat;
122
static char *opt_password= NULL;
123
static char *current_user= NULL;
124
static char *current_host= NULL;
125
static char *path= NULL;
126
static char *fields_terminated= NULL;
127
static char *lines_terminated= NULL;
128
static char *enclosed= NULL;
129
static char *opt_enclosed= NULL;
130
static char *escaped= NULL;
131
static char *where= NULL;
132
121
static char *order_by= NULL;
133
static char *opt_compatible_mode_str= NULL;
134
static char *err_ptr= NULL;
135
static char **defaults_argv= NULL;
136
static char compatible_mode_normal_str[255];
137
static uint32_t opt_compatible_mode= 0;
138
122
static uint32_t opt_drizzle_port= 0;
139
123
static int first_error= 0;
140
124
static string extended_row;
141
125
FILE *md_result_file= 0;
142
126
FILE *stderror_file= 0;
128
const string progname= "drizzledump";
144
143
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
146
static const char *compatible_mode_names[]=
148
"MYSQL323", "MYSQL40", "POSTGRESQL", "ORACLE", "MSSQL", "DB2",
149
"MAXDB", "NO_KEY_OPTIONS", "NO_TABLE_OPTIONS", "NO_FIELD_OPTIONS",
153
static TYPELIB compatible_mode_typelib= {array_elements(compatible_mode_names) - 1,
154
"", compatible_mode_names, NULL};
156
drizzled::hash_set<string> ignore_table;
158
static struct option my_long_options[] =
160
{"all", 'a', "Deprecated. Use --create-options instead.",
161
(char**) &create_options, (char**) &create_options, 0, GET_BOOL, NO_ARG, 1,
163
{"all-databases", 'A',
164
"Dump all the databases. This will be same as --databases with all databases selected.",
165
(char**) &opt_alldbs, (char**) &opt_alldbs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
167
{"all-tablespaces", 'Y',
168
"Dump all the tablespaces.",
169
(char**) &opt_alltspcs, (char**) &opt_alltspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
171
{"add-drop-database", OPT_DROP_DATABASE, "Add a 'DROP DATABASE' before each create.",
172
(char**) &opt_drop_database, (char**) &opt_drop_database, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
174
{"add-drop-table", OPT_DROP, "Add a 'drop table' before each create.",
175
(char**) &opt_drop, (char**) &opt_drop, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
177
{"allow-keywords", OPT_KEYWORDS,
178
"Allow creation of column names that are keywords.", (char**) &opt_keywords,
179
(char**) &opt_keywords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
180
{"comments", 'i', "Write additional information.",
181
(char**) &opt_comments, (char**) &opt_comments, 0, GET_BOOL, NO_ARG,
183
{"compatible", OPT_COMPATIBLE,
184
"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.",
185
(char**) &opt_compatible_mode_str, (char**) &opt_compatible_mode_str, 0,
186
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
187
{"compact", OPT_COMPACT,
188
"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",
189
(char**) &opt_compact, (char**) &opt_compact, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
191
{"complete-insert", 'c', "Use complete insert statements.",
192
(char**) &opt_complete_insert, (char**) &opt_complete_insert, 0, GET_BOOL,
193
NO_ARG, 0, 0, 0, 0, 0, 0},
194
{"compress", 'C', "Use compression in server/client protocol.",
195
(char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
197
{"create-options", OPT_CREATE_OPTIONS,
198
"Include all DRIZZLE specific create options.",
199
(char**) &create_options, (char**) &create_options, 0, GET_BOOL, NO_ARG, 1,
202
"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.",
203
(char**) &opt_databases, (char**) &opt_databases, 0, GET_BOOL, NO_ARG, 0, 0,
205
{"delayed-insert", OPT_DELAYED, "Insert rows with INSERT DELAYED; ",
206
(char**) &opt_delayed, (char**) &opt_delayed, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
208
{"disable-keys", 'K',
209
"'ALTER TABLE tb_name DISABLE KEYS; and 'ALTER TABLE tb_name ENABLE KEYS; will be put in the output.", (char**) &opt_disable_keys,
210
(char**) &opt_disable_keys, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
211
{"extended-insert", 'e',
212
"Allows utilization of the new, much faster INSERT syntax.",
213
(char**) &extended_insert, (char**) &extended_insert, 0, GET_BOOL, NO_ARG,
215
{"fields-terminated-by", OPT_FTB,
216
"Fields in the textfile are terminated by ...", (char**) &fields_terminated,
217
(char**) &fields_terminated, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
218
{"fields-enclosed-by", OPT_ENC,
219
"Fields in the importfile are enclosed by ...", (char**) &enclosed,
220
(char**) &enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
221
{"fields-optionally-enclosed-by", OPT_O_ENC,
222
"Fields in the i.file are opt. enclosed by ...", (char**) &opt_enclosed,
223
(char**) &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
224
{"fields-escaped-by", OPT_ESC, "Fields in the i.file are escaped by ...",
225
(char**) &escaped, (char**) &escaped, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
226
{"flush-logs", 'F', "Flush logs file in server before starting dump. "
227
"Note that if you dump many databases at once (using the option "
228
"--databases= or --all-databases), the logs will be flushed for "
229
"each database dumped. The exception is when using --lock-all-tables "
230
"in this case the logs will be flushed only once, corresponding "
231
"to the moment all tables are locked. So if you want your dump and "
232
"the log flush to happen at the same exact moment you should use "
233
"--lock-all-tables or --flush-logs",
234
(char**) &flush_logs, (char**) &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
236
{"force", 'f', "Continue even if we get an sql-error.",
237
(char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG,
239
{"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG,
240
NO_ARG, 0, 0, 0, 0, 0, 0},
241
{"hex-blob", OPT_HEXBLOB, "Dump binary strings (BINARY, "
242
"VARBINARY, BLOB) in hexadecimal format.",
243
(char**) &opt_hex_blob, (char**) &opt_hex_blob, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
244
{"host", 'h', "Connect to host.", (char**) ¤t_host,
245
(char**) ¤t_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
246
{"ignore-table", OPT_IGNORE_TABLE,
247
"Do not dump the specified table. To specify more than one table to ignore, "
248
"use the directive multiple times, once for each table. Each table must "
249
"be specified with both database and table names, e.g. --ignore-table=database.table",
250
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
251
{"insert-ignore", OPT_INSERT_IGNORE, "Insert rows with INSERT IGNORE.",
252
(char**) &opt_ignore, (char**) &opt_ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
254
{"lines-terminated-by", OPT_LTB, "Lines in the i.file are terminated by ...",
255
(char**) &lines_terminated, (char**) &lines_terminated, 0, GET_STR,
256
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
257
{"lock-all-tables", 'x', "Locks all tables across all databases. This "
258
"is achieved by taking a global read lock for the duration of the whole "
259
"dump. Automatically turns --single-transaction and --lock-tables off.",
260
(char**) &opt_lock_all_tables, (char**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
262
{"mysql", 'm', N_("Use MySQL Protocol."),
263
(char**) &opt_mysql, (char**) &opt_mysql, 0, GET_BOOL, NO_ARG, 1, 0, 0,
265
{"no-autocommit", OPT_AUTOCOMMIT,
266
"Wrap tables with autocommit/commit statements.",
267
(char**) &opt_autocommit, (char**) &opt_autocommit, 0, GET_BOOL, NO_ARG,
269
{"no-create-db", 'n',
270
"'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.}.",
271
(char**) &opt_create_db, (char**) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0,
273
{"no-create-info", 't', "Don't write table creation info.",
274
(char**) &opt_no_create_info, (char**) &opt_no_create_info, 0, GET_BOOL,
275
NO_ARG, 0, 0, 0, 0, 0, 0},
276
{"no-data", 'd', "No row information.", (char**) &opt_no_data,
277
(char**) &opt_no_data, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
278
{"no-set-names", 'N',
279
"Deprecated. Use --skip-set-charset instead.",
280
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
281
{"opt", OPT_OPTIMIZE,
282
"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.",
283
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
284
{"order-by-primary", OPT_ORDER_BY_PRIMARY,
285
"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.",
286
(char**) &opt_order_by_primary, (char**) &opt_order_by_primary, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
288
"Password to use when connecting to server. If password is not given it's solicited on the tty.",
289
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
290
{"port", 'p', "Port number to use for connection.",
291
0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
292
{"quick", 'q', "Don't buffer query, dump directly to stdout.",
293
(char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
294
{"quote-names",'Q', "Quote table and column names with backticks (`).",
295
(char**) &opt_quoted, (char**) &opt_quoted, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
297
{"replace", OPT_DRIZZLE_REPLACE_INTO, "Use REPLACE INTO instead of INSERT INTO.",
298
(char**) &opt_replace_into, (char**) &opt_replace_into, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
301
"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).",
302
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
303
{"routines", 'R', "Dump stored routines (functions and procedures).",
304
(char**) &opt_routines, (char**) &opt_routines, 0, GET_BOOL,
305
NO_ARG, 0, 0, 0, 0, 0, 0},
306
{"single-transaction", OPT_TRANSACTION,
307
"Creates a consistent snapshot by dumping all tables in a single "
308
"transaction. Works ONLY for tables stored in storage engines which "
309
"support multiversioning (currently only InnoDB does); the dump is NOT "
310
"guaranteed to be consistent for other storage engines. "
311
"While a --single-transaction dump is in process, to ensure a valid "
312
"dump file (correct table contents), no other "
313
"connection should use the following statements: ALTER TABLE, DROP "
314
"TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not "
315
"isolated from them. Option automatically turns off --lock-tables.",
316
(char**) &opt_single_transaction, (char**) &opt_single_transaction, 0,
317
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
318
{"dump-date", OPT_DUMP_DATE, "Put a dump date to the end of the output.",
319
(char**) &opt_dump_date, (char**) &opt_dump_date, 0,
320
GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
321
{"skip-opt", OPT_SKIP_OPTIMIZATION,
322
"Disable --opt. Disables --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys.",
323
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
325
"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.",
326
(char**) &path, (char**) &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
327
{"tables", OPT_TABLES, "Overrides option --databases (-B).",
328
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
329
{"show-progress-size", OPT_SHOW_PROGRESS_SIZE, N_("Number of rows before each output progress report (requires --verbose)."),
330
(char**) &show_progress_size, (char**) &show_progress_size, 0, GET_UINT32, REQUIRED_ARG,
331
10000, 0, 0, 0, 0, 0},
332
{"user", 'u', "User for login if not current user.",
333
(char**) ¤t_user, (char**) ¤t_user, 0, GET_STR, REQUIRED_ARG,
335
{"verbose", 'v', "Print info about the various stages.",
336
(char**) &verbose, (char**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
337
{"version",'V', "Output version information and exit.", 0, 0, 0,
338
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
339
{"where", 'w', "Dump only selected records; QUOTES mandatory!",
340
(char**) &where, (char**) &where, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
341
{"xml", 'X', "Dump a database as well formed XML.", 0, 0, 0, GET_NO_ARG,
342
NO_ARG, 0, 0, 0, 0, 0, 0},
343
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
346
static const char *load_default_groups[]= { "drizzledump","client",0 };
145
boost::unordered_set<string> ignore_table;
348
147
static void maybe_exit(int error);
349
148
static void die(int error, const char* reason, ...);
2821
2389
int main(int argc, char **argv)
2824
MY_INIT("drizzledump");
2825
2394
drizzle_result_st result;
2827
compatible_mode_normal_str[0]= 0;
2829
exit_code= get_options(&argc, &argv);
2396
po::options_description commandline_options(N_("Options used only in command line"));
2397
commandline_options.add_options()
2398
("all-databases,A", po::value<bool>(&opt_alldbs)->default_value(false)->zero_tokens(),
2399
N_("Dump all the databases. This will be same as --databases with all databases selected."))
2400
("all-tablespaces,Y", po::value<bool>(&opt_alltspcs)->default_value(false)->zero_tokens(),
2401
N_("Dump all the tablespaces."))
2402
("complete-insert,c", po::value<bool>(&opt_complete_insert)->default_value(false)->zero_tokens(),
2403
N_("Use complete insert statements."))
2404
("compress,C", po::value<bool>(&opt_compress)->default_value(false)->zero_tokens(),
2405
N_("Use compression in server/client protocol."))
2406
("flush-logs,F", po::value<bool>(&flush_logs)->default_value(false)->zero_tokens(),
2407
N_("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"))
2408
("force,f", po::value<bool>(&ignore_errors)->default_value(false)->zero_tokens(),
2409
N_("Continue even if we get an sql-error."))
2410
("help,?", N_("Display this help message and exit."))
2411
("lock-all-tables,x", po::value<bool>(&opt_lock_all_tables)->default_value(false)->zero_tokens(),
2412
N_("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."))
2413
("order-by-primary", po::value<bool>(&opt_order_by_primary)->default_value(false)->zero_tokens(),
2414
N_("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."))
2415
("single-transaction", po::value<bool>(&opt_single_transaction)->default_value(false)->zero_tokens(),
2416
N_("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."))
2417
("opt", N_("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."))
2419
N_("Disable --opt. Disables --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys."))
2420
("tables", N_("Overrides option --databases (-B)."))
2421
("show-progress-size", po::value<uint32_t>(&show_progress_size)->default_value(10000),
2422
N_("Number of rows before each output progress report (requires --verbose)."))
2423
("verbose,v", po::value<bool>(&verbose)->default_value(false)->zero_tokens(),
2424
N_("Print info about the various stages."))
2425
("version,V", N_("Output version information and exit."))
2426
("xml,X", N_("Dump a database as well formed XML."))
2427
("skip-comments", N_("Turn off Comments"))
2428
("skip-create", N_("Turn off create-options"))
2429
("skip-extended-insert", N_("Turn off extended-insert"))
2430
("skip-dump-date",N_( "Turn off dump-date"))
2431
("no-defaults", N_("Do not read from the configuration files"))
2434
po::options_description dump_options(N_("Options specific to the drizzle client"));
2435
dump_options.add_options()
2436
("add-drop-database", po::value<bool>(&opt_drop_database)->default_value(false)->zero_tokens(),
2437
N_("Add a 'DROP DATABASE' before each create."))
2438
("add-drop-table", po::value<bool>(&opt_drop)->default_value(true)->zero_tokens(),
2439
N_("Add a 'drop table' before each create."))
2440
("allow-keywords", po::value<bool>(&opt_keywords)->default_value(false)->zero_tokens(),
2441
N_("Allow creation of column names that are keywords."))
2442
("comments,i", po::value<bool>(&opt_comments)->default_value(true)->zero_tokens(),
2443
N_("Write additional information."))
2444
("compact", po::value<bool>(&opt_compact)->default_value(false)->zero_tokens(),
2445
N_("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"))
2446
("create-options", po::value<bool>(&create_options)->default_value(true)->zero_tokens(),
2447
N_("Include all DRIZZLE specific create options."))
2448
("dump-date", po::value<bool>(&opt_dump_date)->default_value(true)->zero_tokens(),
2449
N_("Put a dump date to the end of the output."))
2450
("databases,B", po::value<bool>(&opt_databases)->default_value(false)->zero_tokens(),
2451
N_("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."))
2452
("delayed-insert", po::value<bool>(&opt_delayed)->default_value(false)->zero_tokens(),
2453
N_("Insert rows with INSERT DELAYED;"))
2454
("disable-keys,K", po::value<bool>(&opt_disable_keys)->default_value(true)->zero_tokens(),
2455
N_("'ALTER TABLE tb_name DISABLE KEYS; and 'ALTER TABLE tb_name ENABLE KEYS; will be put in the output."))
2456
("extended-insert,e", po::value<bool>(&extended_insert)->default_value(true)->zero_tokens(),
2457
N_("Allows utilization of the new, much faster INSERT syntax."))
2458
("fields-terminated-by", po::value<string>(&fields_terminated)->default_value(""),
2459
N_("Fields in the textfile are terminated by ..."))
2460
("fields-enclosed-by", po::value<string>(&enclosed)->default_value(""),
2461
N_("Fields in the importfile are enclosed by ..."))
2462
("fields-optionally-enclosed-by", po::value<string>(&opt_enclosed)->default_value(""),
2463
N_("Fields in the i.file are opt. enclosed by ..."))
2464
("fields-escaped-by", po::value<string>(&escaped)->default_value(""),
2465
N_("Fields in the i.file are escaped by ..."))
2466
("hex-blob", po::value<bool>(&opt_hex_blob)->default_value(false)->zero_tokens(),
2467
"Dump binary strings (BINARY, VARBINARY, BLOB) in hexadecimal format.")
2468
("ignore-table", po::value<string>(),
2469
N_("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"))
2470
("insert-ignore", po::value<bool>(&opt_ignore)->default_value(false)->zero_tokens(),
2471
N_("Insert rows with INSERT IGNORE."))
2472
("lines-terminated-by", po::value<string>(&lines_terminated)->default_value(""),
2473
N_("Lines in the i.file are terminated by ..."))
2474
("no-autocommit", po::value<bool>(&opt_autocommit)->default_value(false)->zero_tokens(),
2475
N_("Wrap tables with autocommit/commit statements."))
2476
("no-create-db,n", po::value<bool>(&opt_create_db)->default_value(false)->zero_tokens(),
2477
N_("'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."))
2478
("no-create-info,t", po::value<bool>(&opt_no_create_info)->default_value(false)->zero_tokens(),
2479
N_("Don't write table creation info."))
2480
("no-data,d", po::value<bool>(&opt_no_data)->default_value(false)->zero_tokens(),
2481
N_("No row information."))
2482
("no-set-names,N", N_("Deprecated. Use --skip-set-charset instead."))
2483
("set-charset", po::value<bool>(&opt_set_charset)->default_value(false)->zero_tokens(),
2484
N_("Enable set-name"))
2485
("quick,q", po::value<bool>(&quick)->default_value(true)->zero_tokens(),
2486
N_("Don't buffer query, dump directly to stdout."))
2487
("quote-names,Q", po::value<bool>(&opt_quoted)->default_value(true)->zero_tokens(),
2488
N_("Quote table and column names with backticks (`)."))
2489
("replace", po::value<bool>(&opt_replace_into)->default_value(false)->zero_tokens(),
2490
N_("Use REPLACE INTO instead of INSERT INTO."))
2491
("result-file,r", po::value<string>(),
2492
N_("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)."))
2493
("tab,T", po::value<string>(&path)->default_value(""),
2494
N_("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."))
2495
("where,w", po::value<string>(&where)->default_value(""),
2496
N_("Dump only selected records; QUOTES mandatory!"))
2499
po::options_description client_options(N_("Options specific to the client"));
2500
client_options.add_options()
2501
("host,h", po::value<string>(¤t_host)->default_value("localhost"),
2502
N_("Connect to host."))
2503
("password,P", po::value<string>(&password)->default_value(PASSWORD_SENTINEL),
2504
N_("Password to use when connecting to server. If password is not given it's solicited on the tty."))
2505
("port,p", po::value<uint32_t>(&opt_drizzle_port)->default_value(0),
2506
N_("Port number to use for connection."))
2507
("user,u", po::value<string>(¤t_user)->default_value(""),
2508
N_("User for login if not current user."))
2509
("protocol",po::value<string>(&opt_protocol)->default_value("mysql"),
2510
N_("The protocol of connection (mysql or drizzle)."))
2513
po::options_description hidden_options(N_("Hidden Options"));
2514
hidden_options.add_options()
2515
("database-used", po::value<vector<string> >(), N_("Used to select the database"))
2516
("Table-used", po::value<vector<string> >(), N_("Used to select the tables"))
2519
po::options_description all_options(N_("Allowed Options + Hidden Options"));
2520
all_options.add(commandline_options).add(dump_options).add(client_options).add(hidden_options);
2522
po::options_description long_options(N_("Allowed Options"));
2523
long_options.add(commandline_options).add(dump_options).add(client_options);
2525
std::string system_config_dir_dump(SYSCONFDIR);
2526
system_config_dir_dump.append("/drizzle/drizzledump.cnf");
2528
std::string system_config_dir_client(SYSCONFDIR);
2529
system_config_dir_client.append("/drizzle/client.cnf");
2531
std::string user_config_dir((getenv("XDG_CONFIG_HOME")? getenv("XDG_CONFIG_HOME"):"~/.config"));
2533
po::positional_options_description p;
2534
p.add("database-used", 1);
2535
p.add("Table-used",-1);
2537
md_result_file= stdout;
2539
po::variables_map vm;
2541
po::store(po::command_line_parser(argc, argv).options(all_options).
2542
positional(p).extra_parser(parse_password_arg).run(), vm);
2544
if (! vm.count("no-defaults"))
2546
std::string user_config_dir_dump(user_config_dir);
2547
user_config_dir_dump.append("/drizzle/drizzledump.cnf");
2549
std::string user_config_dir_client(user_config_dir);
2550
user_config_dir_client.append("/drizzle/client.cnf");
2552
ifstream user_dump_ifs(user_config_dir_dump.c_str());
2553
po::store(parse_config_file(user_dump_ifs, dump_options), vm);
2555
ifstream user_client_ifs(user_config_dir_client.c_str());
2556
po::store(parse_config_file(user_client_ifs, client_options), vm);
2558
ifstream system_dump_ifs(system_config_dir_dump.c_str());
2559
po::store(parse_config_file(system_dump_ifs, dump_options), vm);
2561
ifstream system_client_ifs(system_config_dir_client.c_str());
2562
po::store(parse_config_file(system_client_ifs, client_options), vm);
2567
if ((not vm.count("database-used") && not vm.count("Table-used")
2568
&& not opt_alldbs && path.empty())
2569
|| (vm.count("help")) || vm.count("version"))
2571
printf(_("Drizzledump %s build %s, for %s-%s (%s)\n"),
2572
drizzle_version(), VERSION, HOST_VENDOR, HOST_OS, HOST_CPU);
2573
if (vm.count("version"))
2576
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"));
2577
puts(_("Dumps definitions and data from a Drizzle database server"));
2578
printf(_("Usage: %s [OPTIONS] database [tables]\n"), progname.c_str());
2579
printf(_("OR %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n"),
2581
printf(_("OR %s [OPTIONS] --all-databases [OPTIONS]\n"), progname.c_str());
2582
cout << long_options;
2583
if (vm.count("help"))
2589
if (vm.count("protocol"))
2591
std::transform(opt_protocol.begin(), opt_protocol.end(),
2592
opt_protocol.begin(), ::tolower);
2594
if (not opt_protocol.compare("mysql"))
2595
use_drizzle_protocol=false;
2596
else if (not opt_protocol.compare("drizzle"))
2597
use_drizzle_protocol=true;
2600
cout << _("Error: Unknown protocol") << " '" << opt_protocol << "'" << endl;
2605
if (vm.count("port"))
2607
/* If the port number is > 65535 it is not a valid port
2608
* This also helps with potential data loss casting unsigned long to a
2611
if (opt_drizzle_port > 65535)
2613
fprintf(stderr, _("Value supplied for port is not valid.\n"));
2618
if(vm.count("password"))
2620
if (!opt_password.empty())
2621
opt_password.erase();
2622
if (password == PASSWORD_SENTINEL)
2628
opt_password= password;
2629
tty_password= false;
2637
if (vm.count("result-file"))
2639
if (!(md_result_file= fopen(vm["result-file"].as<string>().c_str(), "w")))
2643
if (vm.count("no-set-names"))
2650
opt_disable_keys= 0;
2652
if (vm["tab"].as<string>().length() >= FN_REFLEN)
2655
This check is made because the some the file functions below
2656
have FN_REFLEN sized stack allocated buffers and will cause
2657
a crash even if the input destination buffer is large enough
2660
fprintf(stderr, _("Input filename too long: %s"), vm["tab"].as<string>().c_str());
2661
exit(EXIT_ARGUMENT_INVALID);
2665
if (vm.count("xml"))
2668
extended_insert= opt_drop= opt_disable_keys= opt_autocommit= opt_create_db= 0;
2671
if (vm.count("skip-opt"))
2673
extended_insert= opt_drop= quick= create_options= 0;
2674
opt_disable_keys= opt_set_charset= 0;
2679
opt_comments= opt_drop= opt_disable_keys= 0;
2683
if (vm.count("opt"))
2685
extended_insert= opt_drop= quick= create_options= 1;
2686
opt_disable_keys= opt_set_charset= 1;
2689
if (vm.count("tables"))
2691
opt_databases= false;
2694
if (vm.count("ignore-table"))
2696
if (!strchr(vm["ignore-table"].as<string>().c_str(), '.'))
2698
fprintf(stderr, _("Illegal use of option --ignore-table=<database>.<table>\n"));
2699
exit(EXIT_ARGUMENT_INVALID);
2701
string tmpptr(vm["ignore-table"].as<string>());
2702
ignore_table.insert(tmpptr);
2705
if (vm.count("skip-create"))
2707
opt_create_db= opt_no_create_info= create_options= false;
2710
if (vm.count("skip-comments"))
2712
opt_comments= false;
2715
if (vm.count("skip-extended-insert"))
2717
extended_insert= false;
2720
if (vm.count("skip-dump-date"))
2722
opt_dump_date= false;
2725
exit_code= get_options();
2832
2728
free_resources();