/* * copy_file -- * Copy a single file into the backup directories. */ static void copy_file(WT_SESSION *session, const char *name) { size_t len; char *first, *second; len = strlen("BACKUP") + strlen(name) + 10; first = dmalloc(len); (void)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); (void)snprintf(second, len, "BACKUP_COPY/%s", name); testutil_check(__wt_copy_and_sync(session, first, second)); free(first); free(second); }
static int copy(WT_SESSION *session, const char *directory, const char *name) { WT_DECL_RET; size_t len; char *to; to = NULL; /* Build the target pathname. */ len = strlen(directory) + strlen(name) + 2; if ((to = malloc(len)) == NULL) { fprintf(stderr, "%s: %s\n", progname, strerror(errno)); return (1); } if ((ret = __wt_snprintf(to, len, "%s/%s", directory, name)) != 0) { fprintf(stderr, "%s: %s\n", progname, strerror(ret)); goto err; } if (verbose && printf("Backing up %s/%s to %s\n", home, name, to) < 0) { fprintf(stderr, "%s: %s\n", progname, strerror(EIO)); goto err; } /* * Use WiredTiger to copy the file: ensuring stability of the copied * file on disk requires care, and WiredTiger knows how to do it. */ if ((ret = __wt_copy_and_sync(session, name, to)) != 0) fprintf(stderr, "%s/%s to %s: backup copy: %s\n", home, name, to, session->strerror(session, ret)); err: free(to); return (ret); }