Commit e46b2a3e authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

MDEV-12956 provide default datadir for mariabackup --copy-back

On Unix, it is compiled-in datadir value.
On Windows, the directory is ..\data, relative to directory
mariabackup.exe

server uses the same logic to determine datadir.
parent 21829bd7
...@@ -443,6 +443,38 @@ datafiles_iter_free(datafiles_iter_t *it) ...@@ -443,6 +443,38 @@ datafiles_iter_free(datafiles_iter_t *it)
ut_free(it); ut_free(it);
} }
/*
Retrieve default data directory, to be used with --copy-back.
On Windows, default datadir is ..\data, relative to the
directory where mariabackup.exe is located(usually "bin")
Elsewhere, the compiled-in constant MYSQL_DATADIR is used.
*/
static char *get_default_datadir() {
static char ddir[] = MYSQL_DATADIR;
#ifdef _WIN32
static char buf[MAX_PATH];
DWORD size = (DWORD)sizeof(buf) - 1;
if (GetModuleFileName(NULL, buf, size) <= size)
{
char *p;
if ((p = strrchr(buf, '\\')))
{
*p = 0;
if ((p = strrchr(buf, '\\')))
{
strncpy(p + 1, "data", buf + MAX_PATH - p);
return buf;
}
}
}
#endif
return ddir;
}
/* ======== Date copying thread context ======== */ /* ======== Date copying thread context ======== */
typedef struct { typedef struct {
...@@ -6764,8 +6796,7 @@ int main(int argc, char **argv) ...@@ -6764,8 +6796,7 @@ int main(int argc, char **argv)
if (xtrabackup_copy_back || xtrabackup_move_back) { if (xtrabackup_copy_back || xtrabackup_move_back) {
if (!check_if_param_set("datadir")) { if (!check_if_param_set("datadir")) {
msg("Error: datadir must be specified.\n"); mysql_data_home = get_default_datadir();
exit(EXIT_FAILURE);
} }
if (!copy_back()) if (!copy_back())
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
......
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