Commit 209864c7 authored by Vlad Lesin's avatar Vlad Lesin

MDEV-18215: mariabackup does not report unknown command line options

MDEV-21298: mariabackup doesn't read from the [mariadbd] and [mariadbd-X.Y]
server option groups from configuration files
MDEV-21301: mariabackup doesn't read [mariadb-backup] option group in
configuration file

All three issues require to change the same code, that is why their
fixes are joined in one commit.

The fix is in invoking load_defaults_or_exit() and handle_options() for
backup-specific groups separately from client-server groups to let the last
handle_options() call fail on unknown backup-specific options.

The option values from backup-specific groups can overwrite option
values from client-server groups.

The MTR tests which contained not supported options are also fixed.
parent 86c50a25
......@@ -1617,24 +1617,11 @@ static int prepare_export()
return err;
}
static const char *xb_client_default_groups[]= {
"client", "client-server", "client-mariadb", "mariadb-client", 0, 0, 0};
static const char *xb_client_default_groups[]={
"xtrabackup", "mariabackup",
"client", "client-server",
"client-mariadb",
0, 0, 0
};
static const char *xb_server_default_groups[]={
"xtrabackup", "mariabackup",
"mysqld", "server", MYSQL_BASE_VERSION,
"mariadb", MARIADB_BASE_VERSION,
"client-server",
#ifdef WITH_WSREP
"galera",
#endif
0, 0, 0
};
static const char *backup_default_groups[]= {
"xtrabackup", "mariabackup", "mariadb-backup", 0, 0, 0};
static void print_version(void)
{
......@@ -1662,7 +1649,7 @@ GNU General Public License for more details.\n\
You can download full text of the license on http://www.gnu.org/licenses/gpl-2.0.txt\n");
printf("Usage: %s [--defaults-file=#] [--backup | --prepare | --copy-back | --move-back] [OPTIONS]\n",my_progname);
print_defaults("my", xb_server_default_groups);
print_defaults("my", load_default_groups);
my_print_help(xb_client_options);
my_print_help(xb_server_options);
my_print_variables(xb_server_options);
......@@ -5990,11 +5977,10 @@ void setup_error_messages()
die("could not initialize error messages");
}
void
handle_options(int argc, char **argv, char ***argv_client, char ***argv_server)
void handle_options(int argc, char **argv, char ***argv_server,
char ***argv_client, char ***argv_backup)
{
/* Setup some variables for Innodb.*/
srv_operation = SRV_OPERATION_RESTORE;
files_charset_info = &my_charset_utf8_general_ci;
......@@ -6023,8 +6009,18 @@ handle_options(int argc, char **argv, char ***argv_client, char ***argv_server)
char conf_file[FN_REFLEN];
int argc_client = argc;
int argc_server = argc;
int argc_backup= argc;
/* scan options for group and config file to load defaults from */
// array_elements() will not work for load_defaults, as it is defined
// as external symbol, so let's use dynamic array to have ability to
// add new server default groups
std::vector<const char *> server_default_groups;
for (const char **default_group= load_default_groups; *default_group;
++default_group)
server_default_groups.push_back(*default_group);
/* scan options for group and config file to load defaults from */
for (i = 1; i < argc; i++) {
char *optend = strcend(argv[i], '=');
......@@ -6032,9 +6028,7 @@ handle_options(int argc, char **argv, char ***argv_client, char ***argv_server)
if (strncmp(argv[i], "--defaults-group",
optend - argv[i]) == 0) {
defaults_group = optend + 1;
append_defaults_group(defaults_group,
xb_server_default_groups,
array_elements(xb_server_default_groups));
server_default_groups.push_back(defaults_group);
}
if (strncmp(argv[i], "--login-path",
......@@ -6064,6 +6058,7 @@ handle_options(int argc, char **argv, char ***argv_client, char ***argv_server)
}
}
server_default_groups.push_back(NULL);
snprintf(conf_file, sizeof(conf_file), "my");
if (prepare && target_dir) {
......@@ -6081,8 +6076,10 @@ handle_options(int argc, char **argv, char ***argv_client, char ***argv_server)
*argv_client = argv;
*argv_server = argv;
load_defaults_or_exit(conf_file, xb_server_default_groups,
&argc_server, argv_server);
*argv_backup = argv;
load_defaults_or_exit(conf_file, &server_default_groups[0],
&argc_server, argv_server);
int n;
for (n = 0; (*argv_server)[n]; n++) {};
......@@ -6131,8 +6128,6 @@ handle_options(int argc, char **argv, char ***argv_client, char ***argv_server)
argc_client = n;
if (innobackupex_mode && argc_client > 0) {
/* emulate innobackupex script */
innobackupex_mode = true;
if (!ibx_handle_options(&argc_client, argv_client)) {
exit(EXIT_FAILURE);
}
......@@ -6143,18 +6138,50 @@ handle_options(int argc, char **argv, char ***argv_client, char ***argv_server)
xb_client_options, xb_get_one_option)))
exit(ho_error);
load_defaults_or_exit(conf_file, backup_default_groups, &argc_backup,
argv_backup);
for (n= 0; (*argv_backup)[n]; n++)
{
};
argc_backup= n;
my_handle_options_init_variables = FALSE;
if (argc_backup > 0 &&
(ho_error= handle_options(&argc_backup, argv_backup,
xb_server_options, xb_get_one_option)))
exit(ho_error);
/* Add back the program name handle_options removes */
++argc_backup;
--(*argv_backup);
if (innobackupex_mode && argc_backup > 0 &&
!ibx_handle_options(&argc_backup, argv_backup))
exit(EXIT_FAILURE);
my_getopt_skip_unknown = FALSE;
if (argc_backup > 0 &&
(ho_error= handle_options(&argc_backup, argv_backup,
xb_client_options, xb_get_one_option)))
exit(ho_error);
my_getopt_skip_unknown = TRUE;
my_handle_options_init_variables = TRUE;
/* Reject command line arguments that don't look like options, i.e. are
not of the form '-X' (single-character options) or '--option' (long
options) */
for (int i = 0 ; i < argc_client ; i++) {
const char * const opt = (*argv_client)[i];
for (int i = 0 ; i < argc_backup ; i++) {
const char * const opt = (*argv_backup)[i];
if (strncmp(opt, "--", 2) &&
!(strlen(opt) == 2 && opt[0] == '-')) {
bool server_option = true;
for (int j = 0; j < argc_server; j++) {
if (opt == (*argv_server)[j]) {
for (int j = 0; j < argc_backup; j++) {
if (opt == (*argv_backup)[j]) {
server_option = false;
break;
}
......@@ -6175,7 +6202,9 @@ static int get_exepath(char *buf, size_t size, const char *argv0);
/* ================= main =================== */
int main(int argc, char **argv)
{
char **client_defaults, **server_defaults;
char **server_defaults;
char **client_defaults;
char **backup_defaults;
if (get_exepath(mariabackup_exe,FN_REFLEN, argv[0]))
strncpy(mariabackup_exe,argv[0], FN_REFLEN-1);
......@@ -6229,7 +6258,8 @@ int main(int argc, char **argv)
mysql_mutex_init(key_LOCK_error_log, &LOCK_error_log,
MY_MUTEX_INIT_FAST);
handle_options(argc, argv, &client_defaults, &server_defaults);
handle_options(argc, argv, &server_defaults, &client_defaults,
&backup_defaults);
#ifndef DBUG_OFF
if (dbug_option) {
......@@ -6246,8 +6276,9 @@ int main(int argc, char **argv)
ibx_cleanup();
}
free_defaults(client_defaults);
free_defaults(server_defaults);
free_defaults(client_defaults);
free_defaults(backup_defaults);
#ifndef DBUG_OFF
if (dbug_option) {
......
......@@ -106,6 +106,7 @@ extern char *autoset_my_option;
extern my_bool my_getopt_print_errors;
extern my_bool my_getopt_skip_unknown;
extern my_bool my_getopt_prefix_matching;
extern my_bool my_handle_options_init_variables;
extern my_error_reporter my_getopt_error_reporter;
extern int handle_options (int *argc, char ***argv,
......
......@@ -36,7 +36,7 @@ connection default;
--disable_result_log
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --ftwrl-wait-timeout=5 --ftwrl-wait-threshold=300 --ftwrl-wait-query-type=all --target-dir=$incremental_dir --incremental-basedir=$basedir ;
exec $XTRABACKUP --prepare --verbose --apply-log-only --target-dir=$basedir ;
exec $XTRABACKUP --prepare --verbose --target-dir=$basedir ;
--enable_result_log
let SEARCH_FILE=$MYSQLTEST_VARDIR/log/current_test;
......@@ -44,7 +44,7 @@ let SEARCH_FILE=$MYSQLTEST_VARDIR/log/current_test;
--source include/search_pattern_in_file.inc
--echo # expect NOT FOUND
exec $XTRABACKUP --prepare --verbose --apply-log-only --target-dir=$basedir --incremental-dir=$incremental_dir ;
exec $XTRABACKUP --prepare --verbose --target-dir=$basedir --incremental-dir=$incremental_dir ;
--source include/search_pattern_in_file.inc
--echo # expect NOT FOUND
......
......@@ -11,7 +11,7 @@ INSERT INTO t VALUES(1);
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$basedir;
--enable_result_log
exec $XTRABACKUP --prepare --apply-log-only --target-dir=$basedir ;
exec $XTRABACKUP --prepare --target-dir=$basedir ;
let SEARCH_FILE=$MYSQLTEST_VARDIR/log/current_test;
--let SEARCH_PATTERN= Rolled back recovered transaction
......
......@@ -12,7 +12,7 @@ SHOW VARIABLES like 'log_bin';
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$basedir;
--enable_result_log
exec $XTRABACKUP --prepare --binlog-info=1 --apply-log-only --target-dir=$basedir ;
exec $XTRABACKUP --prepare --binlog-info=1 --target-dir=$basedir ;
let SEARCH_FILE=$MYSQLTEST_VARDIR/log/current_test;
--let SEARCH_PATTERN= Last binlog file .*, position .*
......
......@@ -33,7 +33,7 @@ select count(*) from t7;
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$incremental_dir --incremental-basedir=$basedir;
--echo # XTRABACKUP PREPARE
exec $XTRABACKUP --apply-log-only --prepare --target-dir=$basedir;
exec $XTRABACKUP --prepare --target-dir=$basedir;
--echo # XTRABACKUP INCREMENTAL PREPARE
exec $XTRABACKUP --prepare --target-dir=$basedir --incremental-dir=$incremental_dir;
......
......@@ -25,7 +25,7 @@ exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir
--let after_load_tablespaces=
--disable_result_log
echo # Prepare full backup, apply incremental one;
exec $XTRABACKUP --apply-log-only --prepare --target-dir=$basedir;
exec $XTRABACKUP --prepare --target-dir=$basedir;
exec $XTRABACKUP --prepare --target-dir=$basedir --incremental-dir=$incremental_dir ;
echo # Restore and check results;
......
# Check for unknown options in command-line
# Check for unknown options in "mariabackup" group
# Check for unknown options in "xtrabackup" group
# Check for unknown options in "mariadb-backup" group
# Check for options overwriting
--let $targetdir=$MYSQLTEST_VARDIR/tmp/backup
--let $custom_cnf=$MYSQLTEST_VARDIR/tmp/custom_my.cnf
--echo # Check for unknown options in command-line
--disable_result_log
--error 7
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --unknown-option=xxx --target-dir=$targetdir;
--error 2
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --unknown-option --target-dir=$targetdir;
--enable_result_log
--echo # Check for unknown options in "mariabackup" group
--write_file $custom_cnf
[mariabackup]
unknown-option=XXX
EOF
--error 7
exec $XTRABACKUP --defaults-file=$custom_cnf --backup --target-dir=$targetdir;
--remove_file $custom_cnf
--echo # Check for unknown options in "xtrabackup" group
--write_file $custom_cnf
[xtrabackup]
unknown-option=XXX
EOF
--error 7
exec $XTRABACKUP --defaults-file=$custom_cnf --backup --target-dir=$targetdir;
--remove_file $custom_cnf
--echo # Check for unknown options in "mariadb-backup" group
--write_file $custom_cnf
[mariadb-backup]
unknown-option=XXX
EOF
--error 7
exec $XTRABACKUP --defaults-file=$custom_cnf --backup --target-dir=$targetdir;
--remove_file $custom_cnf
--echo # Check for options overwriting
--write_file $custom_cnf
[mariadbd]
innodb-flush-method=O_DIRECT
[mariabackup]
innodb-flush-method=blablabla
EOF
--error 13
exec $XTRABACKUP --defaults-file=$custom_cnf --backup --target-dir=$targetdir;
--remove_file $custom_cnf
......@@ -17,7 +17,7 @@ exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir
list_files $basedir undo*;
--echo # xtrabackup prepare
exec $XTRABACKUP --prepare --apply-log-only --target-dir=$basedir;
exec $XTRABACKUP --prepare --target-dir=$basedir;
--echo # Display undo log files from targer directory
list_files $basedir undo*;
......
......@@ -16,7 +16,7 @@ let $targetdir=$MYSQLTEST_VARDIR/tmp/backup;
--disable_result_log
exec $INNOBACKUPEX --defaults-file=$MYSQLTEST_VARDIR/my.cnf --no-timestamp $targetdir;
exec $INNOBACKUPEX --apply-log --rebuild-indexes --rebuild-threads=2 $targetdir;
exec $INNOBACKUPEX --apply-log $targetdir;
--source include/restart_and_restore.inc
--enable_result_log
......
......@@ -38,7 +38,7 @@ INSERT INTO isam_p VALUES (1), (101), (201), (301);
let $targetdir=$MYSQLTEST_VARDIR/tmp;
--disable_result_log
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --no-timestamp --backup --target-dir=$targetdir/full;
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$targetdir/full;
--enable_result_log
DROP TABLE t1;
......
......@@ -79,6 +79,12 @@ my_bool my_getopt_skip_unknown= 0;
*/
my_bool my_getopt_prefix_matching= 1;
/*
This is a flag that can be set in client programs. 1 means that
handle_options() will not initialize options to default values.
*/
my_bool my_handle_options_init_variables = 1;
static void default_reporter(enum loglevel level,
const char *format, ...)
{
......@@ -212,7 +218,8 @@ int handle_options(int *argc, char ***argv,
DBUG_ASSERT(argv && *argv);
(*argc)--; /* Skip the program name */
(*argv)++; /* --- || ---- */
init_variables(longopts, init_one_value);
if (my_handle_options_init_variables)
init_variables(longopts, init_one_value);
/*
Search for args_separator, if found, then the first part of the
......
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