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.
This commit is contained in:
Vladislav Vaintroub 2018-09-11 20:59:35 +01:00
parent 21829bd743
commit e46b2a3e94

View file

@ -443,6 +443,38 @@ datafiles_iter_free(datafiles_iter_t *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 ======== */
typedef struct {
@ -6764,8 +6796,7 @@ int main(int argc, char **argv)
if (xtrabackup_copy_back || xtrabackup_move_back) {
if (!check_if_param_set("datadir")) {
msg("Error: datadir must be specified.\n");
exit(EXIT_FAILURE);
mysql_data_home = get_default_datadir();
}
if (!copy_back())
exit(EXIT_FAILURE);