1/*-------------------------------------------------------------------------
4 * Combine incremental backups with prior backups.
6 * Copyright (c) 2017-2025, PostgreSQL Global Development Group
9 * src/bin/pg_combinebackup/pg_combinebackup.c
11 *-------------------------------------------------------------------------
43/* Incremental file naming convention. */
44 #define INCREMENTAL_PREFIX "INCREMENTAL."
45 #define INCREMENTAL_PREFIX_LENGTH (sizeof(INCREMENTAL_PREFIX) - 1)
48 * Tracking for directories that need to be removed, or have their contents
49 * removed, if the operation fails.
59 * Stores a tablespace mapping provided using -T, --tablespace-mapping.
69 * Stores data parsed from all command-line options.
85 * Data about a tablespace.
87 * Every normal tablespace needs a tablespace mapping, but in-place tablespaces
88 * don't, so the list of tablespaces can contain more entries than the list of
89 * tablespace mappings.
100/* Directories to be removed if we exit uncleanly. */
112 char *input_directory,
113 char *output_directory,
116 char **prior_backup_dirs,
133 static struct option long_options[] = {
150 char *last_input_dir;
158 char **prior_backup_dirs;
171 memset(&opt, 0,
sizeof(opt));
176 /* process command-line options */
178 long_options, &optindex)) != -1)
204 pg_fatal(
"unrecognized checksum algorithm: \"%s\"",
224 /* getopt_long already emitted a complaint */
238 pg_fatal(
"no output directory specified");
240 /* If no manifest is needed, no checksums are needed, either. */
244 /* Check that the platform supports the requested copy method. */
247#if (defined(HAVE_COPYFILE) && defined(COPYFILE_CLONE_FORCE)) || \
248 (defined(__linux__) && defined(FICLONE))
256 pg_fatal(
"file cloning not supported on this platform");
261#if defined(HAVE_COPY_FILE_RANGE)
264 pg_log_debug(
"would use copy_file_range to copy blocks");
266 pg_log_debug(
"will use copy_file_range to copy blocks");
269 pg_fatal(
"copy_file_range not supported on this platform");
273 /* Read the server version from the final backup. */
276 /* Sanity-check control files. */
277 n_backups = argc -
optind;
280 /* Sanity-check backup_label files, and get the contents of the last one. */
284 * We'll need the pathnames to the prior backups. By "prior" we mean all
285 * but the last one listed on the command line.
287 n_prior_backups = argc -
optind - 1;
288 prior_backup_dirs = argv +
optind;
290 /* Load backup manifests. */
294 * Validate the manifest system identifier against the backup system
297 for (
i = 0;
i < n_backups;
i++)
300 manifests[
i]->system_identifier != system_identifier)
306 pg_fatal(
"%s: manifest system identifier is %" PRIu64
", but control file has %" PRIu64,
308 manifests[
i]->system_identifier,
313 /* Figure out which tablespaces are going to be included in the output. */
314 last_input_dir = argv[argc - 1];
319 * Create output directories.
321 * We create one output directory for the main data directory plus one for
322 * each non-in-place tablespace. create_output_directory() will arrange
323 * for those directories to be cleaned up on failure. In-place tablespaces
324 * aren't handled at this stage because they're located beneath the main
325 * output directory, and thus the cleanup of that directory will get rid
326 * of them. Plus, the pg_tblspc directory that needs to contain them
331 for (ts = tablespaces; ts != NULL; ts = ts->
next)
335 /* If we need to write a backup_manifest, prepare to do so. */
341 * Verify that we have a backup manifest for the final backup; else we
342 * won't have the WAL ranges for the resulting manifest.
344 if (manifests[n_prior_backups] == NULL)
345 pg_fatal(
"cannot generate a manifest because no manifest is available for the final input backup");
350 /* Write backup label into output directory. */
356 last_backup_label->
cursor = 0;
361 /* Process everything that's not part of a user-defined tablespace. */
362 pg_log_debug(
"processing backup directory \"%s\"", last_input_dir);
364 NULL, n_prior_backups, prior_backup_dirs,
365 manifests, mwriter, &opt);
367 /* Process user-defined tablespaces. */
368 for (ts = tablespaces; ts != NULL; ts = ts->
next)
373 * If it's a normal tablespace, we need to set up a symbolic link from
374 * pg_tblspc/${OID} to the target directory; if it's an in-place
375 * tablespace, we need to create a directory at pg_tblspc/${OID}.
385 pg_log_debug(
"would create symbolic link from \"%s\" to \"%s\"",
389 pg_log_debug(
"creating symbolic link from \"%s\" to \"%s\"",
392 pg_fatal(
"could not create symbolic link from \"%s\" to \"%s\": %m",
404 pg_fatal(
"could not create directory \"%s\": %m",
409 /* OK, now handle the directory contents. */
411 NULL, n_prior_backups, prior_backup_dirs,
412 manifests, mwriter, &opt);
415 /* Finalize the backup_manifest, if we're generating one. */
418 manifests[n_prior_backups]->first_wal_range);
420 /* fsync that output directory unless we've been told not to do so */
432 /* Warn about the possibility of compromising the backups, when link mode */
434 pg_log_warning(
"--link mode was used; any modifications to the output "
435 "directory might destructively modify input directories");
437 /* It's a success, so don't remove the output directories. */
443 * Process the option argument for the -T, --tablespace-mapping switch.
454 * Basically, we just want to copy everything before the equals sign to
455 * tsmap->old_dir and everything afterwards to tsmap->new_dir, but if
456 * there's more or less than one equals sign, that's an error, and if
457 * there's an equals sign preceded by a backslash, don't treat it as a
458 * field separator but instead copy a literal equals sign.
460 dst_ptr = dst = tsmap->
old_dir;
461 for (arg_ptr =
arg; *arg_ptr !=
'0円'; arg_ptr++)
464 pg_fatal(
"directory name too long");
466 if (*arg_ptr ==
'\\' && *(arg_ptr + 1) ==
'=')
467 ;
/* skip backslash escaping = */
468 else if (*arg_ptr ==
'=' && (arg_ptr ==
arg || *(arg_ptr - 1) !=
'\\'))
471 pg_fatal(
"multiple \"=\" signs in tablespace mapping");
473 dst = dst_ptr = tsmap->
new_dir;
476 *dst_ptr++ = *arg_ptr;
479 pg_fatal(
"invalid tablespace mapping format \"%s\", must be \"OLDDIR=NEWDIR\"",
arg);
482 * All tablespaces are created with absolute directories, so specifying a
483 * non-absolute path here would never match, possibly confusing users.
485 * In contrast to pg_basebackup, both the old and new directories are on
486 * the local machine, so the local machine's definition of an absolute
487 * path is the only relevant one.
490 pg_fatal(
"old directory is not an absolute path in tablespace mapping: %s",
494 pg_fatal(
"old directory is not an absolute path in tablespace mapping: %s",
497 /* Canonicalize paths to avoid spurious failures when comparing. */
501 /* Add it to the list. */
507 * Check that the backup_label files form a coherent backup chain, and return
508 * the contents of the backup_label file from the latest backup.
519 /* Try to read each backup_label file in turn, last to first. */
520 for (
i = n_backups - 1;
i >= 0; --
i)
529 /* Open the backup_label file. */
532 if ((
fd = open(pathbuf, O_RDONLY, 0)) < 0)
533 pg_fatal(
"could not open file \"%s\": %m", pathbuf);
536 * Slurp the whole file into memory.
538 * The exact size limit that we impose here doesn't really matter --
539 * most of what's supposed to be in the file is fixed size and quite
540 * short. However, the length of the backup_label is limited (at least
541 * by some parts of the code) to MAXPGPATH, so include that value in
542 * the maximum length that we tolerate.
546 /* Close the file. */
548 pg_fatal(
"could not close file \"%s\": %m", pathbuf);
550 /* Parse the file contents. */
552 &previous_tli, &previous_lsn);
557 * XXX. It's actually not required that start_lsn == check_lsn. It
558 * would be OK if start_lsn > check_lsn provided that start_lsn is
559 * less than or equal to the relevant switchpoint. But at the moment
560 * we don't have that information.
562 if (
i > 0 && previous_tli == 0)
563 pg_fatal(
"backup at \"%s\" is a full backup, but only the first backup should be a full backup",
565 if (
i == 0 && previous_tli != 0)
566 pg_fatal(
"backup at \"%s\" is an incremental backup, but the first backup should be a full backup",
568 if (
i < n_backups - 1 && start_tli != check_tli)
569 pg_fatal(
"backup at \"%s\" starts on timeline %u, but expected %u",
570 backup_dirs[
i], start_tli, check_tli);
571 if (
i < n_backups - 1 && start_lsn != check_lsn)
572 pg_fatal(
"backup at \"%s\" starts at LSN %X/%08X, but expected %X/%08X",
576 check_tli = previous_tli;
577 check_lsn = previous_lsn;
580 * The last backup label in the chain needs to be saved for later use,
581 * while the others are only needed within this loop.
589 /* Free memory that we don't need any more. */
594 * Return the data from the first backup_info that we read (which is the
595 * backup_label from the last directory specified on the command line).
601 * Sanity check control files and return system_identifier.
607 uint64 system_identifier = 0;
/* placate compiler */
608 uint32 data_checksum_version = 0;
/* placate compiler */
609 bool data_checksum_mismatch =
false;
611 /* Try to read each control file in turn, last to first. */
612 for (
i = n_backups - 1;
i >= 0; --
i)
622 /* Control file contents not meaningful if CRC is bad. */
624 pg_fatal(
"%s: CRC is incorrect", controlpath);
626 /* Can't interpret control file if not current version. */
628 pg_fatal(
"%s: unexpected control file version",
631 /* System identifiers should all match. */
632 if (
i == n_backups - 1)
635 pg_fatal(
"%s: expected system identifier %" PRIu64
", but found %" PRIu64,
636 controlpath, system_identifier,
640 * Detect checksum mismatches, but only if the last backup in the
641 * chain has checksums enabled.
643 if (
i == n_backups - 1)
645 else if (data_checksum_version != 0 &&
647 data_checksum_mismatch =
true;
649 /* Release memory. */
655 * If debug output is enabled, make a note of the system identifier that
656 * we found in all of the relevant control files.
658 pg_log_debug(
"system identifier is %" PRIu64, system_identifier);
661 * Warn the user if not all backups are in the same state with regards to
664 if (data_checksum_mismatch)
667 pg_log_warning_hint(
"Disable, and optionally reenable, checksums on the output directory to avoid failures.");
670 return system_identifier;
674 * Set default permissions for new files and directories based on the
675 * permissions of the given directory. The intent here is that the output
676 * directory should use the same permissions scheme as the final input
684 if (
stat(dir, &st) != 0)
685 pg_fatal(
"could not stat file \"%s\": %m", dir);
691 * Clean up output directories before exiting.
708 pg_log_info(
"removing contents of output directory \"%s\"",
711 pg_log_error(
"failed to remove contents of output directory");
720 * Create the named output directory, unless it already exists or we're in
721 * dry-run mode. If it already exists but is not empty, that's a fatal error.
723 * Adds the created directory to the list of directories to be cleaned up
739 pg_fatal(
"could not create directory \"%s\": %m", dirname);
744 pg_log_debug(
"using existing directory \"%s\"", dirname);
751 pg_fatal(
"directory \"%s\" exists but is not empty", dirname);
754 pg_fatal(
"could not access directory \"%s\": %m", dirname);
761 * Prints help page for the program
763 * progname: the name of the executed program, such as "pg_combinebackup"
768 printf(
_(
"%s reconstructs full backups from incrementals.\n\n"),
progname);
772 printf(
_(
" -d, --debug generate lots of debugging output\n"));
773 printf(
_(
" -k, --link link files instead of copying\n"));
774 printf(
_(
" -n, --dry-run do not actually do anything\n"));
775 printf(
_(
" -N, --no-sync do not wait for changes to be written safely to disk\n"));
776 printf(
_(
" -o, --output=DIRECTORY output directory\n"));
777 printf(
_(
" -T, --tablespace-mapping=OLDDIR=NEWDIR\n"
778 " relocate tablespace in OLDDIR to NEWDIR\n"));
779 printf(
_(
" --clone clone (reflink) files instead of copying\n"));
780 printf(
_(
" --copy copy files (default)\n"));
781 printf(
_(
" --copy-file-range copy using copy_file_range() system call\n"));
782 printf(
_(
" --manifest-checksums=SHA{224,256,384,512}|CRC32C|NONE\n"
783 " use algorithm for manifest checksums\n"));
784 printf(
_(
" --no-manifest suppress generation of backup manifest\n"));
785 printf(
_(
" --sync-method=METHOD set method for syncing files to disk\n"));
786 printf(
_(
" -V, --version output version information, then exit\n"));
787 printf(
_(
" -?, --help show this help, then exit\n"));
789 printf(
_(
"\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
790 printf(
_(
"%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
794 * Try to parse a string as a non-zero OID without leading zeroes.
796 * If it works, return true and set *result to the answer, else return false.
805 oid = strtoul(s, &ep, 10);
806 if (errno != 0 || *ep !=
'0円' || oid < 1 || oid >
PG_UINT32_MAX)
814 * Copy files from the input directory to the output directory, reconstructing
815 * full files from incremental files as required.
817 * If processing a user-defined tablespace, the tsoid should be the OID
818 * of that tablespace and input_directory and output_directory should be the
819 * toplevel input and output directories for that tablespace. Otherwise,
820 * tsoid should be InvalidOid and input_directory and output_directory should
821 * be the main input and output directories.
823 * relative_path is the path beneath the given input and output directories
824 * that we are currently processing. If NULL, it indicates that we're
825 * processing the input and output directories themselves.
827 * n_prior_backups is the number of prior backups that we have available.
828 * This doesn't count the very last backup, which is referenced by
829 * input_directory, just the older ones. prior_backup_dirs is an array of
830 * the locations of those previous backups.
834 char *input_directory,
835 char *output_directory,
838 char **prior_backup_dirs,
848 bool is_pg_tblspc =
false;
849 bool is_pg_wal =
false;
850 bool is_incremental_dir =
false;
855 * Classify this directory.
857 * We set is_pg_tblspc only for the toplevel pg_tblspc directory, because
858 * the symlinks in that specific directory require special handling.
860 * We set is_pg_wal for the toplevel WAL directory and all of its
861 * subdirectories, because those files are not included in the backup
862 * manifest and hence need special treatment. (Since incremental backup
863 * does not exist in pre-v10 versions, we don't have to worry about the
864 * old pg_xlog naming.)
866 * We set is_incremental_dir for directories that can contain incremental
867 * files requiring reconstruction. If such files occur outside these
868 * directories, we want to just copy them straight to the output
869 * directory. This is to protect against a user creating a file with a
870 * strange name like INCREMENTAL.config and then complaining that
871 * incremental backups don't work properly. The test here is a bit tricky:
872 * incremental files occur in subdirectories of base, in pg_global itself,
873 * and in subdirectories of pg_tblspc only if in-place tablespaces are
877 is_incremental_dir =
true;
878 else if (relative_path != NULL)
881 is_pg_wal = (strcmp(relative_path,
"pg_wal") == 0 ||
882 strncmp(relative_path,
"pg_wal/", 7) == 0);
883 is_incremental_dir = strncmp(relative_path,
"base/", 5) == 0 ||
884 strcmp(relative_path,
"global") == 0 ||
889 * If we're under pg_wal, then we don't need checksums, because these
890 * files aren't included in the backup manifest. Otherwise use whatever
891 * type of checksum is configured.
899 * Append the relative path to the input and output directories, and
900 * figure out the appropriate prefix to add to files in this directory
901 * when looking them up in a backup manifest.
903 if (relative_path == NULL)
910 manifest_prefix[0] =
'0円';
926 * Toplevel output directories have already been created by the time this
927 * function is called, but any subdirectories are our responsibility.
929 if (relative_path != NULL)
932 pg_log_debug(
"would create directory \"%s\"", ofulldir);
937 pg_fatal(
"could not create directory \"%s\": %m", ofulldir);
941 /* It's time to scan the directory. */
942 if ((dir =
opendir(ifulldir)) == NULL)
943 pg_fatal(
"could not open directory \"%s\": %m", ifulldir);
944 while (errno = 0, (de =
readdir(dir)) != NULL)
951 int checksum_length = 0;
952 uint8 *checksum_payload = NULL;
955 /* Ignore "." and ".." entries. */
956 if (strcmp(de->
d_name,
".") == 0 ||
957 strcmp(de->
d_name,
"..") == 0)
960 /* Construct input path. */
963 /* Figure out what kind of directory entry this is. */
969 * If we're processing pg_tblspc, then check whether the filename
970 * looks like it could be a tablespace OID. If so, and if the
971 * directory entry is a symbolic link or a directory, skip it.
973 * Our goal here is to ignore anything that would have been considered
974 * by scan_for_existing_tablespaces to be a tablespace.
980 /* If it's a directory, recurse. */
985 /* Append new pathname component to relative path. */
986 if (relative_path == NULL)
994 input_directory, output_directory,
996 n_prior_backups, prior_backup_dirs,
997 manifests, mwriter, opt);
1001 /* Skip anything that's not a regular file. */
1012 * Skip the backup_label and backup_manifest files; they require
1013 * special handling and are handled elsewhere.
1015 if (relative_path == NULL &&
1016 (strcmp(de->
d_name,
"backup_label") == 0 ||
1017 strcmp(de->
d_name,
"backup_manifest") == 0))
1021 * If it's an incremental file, hand it off to the reconstruction
1022 * code, which will figure out what to do.
1024 if (is_incremental_dir &&
1028 /* Output path should not include "INCREMENTAL." prefix. */
1033 /* Manifest path likewise omits incremental prefix. */
1037 /* Reconstruction logic will do the rest. */
1054 /* Construct the path that the backup_manifest will use. */
1059 * It's not an incremental file, so we need to copy the entire
1060 * file to the output directory.
1062 * If a checksum of the required type already exists in the
1063 * backup_manifest for the final input directory, we can save some
1064 * work by reusing that checksum instead of computing a new one.
1067 latest_manifest != NULL)
1071 mfile = manifest_files_lookup(latest_manifest->
files,
1078 * The directory is out of sync with the backup_manifest,
1079 * so emit a warning.
1081 bmpath =
psprintf(
"%s/%s", input_directory,
1083 pg_log_warning(
"manifest file \"%s\" contains no entry for file \"%s\"",
1084 bmpath, manifest_path);
1095 * If we're reusing a checksum, then we don't need copy_file() to
1096 * compute one for us, but otherwise, it needs to compute whatever
1097 * type of checksum we need.
1099 if (checksum_length != 0)
1104 /* Actually copy the file. */
1106 copy_file(ifullpath, ofullpath, &checksum_ctx,
1110 * If copy_file() performed a checksum calculation for us, then
1111 * save the results (except in dry-run mode, when there's no
1122 /* Generate manifest entry, if needed. */
1123 if (mwriter != NULL)
1128 * In order to generate a manifest entry, we need the file size
1129 * and mtime. We have no way to know the correct mtime except to
1130 * stat() the file, so just do that and get the size as well.
1132 * If we didn't need the mtime here, we could try to obtain the
1133 * file size from the reconstruction or file copy process above,
1134 * although that is actually not convenient in all cases. If we
1135 * write the file ourselves then clearly we can keep a count of
1136 * bytes, but if we use something like CopyFile() then it's
1137 * trickier. Since we have to stat() anyway to get the mtime,
1138 * there's no point in worrying about it.
1140 if (
stat(ofullpath, &sb) < 0)
1141 pg_fatal(
"could not stat file \"%s\": %m", ofullpath);
1143 /* OK, now do the work. */
1146 checksum_type, checksum_length,
1150 /* Avoid leaking memory. */
1151 if (checksum_payload != NULL)
1152 pfree(checksum_payload);
1159 * Read the version number from PG_VERSION and convert it to the usual server
1160 * version number format. (e.g. If PG_VERSION contains "14\n" this function
1161 * will return 140000)
1172 /* Construct pathname. */
1179 /* Read into memory. Length limit of 128 should be more than generous. */
1183 /* Close the file. */
1187 /* Convert to integer. */
1189 version = strtoul(
buf.data, &ep, 10);
1190 if (errno != 0 || *ep !=
'\n')
1193 * Incremental backup is not relevant to very old server versions that
1194 * used multi-part version number (e.g. 9.6, or 8.4). So if we see
1195 * what looks like the beginning of such a version number, just bail
1198 if (version < 10 && *ep ==
'.')
1203 /* Debugging output. */
1206 /* Release memory and return result. */
1208 return version * 10000;
1212 * Add a directory to the list of output directories to clean up.
1226 * Empty out the list of directories scheduled for cleanup at exit.
1228 * We want to remove the output directories only on a failure, so call this
1229 * function when we know that the operation has succeeded.
1231 * Since we only expect this to be called when we're about to exit, we could
1232 * just set cleanup_dir_list to NULL and be done with it, but we free the
1233 * memory to be tidy.
1248 * Scan the pg_tblspc directory of the final input backup to get a canonical
1249 * list of what tablespaces are part of the backup.
1251 * 'pathname' should be the path to the toplevel backup directory for the
1252 * final backup in the backup chain.
1265 if ((dir =
opendir(pg_tblspc)) == NULL)
1266 pg_fatal(
"could not open directory \"%s\": %m", pg_tblspc);
1268 while (errno = 0, (de =
readdir(dir)) != NULL)
1278 /* Silently ignore "." and ".." entries. */
1279 if (strcmp(de->
d_name,
".") == 0 || strcmp(de->
d_name,
"..") == 0)
1282 /* Construct full pathname. */
1285 /* Ignore any file name that doesn't look like a proper OID. */
1288 pg_log_debug(
"skipping \"%s\" because the filename is not a legal tablespace OID",
1293 /* Only symbolic links and directories are tablespaces. */
1299 pg_log_debug(
"skipping \"%s\" because it is neither a symbolic link nor a directory",
1304 /* Create a new tablespace object. */
1309 * If it's a link, it's not an in-place tablespace. Otherwise, it must
1310 * be a directory, and thus an in-place tablespace.
1316 /* Read the link target. */
1317 link_length =
readlink(tblspcdir, link_target,
sizeof(link_target));
1318 if (link_length < 0)
1319 pg_fatal(
"could not read symbolic link \"%s\": %m",
1321 if (link_length >=
sizeof(link_target))
1322 pg_fatal(
"target of symbolic link \"%s\" is too long", tblspcdir);
1323 link_target[link_length] =
'0円';
1325 pg_fatal(
"target of symbolic link \"%s\" is relative", tblspcdir);
1327 /* Canonicalize the link target. */
1331 * Find the corresponding tablespace mapping and copy the relevant
1332 * details into the new tablespace entry.
1334 for (tsmap = opt->
tsmappings; tsmap != NULL; tsmap = tsmap->
next)
1336 if (strcmp(tsmap->
old_dir, link_target) == 0)
1345 /* Every non-in-place tablespace must be mapped. */
1347 pg_fatal(
"tablespace at \"%s\" has no tablespace mapping",
1353 * For an in-place tablespace, there's no separate directory, so
1354 * we just record the paths within the data directories.
1362 /* Tablespaces should not share a directory. */
1363 for (otherts = tslist; otherts != NULL; otherts = otherts->
next)
1365 pg_fatal(
"tablespaces with OIDs %u and %u both point at directory \"%s\"",
1368 /* Add this tablespace to the list. */
1374 pg_fatal(
"could not close directory \"%s\": %m", pg_tblspc);
1380 * Read a file into a StringInfo.
1382 * fd is used for the actual file I/O, filename for error reporting purposes.
1383 * A file longer than maxlen is a fatal error.
1391 /* Check file size, and complain if it's too large. */
1397 /* Make sure we have enough space. */
1400 /* Read the data. */
1404 * We don't expect any concurrent changes, so we should read exactly the
1405 * expected number of bytes.
1412 pg_fatal(
"could not read file \"%s\": read %zd of %lld",
1416 /* Adjust buffer length for new data and restore trailing-0円 invariant */
1418 buf->data[
buf->len] =
'0円';
void parse_backup_label(char *filename, StringInfo buf, TimeLineID *start_tli, XLogRecPtr *start_lsn, TimeLineID *previous_tli, XLogRecPtr *previous_lsn)
void write_backup_label(char *output_directory, StringInfo buf, pg_checksum_type checksum_type, manifest_writer *mwriter)
#define PG_TEXTDOMAIN(domain)
#define OidIsValid(objectId)
bool pg_checksum_parse_type(char *name, pg_checksum_type *type)
int pg_checksum_final(pg_checksum_context *context, uint8 *output)
int pg_checksum_init(pg_checksum_context *context, pg_checksum_type type)
#define PG_CHECKSUM_MAX_LENGTH
void set_pglocale_pgservice(const char *argv0, const char *app)
ControlFileData * get_controlfile_by_exact_path(const char *ControlFilePath, bool *crc_ok_p)
@ COPY_METHOD_COPY_FILE_RANGE
void copy_file(const char *fromfile, const char *tofile)
struct dirent * readdir(DIR *)
DIR * opendir(const char *)
void * pg_malloc(size_t size)
void * pg_malloc0(size_t size)
void SetDataDirectoryCreatePerm(int dataDirMode)
PGFileType get_dirent_type(const char *path, const struct dirent *de, bool look_through_symlinks, int elevel)
@ DATA_DIR_SYNC_METHOD_FSYNC
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
#define required_argument
static pg_noreturn void manifest_data ** load_backup_manifests(int n_backups, char **backup_directories)
void pg_logging_increase_verbosity(void)
void pg_logging_init(const char *argv0)
#define pg_log_error(...)
#define pg_log_error_hint(...)
#define pg_log_warning_hint(...)
#define pg_log_debug(...)
void pfree(void *pointer)
void handle_help_version_opts(int argc, char *argv[], const char *fixed_progname, help_handler hlp)
bool parse_sync_method(const char *optarg, DataDirSyncMethod *sync_method)
static cb_tablespace * scan_for_existing_tablespaces(char *pathname, cb_options *opt)
int main(int argc, char *argv[])
struct cb_cleanup_dir cb_cleanup_dir
static void remember_to_cleanup_directory(char *target_path, bool rmtopdir)
static void help(const char *progname)
static void process_directory_recursively(Oid tsoid, char *input_directory, char *output_directory, char *relative_path, int n_prior_backups, char **prior_backup_dirs, manifest_data **manifests, manifest_writer *mwriter, cb_options *opt)
static void create_output_directory(char *dirname, cb_options *opt)
static void check_input_dir_permissions(char *dir)
static uint64 check_control_files(int n_backups, char **backup_dirs)
static cb_cleanup_dir * cleanup_dir_list
struct cb_tablespace cb_tablespace
#define INCREMENTAL_PREFIX_LENGTH
static void cleanup_directories_atexit(void)
static StringInfo check_backup_label_files(int n_backups, char **backup_dirs)
static void add_tablespace_mapping(cb_options *opt, char *arg)
#define INCREMENTAL_PREFIX
struct cb_tablespace_mapping cb_tablespace_mapping
static void slurp_file(int fd, char *filename, StringInfo buf, int maxlen)
struct cb_options cb_options
static bool parse_oid(char *s, Oid *result)
static int read_pg_version_file(char *directory)
static void reset_directory_cleanup_list(void)
#define PG_CONTROL_VERSION
PGDLLIMPORT char * optarg
#define pg_log_warning(...)
int pg_mkdir_p(char *path, int omode)
#define is_absolute_path(filename)
void canonicalize_path(char *path)
int pg_check_dir(const char *dir)
const char * get_progname(const char *argv0)
size_t strlcpy(char *dst, const char *src, size_t siz)
static int fd(const char *x, int i)
char * psprintf(const char *fmt,...)
void reconstruct_from_incremental_file(char *input_filename, char *output_filename, char *relative_path, char *bare_file_name, int n_prior_backups, char **prior_backup_dirs, manifest_data **manifests, char *manifest_path, pg_checksum_type checksum_type, int *checksum_length, uint8 **checksum_payload, CopyMethod copy_method, bool debug, bool dry_run)
#define PG_TBLSPC_DIR_SLASH
bool rmtree(const char *path, bool rmtopdir)
void destroyStringInfo(StringInfo str)
StringInfo makeStringInfo(void)
void resetStringInfo(StringInfo str)
void enlargeStringInfo(StringInfo str, int needed)
void initStringInfo(StringInfo str)
uint32 pg_control_version
uint32 data_checksum_version
struct cb_cleanup_dir * next
cb_tablespace_mapping * tsmappings
DataDirSyncMethod sync_method
pg_checksum_type manifest_checksums
struct cb_tablespace_mapping * next
struct cb_tablespace * next
manifest_files_hash * files
pg_checksum_type checksum_type
#define symlink(oldpath, newpath)
#define readlink(path, buf, size)
manifest_writer * create_manifest_writer(char *directory, uint64 system_identifier)
void add_file_to_manifest(manifest_writer *mwriter, const char *manifest_path, uint64 size, time_t mtime, pg_checksum_type checksum_type, int checksum_length, uint8 *checksum_payload)
void finalize_manifest(manifest_writer *mwriter, manifest_wal_range *first_wal_range)
#define XLOG_CONTROL_FILE
#define LSN_FORMAT_ARGS(lsn)
#define InvalidXLogRecPtr
static const char * directory