Commit 0efe1971 authored by Vlad Lesin's avatar Vlad Lesin

MDEV-19347: Mariabackup does not honor ignore_db_dirs from server

config.

The solution is to read the system variable value on startup and to fill
databases_exclude_hash.

xb_load_list_string() became non-static and was reformatted. The system
variable value is read and processed in get_mysql_vars(), which was also
reformatted.
parent 36bddacf
...@@ -326,36 +326,36 @@ check_server_version(unsigned long version_number, ...@@ -326,36 +326,36 @@ check_server_version(unsigned long version_number,
/*********************************************************************//** /*********************************************************************//**
Receive options important for XtraBackup from MySQL server. Receive options important for XtraBackup from MySQL server.
@return true on success. */ @return true on success. */
bool bool get_mysql_vars(MYSQL *connection)
get_mysql_vars(MYSQL *connection)
{ {
char *gtid_mode_var = NULL; char *gtid_mode_var= NULL;
char *version_var = NULL; char *version_var= NULL;
char *version_comment_var = NULL; char *version_comment_var= NULL;
char *innodb_version_var = NULL; char *innodb_version_var= NULL;
char *have_backup_locks_var = NULL; char *have_backup_locks_var= NULL;
char *log_bin_var = NULL; char *log_bin_var= NULL;
char *lock_wait_timeout_var= NULL; char *lock_wait_timeout_var= NULL;
char *wsrep_on_var = NULL; char *wsrep_on_var= NULL;
char *slave_parallel_workers_var = NULL; char *slave_parallel_workers_var= NULL;
char *gtid_slave_pos_var = NULL; char *gtid_slave_pos_var= NULL;
char *innodb_buffer_pool_filename_var = NULL; char *innodb_buffer_pool_filename_var= NULL;
char *datadir_var = NULL; char *datadir_var= NULL;
char *innodb_log_group_home_dir_var = NULL; char *innodb_log_group_home_dir_var= NULL;
char *innodb_log_file_size_var = NULL; char *innodb_log_file_size_var= NULL;
char *innodb_log_files_in_group_var = NULL; char *innodb_log_files_in_group_var= NULL;
char *innodb_data_file_path_var = NULL; char *innodb_data_file_path_var= NULL;
char *innodb_data_home_dir_var = NULL; char *innodb_data_home_dir_var= NULL;
char *innodb_undo_directory_var = NULL; char *innodb_undo_directory_var= NULL;
char *innodb_page_size_var = NULL; char *innodb_page_size_var= NULL;
char *innodb_undo_tablespaces_var = NULL; char *innodb_undo_tablespaces_var= NULL;
char *page_zip_level_var = NULL; char *page_zip_level_var= NULL;
char *ignore_db_dirs= NULL;
char *endptr; char *endptr;
unsigned long server_version = mysql_get_server_version(connection); unsigned long server_version= mysql_get_server_version(connection);
bool ret = true; bool ret= true;
mysql_variable mysql_vars[] = { mysql_variable mysql_vars[]= {
{"have_backup_locks", &have_backup_locks_var}, {"have_backup_locks", &have_backup_locks_var},
{"log_bin", &log_bin_var}, {"log_bin", &log_bin_var},
{"lock_wait_timeout", &lock_wait_timeout_var}, {"lock_wait_timeout", &lock_wait_timeout_var},
...@@ -366,8 +366,7 @@ get_mysql_vars(MYSQL *connection) ...@@ -366,8 +366,7 @@ get_mysql_vars(MYSQL *connection)
{"wsrep_on", &wsrep_on_var}, {"wsrep_on", &wsrep_on_var},
{"slave_parallel_workers", &slave_parallel_workers_var}, {"slave_parallel_workers", &slave_parallel_workers_var},
{"gtid_slave_pos", &gtid_slave_pos_var}, {"gtid_slave_pos", &gtid_slave_pos_var},
{"innodb_buffer_pool_filename", {"innodb_buffer_pool_filename", &innodb_buffer_pool_filename_var},
&innodb_buffer_pool_filename_var},
{"datadir", &datadir_var}, {"datadir", &datadir_var},
{"innodb_log_group_home_dir", &innodb_log_group_home_dir_var}, {"innodb_log_group_home_dir", &innodb_log_group_home_dir_var},
{"innodb_log_file_size", &innodb_log_file_size_var}, {"innodb_log_file_size", &innodb_log_file_size_var},
...@@ -378,74 +377,88 @@ get_mysql_vars(MYSQL *connection) ...@@ -378,74 +377,88 @@ get_mysql_vars(MYSQL *connection)
{"innodb_page_size", &innodb_page_size_var}, {"innodb_page_size", &innodb_page_size_var},
{"innodb_undo_tablespaces", &innodb_undo_tablespaces_var}, {"innodb_undo_tablespaces", &innodb_undo_tablespaces_var},
{"innodb_compression_level", &page_zip_level_var}, {"innodb_compression_level", &page_zip_level_var},
{NULL, NULL} {"ignore_db_dirs", &ignore_db_dirs},
}; {NULL, NULL}};
read_mysql_variables(connection, "SHOW VARIABLES", read_mysql_variables(connection, "SHOW VARIABLES", mysql_vars, true);
mysql_vars, true);
if (have_backup_locks_var != NULL && !opt_no_backup_locks) { if (have_backup_locks_var != NULL && !opt_no_backup_locks)
have_backup_locks = true; {
have_backup_locks= true;
} }
if (opt_binlog_info == BINLOG_INFO_AUTO) { if (opt_binlog_info == BINLOG_INFO_AUTO)
{
if (log_bin_var != NULL && !strcmp(log_bin_var, "ON")) if (log_bin_var != NULL && !strcmp(log_bin_var, "ON"))
opt_binlog_info = BINLOG_INFO_ON; opt_binlog_info= BINLOG_INFO_ON;
else else
opt_binlog_info = BINLOG_INFO_OFF; opt_binlog_info= BINLOG_INFO_OFF;
} }
if (lock_wait_timeout_var != NULL) { if (lock_wait_timeout_var != NULL)
have_lock_wait_timeout = true; {
have_lock_wait_timeout= true;
} }
if (wsrep_on_var != NULL) { if (wsrep_on_var != NULL)
have_galera_enabled = true; {
have_galera_enabled= true;
} }
/* Check server version compatibility and detect server flavor */ /* Check server version compatibility and detect server flavor */
if (!(ret = check_server_version(server_version, version_var, if (!(ret= check_server_version(server_version, version_var,
version_comment_var, version_comment_var, innodb_version_var)))
innodb_version_var))) { {
goto out; goto out;
} }
if (server_version > 50500) { if (server_version > 50500)
have_flush_engine_logs = true; {
have_flush_engine_logs= true;
} }
if (slave_parallel_workers_var != NULL if (slave_parallel_workers_var != NULL &&
&& atoi(slave_parallel_workers_var) > 0) { atoi(slave_parallel_workers_var) > 0)
have_multi_threaded_slave = true; {
have_multi_threaded_slave= true;
} }
if (innodb_buffer_pool_filename_var != NULL) { if (innodb_buffer_pool_filename_var != NULL)
buffer_pool_filename = strdup(innodb_buffer_pool_filename_var); {
buffer_pool_filename= strdup(innodb_buffer_pool_filename_var);
} }
if ((gtid_mode_var && strcmp(gtid_mode_var, "ON") == 0) || if ((gtid_mode_var && strcmp(gtid_mode_var, "ON") == 0) ||
(gtid_slave_pos_var && *gtid_slave_pos_var)) { (gtid_slave_pos_var && *gtid_slave_pos_var))
have_gtid_slave = true; {
have_gtid_slave= true;
} }
msg("Using server version %s", version_var); msg("Using server version %s", version_var);
if (!(ret = detect_mysql_capabilities_for_backup())) { if (!(ret= detect_mysql_capabilities_for_backup()))
{
goto out; goto out;
} }
/* make sure datadir value is the same in configuration file */ /* make sure datadir value is the same in configuration file */
if (check_if_param_set("datadir")) { if (check_if_param_set("datadir"))
if (!directory_exists(mysql_data_home, false)) { {
if (!directory_exists(mysql_data_home, false))
{
msg("Warning: option 'datadir' points to " msg("Warning: option 'datadir' points to "
"nonexistent directory '%s'", mysql_data_home); "nonexistent directory '%s'",
mysql_data_home);
} }
if (!directory_exists(datadir_var, false)) { if (!directory_exists(datadir_var, false))
{
msg("Warning: MySQL variable 'datadir' points to " msg("Warning: MySQL variable 'datadir' points to "
"nonexistent directory '%s'", datadir_var); "nonexistent directory '%s'",
datadir_var);
} }
if (!equal_paths(mysql_data_home, datadir_var)) { if (!equal_paths(mysql_data_home, datadir_var))
{
msg("Warning: option 'datadir' has different " msg("Warning: option 'datadir' has different "
"values:\n" "values:\n"
" '%s' in defaults file\n" " '%s' in defaults file\n"
...@@ -455,65 +468,70 @@ get_mysql_vars(MYSQL *connection) ...@@ -455,65 +468,70 @@ get_mysql_vars(MYSQL *connection)
} }
/* get some default values is they are missing from my.cnf */ /* get some default values is they are missing from my.cnf */
if (datadir_var && *datadir_var) { if (datadir_var && *datadir_var)
{
strmake(mysql_real_data_home, datadir_var, FN_REFLEN - 1); strmake(mysql_real_data_home, datadir_var, FN_REFLEN - 1);
mysql_data_home= mysql_real_data_home; mysql_data_home= mysql_real_data_home;
} }
if (innodb_data_file_path_var && *innodb_data_file_path_var) { if (innodb_data_file_path_var && *innodb_data_file_path_var)
innobase_data_file_path = my_strdup( {
innodb_data_file_path_var, MYF(MY_FAE)); innobase_data_file_path= my_strdup(innodb_data_file_path_var, MYF(MY_FAE));
} }
if (innodb_data_home_dir_var) { if (innodb_data_home_dir_var)
innobase_data_home_dir = my_strdup( {
innodb_data_home_dir_var, MYF(MY_FAE)); innobase_data_home_dir= my_strdup(innodb_data_home_dir_var, MYF(MY_FAE));
} }
if (innodb_log_group_home_dir_var if (innodb_log_group_home_dir_var && *innodb_log_group_home_dir_var)
&& *innodb_log_group_home_dir_var) { {
srv_log_group_home_dir = my_strdup( srv_log_group_home_dir=
innodb_log_group_home_dir_var, MYF(MY_FAE)); my_strdup(innodb_log_group_home_dir_var, MYF(MY_FAE));
} }
if (innodb_undo_directory_var && *innodb_undo_directory_var) { if (innodb_undo_directory_var && *innodb_undo_directory_var)
srv_undo_dir = my_strdup( {
innodb_undo_directory_var, MYF(MY_FAE)); srv_undo_dir= my_strdup(innodb_undo_directory_var, MYF(MY_FAE));
} }
if (innodb_log_files_in_group_var) { if (innodb_log_files_in_group_var)
srv_n_log_files = strtol( {
innodb_log_files_in_group_var, &endptr, 10); srv_n_log_files= strtol(innodb_log_files_in_group_var, &endptr, 10);
ut_ad(*endptr == 0); ut_ad(*endptr == 0);
} }
if (innodb_log_file_size_var) { if (innodb_log_file_size_var)
srv_log_file_size = strtoll( {
innodb_log_file_size_var, &endptr, 10); srv_log_file_size= strtoll(innodb_log_file_size_var, &endptr, 10);
ut_ad(*endptr == 0); ut_ad(*endptr == 0);
} }
if (innodb_page_size_var) { if (innodb_page_size_var)
innobase_page_size = strtoll( {
innodb_page_size_var, &endptr, 10); innobase_page_size= strtoll(innodb_page_size_var, &endptr, 10);
ut_ad(*endptr == 0); ut_ad(*endptr == 0);
} }
if (innodb_undo_tablespaces_var) { if (innodb_undo_tablespaces_var)
srv_undo_tablespaces = strtoul(innodb_undo_tablespaces_var, {
&endptr, 10); srv_undo_tablespaces= strtoul(innodb_undo_tablespaces_var, &endptr, 10);
ut_ad(*endptr == 0); ut_ad(*endptr == 0);
} }
if (page_zip_level_var != NULL) { if (page_zip_level_var != NULL)
page_zip_level = strtoul(page_zip_level_var, &endptr, 10); {
page_zip_level= strtoul(page_zip_level_var, &endptr, 10);
ut_ad(*endptr == 0); ut_ad(*endptr == 0);
} }
if (ignore_db_dirs)
xb_load_list_string(ignore_db_dirs, ",", register_ignore_db_dirs_filter);
out: out:
free_mysql_variables(mysql_vars); free_mysql_variables(mysql_vars);
return(ret); return (ret);
} }
/*********************************************************************//** /*********************************************************************//**
......
...@@ -3632,6 +3632,11 @@ xb_register_exclude_filter_entry( ...@@ -3632,6 +3632,11 @@ xb_register_exclude_filter_entry(
&tables_exclude_hash); &tables_exclude_hash);
} }
void register_ignore_db_dirs_filter(const char *name)
{
xb_add_filter(name, &databases_exclude_hash);
}
/*********************************************************************** /***********************************************************************
Register new table for the filter. */ Register new table for the filter. */
static static
...@@ -3694,25 +3699,23 @@ xb_register_exclude_regex( ...@@ -3694,25 +3699,23 @@ xb_register_exclude_regex(
typedef void (*insert_entry_func_t)(const char*); typedef void (*insert_entry_func_t)(const char*);
/*********************************************************************** /* Scan string and load filter entries from it.
Scan string and load filter entries from it. */ @param[in] list string representing a list
static @param[in] delimiters delimiters of entries
void @param[in] ins callback to add entry */
xb_load_list_string( void xb_load_list_string(char *list, const char *delimiters,
/*================*/ insert_entry_func_t ins)
char* list, /*!< in: string representing a list */
const char* delimiters, /*!< in: delimiters of entries */
insert_entry_func_t ins) /*!< in: callback to add entry */
{ {
char* p; char *p;
char* saveptr; char *saveptr;
p = strtok_r(list, delimiters, &saveptr); p= strtok_r(list, delimiters, &saveptr);
while (p) { while (p)
{
ins(p); ins(p);
p = strtok_r(NULL, delimiters, &saveptr); p= strtok_r(NULL, delimiters, &saveptr);
} }
} }
......
...@@ -194,4 +194,14 @@ void mdl_lock_init(); ...@@ -194,4 +194,14 @@ void mdl_lock_init();
void mdl_lock_table(ulint space_id); void mdl_lock_table(ulint space_id);
void mdl_unlock_all(); void mdl_unlock_all();
bool ends_with(const char *str, const char *suffix); bool ends_with(const char *str, const char *suffix);
typedef void (*insert_entry_func_t)(const char*);
/* Scan string and load filter entries from it.
@param[in] list string representing a list
@param[in] delimiters delimiters of entries
@param[in] ins callback to add entry */
void xb_load_list_string(char *list, const char *delimiters,
insert_entry_func_t ins);
void register_ignore_db_dirs_filter(const char *name);
#endif /* XB_XTRABACKUP_H */ #endif /* XB_XTRABACKUP_H */
--ignore-db-dirs=db3
--ignore-db-dirs=db4
select @@ignore_db_dirs;
@@ignore_db_dirs
db3,db4
CREATE TABLE t1(i INT) ENGINE INNODB; CREATE TABLE t1(i INT) ENGINE INNODB;
INSERT INTO t1 VALUES(1); INSERT INTO t1 VALUES(1);
CREATE TABLE t2(i int) ENGINE INNODB; CREATE TABLE t2(i int) ENGINE INNODB;
......
#--source include/innodb_page_size.inc #--source include/innodb_page_size.inc
# Test --databases-exclude and --tables-exclude feature of xtrabackup 2.3.8 # Test --databases-exclude and --tables-exclude feature of xtrabackup 2.3.8
select @@ignore_db_dirs;
let $MYSQLD_DATADIR= `select @@datadir`;
mkdir $MYSQLD_DATADIR/db3;
mkdir $MYSQLD_DATADIR/db4;
mkdir $MYSQLD_DATADIR/db5;
CREATE TABLE t1(i INT) ENGINE INNODB; CREATE TABLE t1(i INT) ENGINE INNODB;
INSERT INTO t1 VALUES(1); INSERT INTO t1 VALUES(1);
...@@ -24,8 +31,19 @@ list_files $targetdir/test *.ibd; ...@@ -24,8 +31,19 @@ list_files $targetdir/test *.ibd;
# check that db2 database is not in the backup (excluded) # check that db2 database is not in the backup (excluded)
--error 1 --error 1
list_files $targetdir/db2 *.ibd; list_files $targetdir/db2 *.ibd;
# check that db3 database is not in the backup (excluded)
--error 1
list_files $targetdir/db3 *.ibd;
# check that db4 database is not in the backup (excluded)
--error 1
list_files $targetdir/db4 *.ibd;
# check that db5 database is in the backup
list_files $targetdir/db5 *.ibd;
DROP TABLE t1; DROP TABLE t1;
DROP TABLE t2; DROP TABLE t2;
DROP DATABASE db2; DROP DATABASE db2;
rmdir $MYSQLD_DATADIR/db3;
rmdir $MYSQLD_DATADIR/db4;
rmdir $MYSQLD_DATADIR/db5;
rmdir $targetdir; rmdir $targetdir;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment