Skip to content

Commit 1507122

Browse files
committed
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.
1 parent 0ae13b5 commit 1507122

File tree

5 files changed

+86
-4
lines changed

5 files changed

+86
-4
lines changed

extra/mariabackup/backup_copy.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,15 +975,17 @@ copy_file(ds_ctxt_t *datasink,
975975
datafile_cur_t cursor;
976976
xb_fil_cur_result_t res;
977977
const char *action;
978+
const char *dst_path =
979+
(xtrabackup_copy_back || xtrabackup_move_back)?
980+
dst_file_path : trim_dotslash(dst_file_path);
978981

979982
if (!datafile_open(src_file_path, &cursor, thread_n)) {
980983
goto error_close;
981984
}
982985

983986
strncpy(dst_name, cursor.rel_path, sizeof(dst_name));
984987

985-
dstfile = ds_open(datasink, trim_dotslash(dst_file_path),
986-
&cursor.statinfo);
988+
dstfile = ds_open(datasink, dst_path, &cursor.statinfo);
987989
if (dstfile == NULL) {
988990
msg("[%02u] error: "
989991
"cannot open the destination stream for %s\n",

extra/mariabackup/backup_mysql.cc

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ get_mysql_vars(MYSQL *connection)
477477
innodb_data_file_path_var, MYF(MY_FAE));
478478
}
479479

480-
if (innodb_data_home_dir_var && *innodb_data_home_dir_var) {
480+
if (innodb_data_home_dir_var) {
481481
innobase_data_home_dir = my_strdup(
482482
innodb_data_home_dir_var, MYF(MY_FAE));
483483
}
@@ -1521,6 +1521,44 @@ write_xtrabackup_info(MYSQL *connection)
15211521

15221522
extern const char *innodb_checksum_algorithm_names[];
15231523

1524+
#ifdef _WIN32
1525+
#include <algorithm>
1526+
#endif
1527+
1528+
static std::string make_local_paths(const char *data_file_path)
1529+
{
1530+
if (strchr(data_file_path, '/') == 0
1531+
#ifdef _WIN32
1532+
&& strchr(data_file_path, '\\') == 0
1533+
#endif
1534+
){
1535+
return std::string(data_file_path);
1536+
}
1537+
1538+
std::ostringstream buf;
1539+
1540+
char *dup = strdup(innobase_data_file_path);
1541+
ut_a(dup);
1542+
char *p;
1543+
char * token = strtok_r(dup, ";", &p);
1544+
while (token) {
1545+
if (buf.tellp())
1546+
buf << ";";
1547+
1548+
char *fname = strrchr(token, '/');
1549+
#ifdef _WIN32
1550+
fname = std::max(fname,strrchr(token, '\\'));
1551+
#endif
1552+
if (fname)
1553+
buf << fname + 1;
1554+
else
1555+
buf << token;
1556+
token = strtok_r(NULL, ";", &p);
1557+
}
1558+
free(dup);
1559+
return buf.str();
1560+
}
1561+
15241562
bool write_backup_config_file()
15251563
{
15261564
int rc= backup_file_printf("backup-my.cnf",
@@ -1541,7 +1579,7 @@ bool write_backup_config_file()
15411579
"%s\n",
15421580
innodb_checksum_algorithm_names[srv_checksum_algorithm],
15431581
innodb_checksum_algorithm_names[srv_log_checksum_algorithm],
1544-
innobase_data_file_path,
1582+
make_local_paths(innobase_data_file_path).c_str(),
15451583
srv_n_log_files,
15461584
innobase_log_file_size,
15471585
srv_page_size,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--innodb --innodb-data-home-dir= --innodb-data-file-path=$MYSQLTEST_VARDIR/tmp/absolute_path_ibdata1:3M;ibdata_second:1M:autoextend
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CREATE TABLE t(i INT) ENGINE INNODB;
2+
INSERT INTO t VALUES(1);
3+
# xtrabackup backup
4+
# remove datadir
5+
# xtrabackup copy back
6+
# restart server
7+
SELECT * from t;
8+
i
9+
1
10+
DROP TABLE t;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This test just backs up and restores empty database
2+
# Innodb system tablespace is specified with absolute path in the .opt file
3+
CREATE TABLE t(i INT) ENGINE INNODB;
4+
INSERT INTO t VALUES(1);
5+
echo # xtrabackup backup;
6+
7+
let $targetdir=$MYSQLTEST_VARDIR/tmp/backup;
8+
let $_innodb_data_file_path=`select @@innodb_data_file_path`;
9+
let $_innodb_data_home_dir=`select @@innodb_data_home_dir`;
10+
let $_datadir= `SELECT @@datadir`;
11+
12+
--disable_result_log
13+
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$targetdir;
14+
--enable_result_log
15+
exec $XTRABACKUP --prepare --target-dir=$targetdir;
16+
17+
--source include/shutdown_mysqld.inc
18+
echo # remove datadir;
19+
rmdir $_datadir;
20+
#remove out-of-datadir ibdata1
21+
remove_file $MYSQLTEST_VARDIR/tmp/absolute_path_ibdata1;
22+
echo # xtrabackup copy back;
23+
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;
24+
echo # restart server;
25+
--source include/start_mysqld.inc
26+
--enable_result_log
27+
28+
SELECT * from t;
29+
DROP TABLE t;
30+
rmdir $targetdir;
31+

0 commit comments

Comments
 (0)