1
0
mirror of https://github.com/MariaDB/server.git synced 2026-01-06 05:22:24 +03:00

MDEV-15780 : Mariabackup with absolute paths in innodb_data_file_path

System tablespace can be specified with absolute path, if innodb_data_home_dir
is empty.

This was not handled well  by mariabackup

1. In backup phase, empty innodb_data_home_dir variable from server was
not recognized. full paths were stored in backup-my.ini, even if
it stored all files locally. thus prepare phase would not find the system
tablespace files.

2. In copy-back phase, copy would not be done to the absolute destination
path, as path would be stripped with trim_dotslash

This patch fixes the above defects.
This commit is contained in:
Vladislav Vaintroub
2018-04-11 23:07:23 +01:00
parent 0ae13b51d7
commit 15071226a0
5 changed files with 86 additions and 4 deletions

View File

@@ -975,6 +975,9 @@ copy_file(ds_ctxt_t *datasink,
datafile_cur_t cursor;
xb_fil_cur_result_t res;
const char *action;
const char *dst_path =
(xtrabackup_copy_back || xtrabackup_move_back)?
dst_file_path : trim_dotslash(dst_file_path);
if (!datafile_open(src_file_path, &cursor, thread_n)) {
goto error_close;
@@ -982,8 +985,7 @@ copy_file(ds_ctxt_t *datasink,
strncpy(dst_name, cursor.rel_path, sizeof(dst_name));
dstfile = ds_open(datasink, trim_dotslash(dst_file_path),
&cursor.statinfo);
dstfile = ds_open(datasink, dst_path, &cursor.statinfo);
if (dstfile == NULL) {
msg("[%02u] error: "
"cannot open the destination stream for %s\n",

View File

@@ -477,7 +477,7 @@ get_mysql_vars(MYSQL *connection)
innodb_data_file_path_var, MYF(MY_FAE));
}
if (innodb_data_home_dir_var && *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));
}
@@ -1521,6 +1521,44 @@ cleanup:
extern const char *innodb_checksum_algorithm_names[];
#ifdef _WIN32
#include <algorithm>
#endif
static std::string make_local_paths(const char *data_file_path)
{
if (strchr(data_file_path, '/') == 0
#ifdef _WIN32
&& strchr(data_file_path, '\\') == 0
#endif
){
return std::string(data_file_path);
}
std::ostringstream buf;
char *dup = strdup(innobase_data_file_path);
ut_a(dup);
char *p;
char * token = strtok_r(dup, ";", &p);
while (token) {
if (buf.tellp())
buf << ";";
char *fname = strrchr(token, '/');
#ifdef _WIN32
fname = std::max(fname,strrchr(token, '\\'));
#endif
if (fname)
buf << fname + 1;
else
buf << token;
token = strtok_r(NULL, ";", &p);
}
free(dup);
return buf.str();
}
bool write_backup_config_file()
{
int rc= backup_file_printf("backup-my.cnf",
@@ -1541,7 +1579,7 @@ bool write_backup_config_file()
"%s\n",
innodb_checksum_algorithm_names[srv_checksum_algorithm],
innodb_checksum_algorithm_names[srv_log_checksum_algorithm],
innobase_data_file_path,
make_local_paths(innobase_data_file_path).c_str(),
srv_n_log_files,
innobase_log_file_size,
srv_page_size,

View File

@@ -0,0 +1 @@
--innodb --innodb-data-home-dir= --innodb-data-file-path=$MYSQLTEST_VARDIR/tmp/absolute_path_ibdata1:3M;ibdata_second:1M:autoextend

View File

@@ -0,0 +1,10 @@
CREATE TABLE t(i INT) ENGINE INNODB;
INSERT INTO t VALUES(1);
# xtrabackup backup
# remove datadir
# xtrabackup copy back
# restart server
SELECT * from t;
i
1
DROP TABLE t;

View File

@@ -0,0 +1,31 @@
# This test just backs up and restores empty database
# Innodb system tablespace is specified with absolute path in the .opt file
CREATE TABLE t(i INT) ENGINE INNODB;
INSERT INTO t VALUES(1);
echo # xtrabackup backup;
let $targetdir=$MYSQLTEST_VARDIR/tmp/backup;
let $_innodb_data_file_path=`select @@innodb_data_file_path`;
let $_innodb_data_home_dir=`select @@innodb_data_home_dir`;
let $_datadir= `SELECT @@datadir`;
--disable_result_log
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$targetdir;
--enable_result_log
exec $XTRABACKUP --prepare --target-dir=$targetdir;
--source include/shutdown_mysqld.inc
echo # remove datadir;
rmdir $_datadir;
#remove out-of-datadir ibdata1
remove_file $MYSQLTEST_VARDIR/tmp/absolute_path_ibdata1;
echo # xtrabackup copy back;
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --copy-back --datadir=$_datadir --target-dir=$targetdir "--innodb_data_file_path=$_innodb_data_file_path" --innodb_data_home_dir=$_innodb_data_home_dir;
echo # restart server;
--source include/start_mysqld.inc
--enable_result_log
SELECT * from t;
DROP TABLE t;
rmdir $targetdir;