From 0ddbec40fbba8ce818489c82a1b679a0b33aa50e Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Wed, 9 Nov 2022 16:41:19 +0400 Subject: MDEV-23335 MariaBackup Incremental Does Not Reflect Dropped/Created Databases --- extra/mariabackup/backup_copy.cc | 49 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'extra') diff --git a/extra/mariabackup/backup_copy.cc b/extra/mariabackup/backup_copy.cc index 23ade2a46be..57dfdbc7ad4 100644 --- a/extra/mariabackup/backup_copy.cc +++ b/extra/mariabackup/backup_copy.cc @@ -57,6 +57,9 @@ Street, Fifth Floor, Boston, MA 02110-1335 USA #include "backup_copy.h" #include "backup_mysql.h" #include +#ifdef _WIN32 +#include /* rmdir */ +#endif #define ROCKSDB_BACKUP_DIR "#rocksdb" @@ -1623,7 +1626,49 @@ bool backup_finish() return(true); } -bool + +/* + Drop all empty database directories in the base backup + that do not exists in the icremental backup. + + This effectively re-plays all DROP DATABASE statements happened + in between base backup and incremental backup creation time. + + Note, only checking if base_dir/db/ is empty is not enough, + because inc_dir/db/db.opt might have been dropped for some reasons, + which may also result into empty base_dir/db/. + + Only the fact that at the same time: + - base_dir/db/ exists + - inc_dir/db/ does not exist + means that DROP DATABASE happened. +*/ +static void +ibx_incremental_drop_databases(const char *base_dir, + const char *inc_dir) +{ + datadir_node_t node; + datadir_node_init(&node); + datadir_iter_t *it = datadir_iter_new(base_dir); + + while (datadir_iter_next(it, &node)) { + if (node.is_empty_dir) { + char path[FN_REFLEN]; + snprintf(path, sizeof(path), "%s/%s", + inc_dir, node.filepath_rel); + if (!directory_exists(path, false)) { + msg("Removing %s", node.filepath); + rmdir(node.filepath); + } + } + + } + datadir_iter_free(it); + datadir_node_free(&node); +} + + +static bool ibx_copy_incremental_over_full() { const char *ext_list[] = {"frm", "isl", "MYD", "MYI", "MAD", "MAI", @@ -1706,6 +1751,8 @@ ibx_copy_incremental_over_full() } copy_or_move_dir(path, ROCKSDB_BACKUP_DIR, true, true); } + ibx_incremental_drop_databases(xtrabackup_target_dir, + xtrabackup_incremental_dir); } -- cgit v1.2.1