|
90 | 90 | /* Max length GTID position that we will output. */
|
91 | 91 | #define MAX_GTID_LENGTH 1024
|
92 | 92 |
|
| 93 | +static my_bool ignore_table_data(const uchar *hash_key, size_t len); |
93 | 94 | static void add_load_option(DYNAMIC_STRING *str, const char *option,
|
94 | 95 | const char *option_value);
|
95 | 96 | static ulong find_set(TYPELIB *, const char *, size_t, char **, uint *);
|
@@ -210,7 +211,7 @@ TYPELIB compatible_mode_typelib= {array_elements(compatible_mode_names) - 1,
|
210 | 211 |
|
211 | 212 | #define MED_ENGINES "MRG_MyISAM, MRG_ISAM, CONNECT, OQGRAPH, SPIDER, VP, FEDERATED"
|
212 | 213 |
|
213 |
| -HASH ignore_table; |
| 214 | +HASH ignore_table, ignore_data; |
214 | 215 |
|
215 | 216 | static struct my_option my_long_options[] =
|
216 | 217 | {
|
@@ -371,6 +372,12 @@ static struct my_option my_long_options[] =
|
371 | 372 | &opt_hex_blob, &opt_hex_blob, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
372 | 373 | {"host", 'h', "Connect to host.", ¤t_host,
|
373 | 374 | ¤t_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
| 375 | + {"ignore-table-data", OPT_IGNORE_DATA, |
| 376 | + "Do not dump the specified table data. To specify more than one table " |
| 377 | + "to ignore, use the directive multiple times, once for each table. " |
| 378 | + "Each table must be specified with both database and table names, e.g., " |
| 379 | + "--ignore-table-data=database.table.", |
| 380 | + 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, |
374 | 381 | {"ignore-table", OPT_IGNORE_TABLE,
|
375 | 382 | "Do not dump the specified table. To specify more than one table to ignore, "
|
376 | 383 | "use the directive multiple times, once for each table. Each table must "
|
@@ -895,6 +902,18 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
|
895 | 902 | case (int) OPT_TABLES:
|
896 | 903 | opt_databases=0;
|
897 | 904 | break;
|
| 905 | + case (int) OPT_IGNORE_DATA: |
| 906 | + { |
| 907 | + if (!strchr(argument, '.')) |
| 908 | + { |
| 909 | + fprintf(stderr, |
| 910 | + "Illegal use of option --ignore-table-data=<database>.<table>\n"); |
| 911 | + exit(1); |
| 912 | + } |
| 913 | + if (my_hash_insert(&ignore_data, (uchar*)my_strdup(argument, MYF(0)))) |
| 914 | + exit(EX_EOM); |
| 915 | + break; |
| 916 | + } |
898 | 917 | case (int) OPT_IGNORE_TABLE:
|
899 | 918 | {
|
900 | 919 | if (!strchr(argument, '.'))
|
@@ -993,6 +1012,10 @@ static int get_options(int *argc, char ***argv)
|
993 | 1012 | (uchar*) my_strdup("mysql.slow_log", MYF(MY_WME))))
|
994 | 1013 | return(EX_EOM);
|
995 | 1014 |
|
| 1015 | + if (my_hash_init(&ignore_data, charset_info, 16, 0, 0, |
| 1016 | + (my_hash_get_key) get_table_key, my_free, 0)) |
| 1017 | + return(EX_EOM); |
| 1018 | + |
996 | 1019 | if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
|
997 | 1020 | return(ho_error);
|
998 | 1021 |
|
@@ -1637,6 +1660,8 @@ static void free_resources()
|
1637 | 1660 | free_root(&glob_root, MYF(0));
|
1638 | 1661 | if (my_hash_inited(&ignore_table))
|
1639 | 1662 | my_hash_free(&ignore_table);
|
| 1663 | + if (my_hash_inited(&ignore_data)) |
| 1664 | + my_hash_free(&ignore_data); |
1640 | 1665 | dynstr_free(&extended_row);
|
1641 | 1666 | dynstr_free(&dynamic_where);
|
1642 | 1667 | dynstr_free(&insert_pat);
|
@@ -3601,7 +3626,7 @@ static char *alloc_query_str(ulong size)
|
3601 | 3626 | */
|
3602 | 3627 |
|
3603 | 3628 |
|
3604 |
| -static void dump_table(char *table, char *db) |
| 3629 | +static void dump_table(char *table, char *db, const uchar *hash_key, size_t len) |
3605 | 3630 | {
|
3606 | 3631 | char ignore_flag;
|
3607 | 3632 | char buf[200], table_buff[NAME_LEN+3];
|
@@ -3629,7 +3654,7 @@ static void dump_table(char *table, char *db)
|
3629 | 3654 | DBUG_VOID_RETURN;
|
3630 | 3655 |
|
3631 | 3656 | /* Check --no-data flag */
|
3632 |
| - if (opt_no_data) |
| 3657 | + if (opt_no_data || (hash_key && ignore_table_data(hash_key, len))) |
3633 | 3658 | {
|
3634 | 3659 | verbose_msg("-- Skipping dump data for table '%s', --no-data was used\n",
|
3635 | 3660 | table);
|
@@ -4557,10 +4582,14 @@ static int init_dumping(char *database, int init_func(char*))
|
4557 | 4582 |
|
4558 | 4583 | /* Return 1 if we should copy the table */
|
4559 | 4584 |
|
4560 |
| -my_bool include_table(const uchar *hash_key, size_t len) |
| 4585 | +static my_bool include_table(const uchar *hash_key, size_t len) |
4561 | 4586 | {
|
4562 | 4587 | return ! my_hash_search(&ignore_table, hash_key, len);
|
4563 | 4588 | }
|
| 4589 | +static my_bool ignore_table_data(const uchar *hash_key, size_t len) |
| 4590 | +{ |
| 4591 | + return my_hash_search(&ignore_data, hash_key, len) != NULL; |
| 4592 | +} |
4564 | 4593 |
|
4565 | 4594 |
|
4566 | 4595 | static int dump_all_tables_in_db(char *database)
|
@@ -4625,7 +4654,7 @@ static int dump_all_tables_in_db(char *database)
|
4625 | 4654 | char *end= strmov(afterdot, table);
|
4626 | 4655 | if (include_table((uchar*) hash_key, end - hash_key))
|
4627 | 4656 | {
|
4628 |
| - dump_table(table,database); |
| 4657 | + dump_table(table, database, (uchar*) hash_key, end - hash_key); |
4629 | 4658 | my_free(order_by);
|
4630 | 4659 | order_by= 0;
|
4631 | 4660 | if (opt_dump_triggers && mysql_get_server_version(mysql) >= 50009)
|
@@ -5014,7 +5043,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
|
5014 | 5043 | for (pos= dump_tables; pos < end; pos++)
|
5015 | 5044 | {
|
5016 | 5045 | DBUG_PRINT("info",("Dumping table %s", *pos));
|
5017 |
| - dump_table(*pos, db); |
| 5046 | + dump_table(*pos, db, NULL, 0); |
5018 | 5047 | if (opt_dump_triggers &&
|
5019 | 5048 | mysql_get_server_version(mysql) >= 50009)
|
5020 | 5049 | {
|
@@ -5995,6 +6024,7 @@ int main(int argc, char **argv)
|
5995 | 6024 | compatible_mode_normal_str[0]= 0;
|
5996 | 6025 | default_charset= (char *)mysql_universal_client_charset;
|
5997 | 6026 | bzero((char*) &ignore_table, sizeof(ignore_table));
|
| 6027 | + bzero((char*) &ignore_data, sizeof(ignore_data)); |
5998 | 6028 |
|
5999 | 6029 | exit_code= get_options(&argc, &argv);
|
6000 | 6030 | if (exit_code)
|
|
0 commit comments