summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/test/utility/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/third_party/wiredtiger/test/utility/misc.c')
-rw-r--r--src/third_party/wiredtiger/test/utility/misc.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/third_party/wiredtiger/test/utility/misc.c b/src/third_party/wiredtiger/test/utility/misc.c
index fc0896aced6..674a868c35e 100644
--- a/src/third_party/wiredtiger/test/utility/misc.c
+++ b/src/third_party/wiredtiger/test/utility/misc.c
@@ -35,6 +35,12 @@ void (*custom_die)(void) = NULL;
const char *progname = "program name not set";
/*
+ * Backup directory initialize command, remove and re-create the primary backup directory, plus a
+ * copy we maintain for recovery testing.
+ */
+#define HOME_BACKUP_INIT_CMD "rm -rf %s/BACKUP %s/BACKUP.copy && mkdir %s/BACKUP %s/BACKUP.copy"
+
+/*
* testutil_die --
* Report an error and abort.
*/
@@ -256,6 +262,46 @@ testutil_timestamp_parse(const char *str, uint64_t *tsp)
testutil_assert(p - str <= 16);
}
+void
+testutil_create_backup_directory(const char *home)
+{
+ size_t len;
+ char *cmd;
+
+ len = strlen(home) * 4 + strlen(HOME_BACKUP_INIT_CMD) + 1;
+ cmd = dmalloc(len);
+ testutil_check(__wt_snprintf(cmd, len, HOME_BACKUP_INIT_CMD, home, home, home, home));
+ testutil_checkfmt(system(cmd), "%s", "backup directory creation failed");
+ free(cmd);
+}
+
+/*
+ * copy_file --
+ * Copy a single file into the backup directories.
+ */
+void
+testutil_copy_file(WT_SESSION *session, const char *name)
+{
+ size_t len;
+ char *first, *second;
+
+ len = strlen("BACKUP") + strlen(name) + 10;
+ first = dmalloc(len);
+ testutil_check(__wt_snprintf(first, len, "BACKUP/%s", name));
+ testutil_check(__wt_copy_and_sync(session, name, first));
+
+ /*
+ * Save another copy of the original file to make debugging recovery errors easier.
+ */
+ len = strlen("BACKUP.copy") + strlen(name) + 10;
+ second = dmalloc(len);
+ testutil_check(__wt_snprintf(second, len, "BACKUP.copy/%s", name));
+ testutil_check(__wt_copy_and_sync(session, first, second));
+
+ free(first);
+ free(second);
+}
+
/*
* testutil_is_flag_set --
* Return if an environment variable flag is set.