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,
/*********************************************************************//**
Receive options important for XtraBackup from MySQL server.
@return true on success. */
bool
get_mysql_vars(MYSQL *connection)
bool get_mysql_vars(MYSQL *connection)
{
char *gtid_mode_var = NULL;
char *version_var = NULL;
char *version_comment_var = NULL;
char *innodb_version_var = NULL;
char *have_backup_locks_var = NULL;
char *log_bin_var = NULL;
char *gtid_mode_var= NULL;
char *version_var= NULL;
char *version_comment_var= NULL;
char *innodb_version_var= NULL;
char *have_backup_locks_var= NULL;
char *log_bin_var= NULL;
char *lock_wait_timeout_var= NULL;
char *wsrep_on_var = NULL;
char *slave_parallel_workers_var = NULL;
char *gtid_slave_pos_var = NULL;
char *innodb_buffer_pool_filename_var = NULL;
char *datadir_var = NULL;
char *innodb_log_group_home_dir_var = NULL;
char *innodb_log_file_size_var = NULL;
char *innodb_log_files_in_group_var = NULL;
char *innodb_data_file_path_var = NULL;
char *innodb_data_home_dir_var = NULL;
char *innodb_undo_directory_var = NULL;
char *innodb_page_size_var = NULL;
char *innodb_undo_tablespaces_var = NULL;
char *page_zip_level_var = NULL;
char *wsrep_on_var= NULL;
char *slave_parallel_workers_var= NULL;
char *gtid_slave_pos_var= NULL;
char *innodb_buffer_pool_filename_var= NULL;
char *datadir_var= NULL;
char *innodb_log_group_home_dir_var= NULL;
char *innodb_log_file_size_var= NULL;
char *innodb_log_files_in_group_var= NULL;
char *innodb_data_file_path_var= NULL;
char *innodb_data_home_dir_var= NULL;
char *innodb_undo_directory_var= NULL;
char *innodb_page_size_var= NULL;
char *innodb_undo_tablespaces_var= NULL;
char *page_zip_level_var= NULL;
char *ignore_db_dirs= NULL;
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},
{"log_bin", &log_bin_var},
{"lock_wait_timeout", &lock_wait_timeout_var},
......@@ -366,8 +366,7 @@ get_mysql_vars(MYSQL *connection)
{"wsrep_on", &wsrep_on_var},
{"slave_parallel_workers", &slave_parallel_workers_var},
{"gtid_slave_pos", &gtid_slave_pos_var},
{"innodb_buffer_pool_filename",
&innodb_buffer_pool_filename_var},
{"innodb_buffer_pool_filename", &innodb_buffer_pool_filename_var},
{"datadir", &datadir_var},
{"innodb_log_group_home_dir", &innodb_log_group_home_dir_var},
{"innodb_log_file_size", &innodb_log_file_size_var},
......@@ -378,74 +377,88 @@ get_mysql_vars(MYSQL *connection)
{"innodb_page_size", &innodb_page_size_var},
{"innodb_undo_tablespaces", &innodb_undo_tablespaces_var},
{"innodb_compression_level", &page_zip_level_var},
{NULL, NULL}
};
{"ignore_db_dirs", &ignore_db_dirs},
{NULL, NULL}};
read_mysql_variables(connection, "SHOW VARIABLES",
mysql_vars, true);
read_mysql_variables(connection, "SHOW VARIABLES", mysql_vars, true);
if (have_backup_locks_var != NULL && !opt_no_backup_locks) {
have_backup_locks = true;
if (have_backup_locks_var != NULL && !opt_no_backup_locks)
{
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"))
opt_binlog_info = BINLOG_INFO_ON;
opt_binlog_info= BINLOG_INFO_ON;
else
opt_binlog_info = BINLOG_INFO_OFF;
opt_binlog_info= BINLOG_INFO_OFF;
}
if (lock_wait_timeout_var != NULL) {
have_lock_wait_timeout = true;
if (lock_wait_timeout_var != NULL)
{
have_lock_wait_timeout= true;
}
if (wsrep_on_var != NULL) {
have_galera_enabled = true;
if (wsrep_on_var != NULL)
{
have_galera_enabled= true;
}
/* Check server version compatibility and detect server flavor */
if (!(ret = check_server_version(server_version, version_var,
version_comment_var,
innodb_version_var))) {
if (!(ret= check_server_version(server_version, version_var,
version_comment_var, innodb_version_var)))
{
goto out;
}
if (server_version > 50500) {
have_flush_engine_logs = true;
if (server_version > 50500)
{
have_flush_engine_logs= true;
}
if (slave_parallel_workers_var != NULL
&& atoi(slave_parallel_workers_var) > 0) {
have_multi_threaded_slave = true;
if (slave_parallel_workers_var != NULL &&
atoi(slave_parallel_workers_var) > 0)
{
have_multi_threaded_slave= true;
}
if (innodb_buffer_pool_filename_var != NULL) {
buffer_pool_filename = strdup(innodb_buffer_pool_filename_var);
if (innodb_buffer_pool_filename_var != NULL)
{
buffer_pool_filename= strdup(innodb_buffer_pool_filename_var);
}
if ((gtid_mode_var && strcmp(gtid_mode_var, "ON") == 0) ||
(gtid_slave_pos_var && *gtid_slave_pos_var)) {
have_gtid_slave = true;
(gtid_slave_pos_var && *gtid_slave_pos_var))
{
have_gtid_slave= true;
}
msg("Using server version %s", version_var);
if (!(ret = detect_mysql_capabilities_for_backup())) {
if (!(ret= detect_mysql_capabilities_for_backup()))
{
goto out;
}
/* make sure datadir value is the same in configuration file */
if (check_if_param_set("datadir")) {
if (!directory_exists(mysql_data_home, false)) {
if (check_if_param_set("datadir"))
{
if (!directory_exists(mysql_data_home, false))
{
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 "
"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 "
"values:\n"
" '%s' in defaults file\n"
......@@ -455,65 +468,70 @@ get_mysql_vars(MYSQL *connection)
}
/* 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);
mysql_data_home= mysql_real_data_home;
}
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));
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));
}
if (innodb_data_home_dir_var) {
innobase_data_home_dir = my_strdup(
innodb_data_home_dir_var, MYF(MY_FAE));
if (innodb_data_home_dir_var)
{
innobase_data_home_dir= my_strdup(innodb_data_home_dir_var, MYF(MY_FAE));
}
if (innodb_log_group_home_dir_var
&& *innodb_log_group_home_dir_var) {
srv_log_group_home_dir = my_strdup(
innodb_log_group_home_dir_var, MYF(MY_FAE));
if (innodb_log_group_home_dir_var && *innodb_log_group_home_dir_var)
{
srv_log_group_home_dir=
my_strdup(innodb_log_group_home_dir_var, MYF(MY_FAE));
}
if (innodb_undo_directory_var && *innodb_undo_directory_var) {
srv_undo_dir = my_strdup(
innodb_undo_directory_var, MYF(MY_FAE));
if (innodb_undo_directory_var && *innodb_undo_directory_var)
{
srv_undo_dir= my_strdup(innodb_undo_directory_var, MYF(MY_FAE));
}
if (innodb_log_files_in_group_var) {
srv_n_log_files = strtol(
innodb_log_files_in_group_var, &endptr, 10);
if (innodb_log_files_in_group_var)
{
srv_n_log_files= strtol(innodb_log_files_in_group_var, &endptr, 10);
ut_ad(*endptr == 0);
}
if (innodb_log_file_size_var) {
srv_log_file_size = strtoll(
innodb_log_file_size_var, &endptr, 10);
if (innodb_log_file_size_var)
{
srv_log_file_size= strtoll(innodb_log_file_size_var, &endptr, 10);
ut_ad(*endptr == 0);
}
if (innodb_page_size_var) {
innobase_page_size = strtoll(
innodb_page_size_var, &endptr, 10);
if (innodb_page_size_var)
{
innobase_page_size= strtoll(innodb_page_size_var, &endptr, 10);
ut_ad(*endptr == 0);
}
if (innodb_undo_tablespaces_var) {
srv_undo_tablespaces = strtoul(innodb_undo_tablespaces_var,
&endptr, 10);
if (innodb_undo_tablespaces_var)
{
srv_undo_tablespaces= strtoul(innodb_undo_tablespaces_var, &endptr, 10);
ut_ad(*endptr == 0);
}
if (page_zip_level_var != NULL) {
page_zip_level = strtoul(page_zip_level_var, &endptr, 10);
if (page_zip_level_var != NULL)
{
page_zip_level= strtoul(page_zip_level_var, &endptr, 10);
ut_ad(*endptr == 0);
}
if (ignore_db_dirs)
xb_load_list_string(ignore_db_dirs, ",", register_ignore_db_dirs_filter);
out:
free_mysql_variables(mysql_vars);
return(ret);
return (ret);
}
/*********************************************************************//**
......
......@@ -3632,6 +3632,11 @@ xb_register_exclude_filter_entry(
&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. */
static
......@@ -3694,25 +3699,23 @@ xb_register_exclude_regex(
typedef void (*insert_entry_func_t)(const char*);
/***********************************************************************
Scan string and load filter entries from it. */
static
void
xb_load_list_string(
/*================*/
char* list, /*!< in: string representing a list */
const char* delimiters, /*!< in: delimiters of entries */
insert_entry_func_t ins) /*!< in: callback to add entry */
/* 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)
{
char* p;
char* saveptr;
char *p;
char *saveptr;
p = strtok_r(list, delimiters, &saveptr);
while (p) {
p= strtok_r(list, delimiters, &saveptr);
while (p)
{
ins(p);
p = strtok_r(NULL, delimiters, &saveptr);
p= strtok_r(NULL, delimiters, &saveptr);
}
}
......
......@@ -194,4 +194,14 @@ void mdl_lock_init();
void mdl_lock_table(ulint space_id);
void mdl_unlock_all();
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 */
--ignore-db-dirs=db3
--ignore-db-dirs=db4
select @@ignore_db_dirs;
@@ignore_db_dirs
db3,db4
CREATE TABLE t1(i INT) ENGINE INNODB;
INSERT INTO t1 VALUES(1);
CREATE TABLE t2(i int) ENGINE INNODB;
......
#--source include/innodb_page_size.inc
# 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;
INSERT INTO t1 VALUES(1);
......@@ -24,8 +31,19 @@ list_files $targetdir/test *.ibd;
# check that db2 database is not in the backup (excluded)
--error 1
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 t2;
DROP DATABASE db2;
rmdir $MYSQLD_DATADIR/db3;
rmdir $MYSQLD_DATADIR/db4;
rmdir $MYSQLD_DATADIR/db5;
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