diff options
author | Vicențiu Ciorbaru <vicentiu@mariadb.org> | 2020-08-29 14:58:46 +0300 |
---|---|---|
committer | Vicențiu Ciorbaru <vicentiu@mariadb.org> | 2020-08-29 14:58:46 +0300 |
commit | b1f2871692e077951f8a2e6f5ebb2dec90bccf03 (patch) | |
tree | e81c28c1d17c7434124b1984eb4e6971f0d5b169 /client | |
parent | 72f0f0db9caaca6da7b9b35d60faa09b132442ec (diff) | |
download | mariadb-git-bb-10.6-vicentiu-wip.tar.gz |
mysqldump wipbb-10.6-vicentiu-wip
Diffstat (limited to 'client')
-rw-r--r-- | client/mysqldump.c | 62 |
1 files changed, 50 insertions, 12 deletions
diff --git a/client/mysqldump.c b/client/mysqldump.c index 4830a6c782b..55b10ca0037 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -117,7 +117,7 @@ static my_bool verbose= 0, opt_no_create_info= 0, opt_no_data= 0, opt_no_data_m opt_include_master_host_port= 0, opt_events= 0, opt_comments_used= 0, opt_alltspcs=0, opt_notspcs= 0, opt_logging, - opt_drop_trigger= 0 ; + opt_drop_trigger= 0, opt_specific_tables= 0; static my_bool insert_pat_inited= 0, debug_info_flag= 0, debug_check_flag= 0, select_field_names_inited= 0; static ulong opt_max_allowed_packet, opt_net_buffer_length; @@ -531,6 +531,10 @@ static struct my_option my_long_options[] = {"socket", 'S', "The socket file to use for connection.", &opt_mysql_unix_port, &opt_mysql_unix_port, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"specific-tables", 'B', + "TODO documentation", + &opt_specific_tables, &opt_specific_tables, 0, GET_BOOL, NO_ARG, 0, 0, + 0, 0, 0, 0}, #include <sslopt-longopts.h> {"tab",'T', "Create tab-separated textfile for each table to given path. (Create .sql " @@ -650,6 +654,7 @@ static void short_usage_sub(FILE *f) fprintf(f, "OR %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n", my_progname_short); fprintf(f, "OR %s [OPTIONS] --all-databases [OPTIONS]\n", my_progname_short); + fprintf(f, "OR %s [OPTIONS] --specific-tables [OPTIONS] db.table [db.table ...]\n", my_progname_short); } @@ -4695,7 +4700,7 @@ static int init_dumping(char *database, int init_func(char*)) } if (!path && !opt_xml) { - if (opt_databases || opt_alldbs) + if (opt_databases || opt_alldbs || opt_specific_tables) { /* length of table name * 2 (if name contains quotes), 2 quotes and 0 @@ -6282,33 +6287,66 @@ int main(int argc, char **argv) } else { + // We have either --databases <list> + // or --specific-tables <list> // Check all arguments meet length condition. Currently database and table // names are limited to NAME_LEN bytes and stack-based buffers assumes // that escaped name will be not longer than NAME_LEN*2 + 2 bytes long. + // database.table + // + // TODO this looks like it needs changes! int argument; for (argument= 0; argument < argc; argument++) { size_t argument_length= strlen(argv[argument]); - if (argument_length > NAME_LEN) + if (argument_length > NAME_LEN || + (opt_specific_tables && argument_length > NAME_LEN * 2 + 1)) { die(EX_CONSCHECK, "[ERROR] Argument '%s' is too long, it cannot be " "name for any table or database.\n", argv[argument]); } + if (opt_specific_tables && !strchr(argv[argument], '.')) + { + die(EX_CONSCHECK, "[ERROR] Argument '%s' does not specify the database " + "and table name. Use <database>.<table> format.\n", argv[argument]); + } } - if (argc > 1 && !opt_databases) + if (opt_specific_tables) { - /* Only one database and selected table(s) */ - if (!opt_alltspcs && !opt_notspcs) - dump_tablespaces_for_tables(*argv, (argv + 1), (argc - 1)); - dump_selected_tables(*argv, (argv + 1), (argc - 1)); + int i; + for (i= 0; i < argc; i++) + { + char *db, *table; + char *dot_pos= strchr(argv[i], '.'); + *dot_pos= '\0'; // Replace dot with \0 so we separate db and table. + db= argv[i]; + table= dot_pos + 1; + + if (init_dumping(db, init_dumping_tables)) + goto err; + + if (!opt_alltspcs && !opt_notspcs) + dump_tablespaces_for_tables(db, &table, 1); + dump_selected_tables(db, &table, 1); + } } else { - /* One or more databases, all tables */ - if (!opt_alltspcs && !opt_notspcs) - dump_tablespaces_for_databases(argv); - dump_databases(argv); + if (argc > 1 && !opt_databases) + { + /* Only one database and selected table(s) */ + if (!opt_alltspcs && !opt_notspcs) + dump_tablespaces_for_tables(*argv, (argv + 1), (argc - 1)); + dump_selected_tables(*argv, (argv + 1), (argc - 1)); + } + else + { + /* One or more databases, all tables */ + if (!opt_alltspcs && !opt_notspcs) + dump_tablespaces_for_databases(argv); + dump_databases(argv); + } } } |