PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pg_combinebackup.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * pg_combinebackup.c
4 * Combine incremental backups with prior backups.
5 *
6 * Copyright (c) 2017-2026, PostgreSQL Global Development Group
7 *
8 * IDENTIFICATION
9 * src/bin/pg_combinebackup/pg_combinebackup.c
10 *
11 *-------------------------------------------------------------------------
12 */
13#include "postgres_fe.h"
14
15#include <dirent.h>
16#include <fcntl.h>
17#include <limits.h>
18
19#ifdef HAVE_COPYFILE_H
20#include <copyfile.h>
21#endif
22#ifdef __linux__
23#include <sys/ioctl.h>
24#include <linux/fs.h>
25#endif
26
28#include "backup_label.h"
31#include "common/file_perm.h"
32#include "common/file_utils.h"
33#include "common/logging.h"
34#include "common/relpath.h"
35#include "copy_file.h"
37#include "fe_utils/version.h"
38#include "getopt_long.h"
39#include "lib/stringinfo.h"
40#include "load_manifest.h"
41#include "reconstruct.h"
42#include "write_manifest.h"
43
44/* Incremental file naming convention. */
45#define INCREMENTAL_PREFIX "INCREMENTAL."
46#define INCREMENTAL_PREFIX_LENGTH (sizeof(INCREMENTAL_PREFIX) - 1)
47
48/*
49 * Tracking for directories that need to be removed, or have their contents
50 * removed, if the operation fails.
51 */
58
59/*
60 * Stores a tablespace mapping provided using -T, --tablespace-mapping.
61 */
68
69/*
70 * Stores data parsed from all command-line options.
71 */
84
85/*
86 * Data about a tablespace.
87 *
88 * Every normal tablespace needs a tablespace mapping, but in-place tablespaces
89 * don't, so the list of tablespaces can contain more entries than the list of
90 * tablespace mappings.
91 */
100
101/* Directories to be removed if we exit uncleanly. */
103
104static void add_tablespace_mapping(cb_options *opt, char *arg);
107static void check_input_dir_permissions(char *dir);
108static void cleanup_directories_atexit(void);
109static void create_output_directory(char *dirname, cb_options *opt);
110static void help(const char *progname);
111static bool parse_oid(char *s, Oid *result);
113 char *input_directory,
114 char *output_directory,
115 char *relative_path,
116 int n_prior_backups,
117 char **prior_backup_dirs,
120 cb_options *opt);
121static void remember_to_cleanup_directory(char *target_path, bool rmtopdir);
122static void reset_directory_cleanup_list(void);
123static cb_tablespace *scan_for_existing_tablespaces(char *pathname,
124 cb_options *opt);
125static void slurp_file(int fd, char *filename, StringInfo buf, int maxlen);
126
127/*
128 * Main program.
129 */
130int
131main(int argc, char *argv[])
132{
133 static struct option long_options[] = {
134 {"debug", no_argument, NULL, 'd'},
135 {"dry-run", no_argument, NULL, 'n'},
136 {"no-sync", no_argument, NULL, 'N'},
137 {"output", required_argument, NULL, 'o'},
138 {"tablespace-mapping", required_argument, NULL, 'T'},
139 {"link", no_argument, NULL, 'k'},
140 {"manifest-checksums", required_argument, NULL, 1},
141 {"no-manifest", no_argument, NULL, 2},
142 {"sync-method", required_argument, NULL, 3},
143 {"clone", no_argument, NULL, 4},
144 {"copy", no_argument, NULL, 5},
145 {"copy-file-range", no_argument, NULL, 6},
146 {NULL, 0, NULL, 0}
147 };
148
149 const char *progname;
150 char *last_input_dir;
151 int i;
152 int optindex;
153 int c;
154 int n_backups;
155 int n_prior_backups;
156 uint32 version;
157 uint64 system_identifier;
158 char **prior_backup_dirs;
159 cb_options opt;
160 cb_tablespace *tablespaces;
161 cb_tablespace *ts;
165 char *pgdata;
166
167 pg_logging_init(argv[0]);
168 progname = get_progname(argv[0]);
169 set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_combinebackup"));
171
172 memset(&opt, 0, sizeof(opt));
176
177 /* process command-line options */
178 while ((c = getopt_long(argc, argv, "dknNo:T:",
179 long_options, &optindex)) != -1)
180 {
181 switch (c)
182 {
183 case 'd':
184 opt.debug = true;
186 break;
187 case 'k':
189 break;
190 case 'n':
191 opt.dry_run = true;
192 break;
193 case 'N':
194 opt.no_sync = true;
195 break;
196 case 'o':
197 opt.output = optarg;
198 break;
199 case 'T':
201 break;
202 case 1:
204 &opt.manifest_checksums))
205 pg_fatal("unrecognized checksum algorithm: \"%s\"",
206 optarg);
207 break;
208 case 2:
209 opt.no_manifest = true;
210 break;
211 case 3:
213 exit(1);
214 break;
215 case 4:
217 break;
218 case 5:
220 break;
221 case 6:
223 break;
224 default:
225 /* getopt_long already emitted a complaint */
226 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
227 exit(1);
228 }
229 }
230
231 if (optind >= argc)
232 {
233 pg_log_error("no input directories specified");
234 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
235 exit(1);
236 }
237
238 if (opt.output == NULL)
239 pg_fatal("no output directory specified");
240
241 /* If no manifest is needed, no checksums are needed, either. */
242 if (opt.no_manifest)
244
245 if (opt.dry_run)
246 {
247 pg_log_info("executing in dry-run mode");
248 pg_log_info_detail("The target directory will not be modified.");
249 }
250
251 /* Check that the platform supports the requested copy method. */
253 {
254#if (defined(HAVE_COPYFILE) && defined(COPYFILE_CLONE_FORCE)) || \
255 (defined(__linux__) && defined(FICLONE))
256
257 if (opt.dry_run)
258 pg_log_debug("would use cloning to copy files");
259 else
260 pg_log_debug("will use cloning to copy files");
261
262#else
263 pg_fatal("file cloning not supported on this platform");
264#endif
265 }
267 {
268#if defined(HAVE_COPY_FILE_RANGE)
269
270 if (opt.dry_run)
271 pg_log_debug("would use copy_file_range to copy blocks");
272 else
273 pg_log_debug("will use copy_file_range to copy blocks");
274
275#else
276 pg_fatal("copy_file_range not supported on this platform");
277#endif
278 }
279
280 /* Read the server version from the final backup. */
281 pgdata = argv[argc - 1];
282 version = get_pg_version(pgdata, NULL);
283 if (GET_PG_MAJORVERSION_NUM(version) < 10)
284 pg_fatal("server version too old");
285 pg_log_debug("read server version %u from file \"%s/%s\"",
286 GET_PG_MAJORVERSION_NUM(version), pgdata, "PG_VERSION");
287
288 /* Sanity-check control files. */
289 n_backups = argc - optind;
290 system_identifier = check_control_files(n_backups, argv + optind);
291
292 /* Sanity-check backup_label files, and get the contents of the last one. */
294
295 /*
296 * We'll need the pathnames to the prior backups. By "prior" we mean all
297 * but the last one listed on the command line.
298 */
299 n_prior_backups = argc - optind - 1;
300 prior_backup_dirs = argv + optind;
301
302 /* Load backup manifests. */
304
305 /*
306 * Validate the manifest system identifier against the backup system
307 * identifier.
308 */
309 for (i = 0; i < n_backups; i++)
310 {
311 if (manifests[i] &&
312 manifests[i]->system_identifier != system_identifier)
313 {
314 char *controlpath;
315
317
318 pg_fatal("%s: manifest system identifier is %" PRIu64 ", but control file has %" PRIu64,
320 manifests[i]->system_identifier,
321 system_identifier);
322 }
323 }
324
325 /* Figure out which tablespaces are going to be included in the output. */
326 last_input_dir = argv[argc - 1];
329
330 /*
331 * Create output directories.
332 *
333 * We create one output directory for the main data directory plus one for
334 * each non-in-place tablespace. create_output_directory() will arrange
335 * for those directories to be cleaned up on failure. In-place tablespaces
336 * aren't handled at this stage because they're located beneath the main
337 * output directory, and thus the cleanup of that directory will get rid
338 * of them. Plus, the pg_tblspc directory that needs to contain them
339 * doesn't exist yet.
340 */
343 for (ts = tablespaces; ts != NULL; ts = ts->next)
344 if (!ts->in_place)
346
347 /* If we need to write a backup_manifest, prepare to do so. */
348 if (!opt.dry_run && !opt.no_manifest)
349 {
350 mwriter = create_manifest_writer(opt.output, system_identifier);
351
352 /*
353 * Verify that we have a backup manifest for the final backup; else we
354 * won't have the WAL ranges for the resulting manifest.
355 */
357 pg_fatal("cannot generate a manifest because no manifest is available for the final input backup");
358 }
359 else
360 mwriter = NULL;
361
362 /* Write backup label into output directory. */
363 if (opt.dry_run)
364 pg_log_debug("would generate \"%s/backup_label\"", opt.output);
365 else
366 {
367 pg_log_debug("generating \"%s/backup_label\"", opt.output);
368 last_backup_label->cursor = 0;
371 }
372
373 /* Process everything that's not part of a user-defined tablespace. */
374 pg_log_debug("processing backup directory \"%s\"", last_input_dir);
377 manifests, mwriter, &opt);
378
379 /* Process user-defined tablespaces. */
380 for (ts = tablespaces; ts != NULL; ts = ts->next)
381 {
382 pg_log_debug("processing tablespace directory \"%s\"", ts->old_dir);
383
384 /*
385 * If it's a normal tablespace, we need to set up a symbolic link from
386 * pg_tblspc/${OID} to the target directory; if it's an in-place
387 * tablespace, we need to create a directory at pg_tblspc/${OID}.
388 */
389 if (!ts->in_place)
390 {
391 char linkpath[MAXPGPATH];
392
394 ts->oid);
395
396 if (opt.dry_run)
397 pg_log_debug("would create symbolic link from \"%s\" to \"%s\"",
398 linkpath, ts->new_dir);
399 else
400 {
401 pg_log_debug("creating symbolic link from \"%s\" to \"%s\"",
402 linkpath, ts->new_dir);
403 if (symlink(ts->new_dir, linkpath) != 0)
404 pg_fatal("could not create symbolic link from \"%s\" to \"%s\": %m",
405 linkpath, ts->new_dir);
406 }
407 }
408 else
409 {
410 if (opt.dry_run)
411 pg_log_debug("would create directory \"%s\"", ts->new_dir);
412 else
413 {
414 pg_log_debug("creating directory \"%s\"", ts->new_dir);
415 if (pg_mkdir_p(ts->new_dir, pg_dir_create_mode) == -1)
416 pg_fatal("could not create directory \"%s\": %m",
417 ts->new_dir);
418 }
419 }
420
421 /* OK, now handle the directory contents. */
424 manifests, mwriter, &opt);
425 }
426
427 /* Finalize the backup_manifest, if we're generating one. */
428 if (mwriter != NULL)
430 manifests[n_prior_backups]->first_wal_range);
431
432 /* fsync that output directory unless we've been told not to do so */
433 if (!opt.no_sync)
434 {
435 if (opt.dry_run)
436 pg_log_debug("would recursively fsync \"%s\"", opt.output);
437 else
438 {
439 pg_log_debug("recursively fsyncing \"%s\"", opt.output);
440 sync_pgdata(opt.output, version, opt.sync_method, true);
441 }
442 }
443
444 /* Warn about the possibility of compromising the backups, when link mode */
445 if (opt.copy_method == COPY_METHOD_LINK)
446 pg_log_warning("--link mode was used; any modifications to the output "
447 "directory might destructively modify input directories");
448
449 /* It's a success, so don't remove the output directories. */
451 exit(0);
452}
453
454/*
455 * Process the option argument for the -T, --tablespace-mapping switch.
456 */
457static void
459{
461 char *dst;
462 char *dst_ptr;
463 char *arg_ptr;
464
465 /*
466 * Basically, we just want to copy everything before the equals sign to
467 * tsmap->old_dir and everything afterwards to tsmap->new_dir, but if
468 * there's more or less than one equals sign, that's an error, and if
469 * there's an equals sign preceded by a backslash, don't treat it as a
470 * field separator but instead copy a literal equals sign.
471 */
472 dst_ptr = dst = tsmap->old_dir;
473 for (arg_ptr = arg; *arg_ptr != '\0'; arg_ptr++)
474 {
475 if (dst_ptr - dst >= MAXPGPATH)
476 pg_fatal("directory name too long");
477
478 if (*arg_ptr == '\\' && *(arg_ptr + 1) == '=')
479 ; /* skip backslash escaping = */
480 else if (*arg_ptr == '=' && (arg_ptr == arg || *(arg_ptr - 1) != '\\'))
481 {
482 if (tsmap->new_dir[0] != '\0')
483 pg_fatal("multiple \"=\" signs in tablespace mapping");
484 else
485 dst = dst_ptr = tsmap->new_dir;
486 }
487 else
488 *dst_ptr++ = *arg_ptr;
489 }
490 if (!tsmap->old_dir[0] || !tsmap->new_dir[0])
491 pg_fatal("invalid tablespace mapping format \"%s\", must be \"OLDDIR=NEWDIR\"", arg);
492
493 /*
494 * All tablespaces are created with absolute directories, so specifying a
495 * non-absolute path here would never match, possibly confusing users.
496 *
497 * In contrast to pg_basebackup, both the old and new directories are on
498 * the local machine, so the local machine's definition of an absolute
499 * path is the only relevant one.
500 */
501 if (!is_absolute_path(tsmap->old_dir))
502 pg_fatal("old directory is not an absolute path in tablespace mapping: %s",
503 tsmap->old_dir);
504
505 if (!is_absolute_path(tsmap->new_dir))
506 pg_fatal("new directory is not an absolute path in tablespace mapping: %s",
507 tsmap->new_dir);
508
509 /* Canonicalize paths to avoid spurious failures when comparing. */
510 canonicalize_path(tsmap->old_dir);
511 canonicalize_path(tsmap->new_dir);
512
513 /* Add it to the list. */
514 tsmap->next = opt->tsmappings;
515 opt->tsmappings = tsmap;
516}
517
518/*
519 * Check that the backup_label files form a coherent backup chain, and return
520 * the contents of the backup_label file from the latest backup.
521 */
522static StringInfo
524{
527 int i;
530
531 /* Try to read each backup_label file in turn, last to first. */
532 for (i = n_backups - 1; i >= 0; --i)
533 {
534 char pathbuf[MAXPGPATH];
535 int fd;
538 XLogRecPtr start_lsn;
540
541 /* Open the backup_label file. */
542 snprintf(pathbuf, MAXPGPATH, "%s/backup_label", backup_dirs[i]);
543 pg_log_debug("reading \"%s\"", pathbuf);
544 if ((fd = open(pathbuf, O_RDONLY, 0)) < 0)
545 pg_fatal("could not open file \"%s\": %m", pathbuf);
546
547 /*
548 * Slurp the whole file into memory.
549 *
550 * The exact size limit that we impose here doesn't really matter --
551 * most of what's supposed to be in the file is fixed size and quite
552 * short. However, the length of the backup_label is limited (at least
553 * by some parts of the code) to MAXPGPATH, so include that value in
554 * the maximum length that we tolerate.
555 */
556 slurp_file(fd, pathbuf, buf, 10000 + MAXPGPATH);
557
558 /* Close the file. */
559 if (close(fd) != 0)
560 pg_fatal("could not close file \"%s\": %m", pathbuf);
561
562 /* Parse the file contents. */
565
566 /*
567 * Sanity checks.
568 *
569 * XXX. It's actually not required that start_lsn == check_lsn. It
570 * would be OK if start_lsn > check_lsn provided that start_lsn is
571 * less than or equal to the relevant switchpoint. But at the moment
572 * we don't have that information.
573 */
574 if (i > 0 && previous_tli == 0)
575 pg_fatal("backup at \"%s\" is a full backup, but only the first backup should be a full backup",
576 backup_dirs[i]);
577 if (i == 0 && previous_tli != 0)
578 pg_fatal("backup at \"%s\" is an incremental backup, but the first backup should be a full backup",
579 backup_dirs[i]);
580 if (i < n_backups - 1 && start_tli != check_tli)
581 pg_fatal("backup at \"%s\" starts on timeline %u, but expected %u",
583 if (i < n_backups - 1 && start_lsn != check_lsn)
584 pg_fatal("backup at \"%s\" starts at LSN %X/%08X, but expected %X/%08X",
585 backup_dirs[i],
586 LSN_FORMAT_ARGS(start_lsn),
590
591 /*
592 * The last backup label in the chain needs to be saved for later use,
593 * while the others are only needed within this loop.
594 */
595 if (lastbuf == buf)
597 else
599 }
600
601 /* Free memory that we don't need any more. */
602 if (lastbuf != buf)
604
605 /*
606 * Return the data from the first backup_info that we read (which is the
607 * backup_label from the last directory specified on the command line).
608 */
609 return lastbuf;
610}
611
612/*
613 * Sanity check control files and return system_identifier.
614 */
615static uint64
617{
618 int i;
619 uint64 system_identifier = 0; /* placate compiler */
620 uint32 data_checksum_version = PG_DATA_CHECKSUM_OFF; /* placate compiler */
621 bool data_checksum_mismatch = false;
622
623 /* Try to read each control file in turn, last to first. */
624 for (i = n_backups - 1; i >= 0; --i)
625 {
626 ControlFileData *control_file;
627 bool crc_ok;
628 char *controlpath;
629
631 pg_log_debug("reading \"%s\"", controlpath);
633
634 /* Control file contents not meaningful if CRC is bad. */
635 if (!crc_ok)
636 pg_fatal("%s: CRC is incorrect", controlpath);
637
638 /* Can't interpret control file if not current version. */
639 if (control_file->pg_control_version != PG_CONTROL_VERSION)
640 pg_fatal("%s: unexpected control file version",
642
643 /* System identifiers should all match. */
644 if (i == n_backups - 1)
645 system_identifier = control_file->system_identifier;
646 else if (system_identifier != control_file->system_identifier)
647 pg_fatal("%s: expected system identifier %" PRIu64 ", but found %" PRIu64,
648 controlpath, system_identifier,
649 control_file->system_identifier);
650
651 /*
652 * Detect checksum mismatches, but only if the last backup in the
653 * chain has checksums enabled.
654 */
655 if (i == n_backups - 1)
656 data_checksum_version = control_file->data_checksum_version;
657 else if (data_checksum_version != PG_DATA_CHECKSUM_OFF &&
658 data_checksum_version != control_file->data_checksum_version)
660
661 /* Release memory. */
662 pfree(control_file);
664 }
665
666 /*
667 * If debug output is enabled, make a note of the system identifier that
668 * we found in all of the relevant control files.
669 */
670 pg_log_debug("system identifier is %" PRIu64, system_identifier);
671
672 /*
673 * Warn the user if not all backups are in the same state with regards to
674 * checksums.
675 */
677 {
678 pg_log_warning("only some backups have checksums enabled");
679 pg_log_warning_hint("Disable, and optionally reenable, checksums on the output directory to avoid failures.");
680 }
681
682 return system_identifier;
683}
684
685/*
686 * Set default permissions for new files and directories based on the
687 * permissions of the given directory. The intent here is that the output
688 * directory should use the same permissions scheme as the final input
689 * directory.
690 */
691static void
693{
694 struct stat st;
695
696 if (stat(dir, &st) != 0)
697 pg_fatal("could not stat file \"%s\": %m", dir);
698
700}
701
702/*
703 * Clean up output directories before exiting.
704 */
705static void
707{
708 while (cleanup_dir_list != NULL)
709 {
711
712 if (dir->rmtopdir)
713 {
714 pg_log_info("removing output directory \"%s\"", dir->target_path);
715 if (!rmtree(dir->target_path, dir->rmtopdir))
716 pg_log_error("failed to remove output directory");
717 }
718 else
719 {
720 pg_log_info("removing contents of output directory \"%s\"",
721 dir->target_path);
722 if (!rmtree(dir->target_path, dir->rmtopdir))
723 pg_log_error("failed to remove contents of output directory");
724 }
725
727 pfree(dir);
728 }
729}
730
731/*
732 * Create the named output directory, unless it already exists or we're in
733 * dry-run mode. If it already exists but is not empty, that's a fatal error.
734 *
735 * Adds the created directory to the list of directories to be cleaned up
736 * at process exit.
737 */
738static void
740{
741 switch (pg_check_dir(dirname))
742 {
743 case 0:
744 if (opt->dry_run)
745 {
746 pg_log_debug("would create directory \"%s\"", dirname);
747 return;
748 }
749 pg_log_debug("creating directory \"%s\"", dirname);
750 if (pg_mkdir_p(dirname, pg_dir_create_mode) == -1)
751 pg_fatal("could not create directory \"%s\": %m", dirname);
752 remember_to_cleanup_directory(dirname, true);
753 break;
754
755 case 1:
756 pg_log_debug("using existing directory \"%s\"", dirname);
757 remember_to_cleanup_directory(dirname, false);
758 break;
759
760 case 2:
761 case 3:
762 case 4:
763 pg_fatal("directory \"%s\" exists but is not empty", dirname);
764
765 case -1:
766 pg_fatal("could not access directory \"%s\": %m", dirname);
767 }
768}
769
770/*
771 * help
772 *
773 * Prints help page for the program
774 *
775 * progname: the name of the executed program, such as "pg_combinebackup"
776 */
777static void
778help(const char *progname)
779{
780 printf(_("%s reconstructs full backups from incrementals.\n\n"), progname);
781 printf(_("Usage:\n"));
782 printf(_(" %s [OPTION]... DIRECTORY...\n"), progname);
783 printf(_("\nOptions:\n"));
784 printf(_(" -d, --debug generate lots of debugging output\n"));
785 printf(_(" -k, --link link files instead of copying\n"));
786 printf(_(" -n, --dry-run do not actually do anything\n"));
787 printf(_(" -N, --no-sync do not wait for changes to be written safely to disk\n"));
788 printf(_(" -o, --output=DIRECTORY output directory\n"));
789 printf(_(" -T, --tablespace-mapping=OLDDIR=NEWDIR\n"
790 " relocate tablespace in OLDDIR to NEWDIR\n"));
791 printf(_(" --clone clone (reflink) files instead of copying\n"));
792 printf(_(" --copy copy files (default)\n"));
793 printf(_(" --copy-file-range copy using copy_file_range() system call\n"));
794 printf(_(" --manifest-checksums=SHA{224,256,384,512}|CRC32C|NONE\n"
795 " use algorithm for manifest checksums\n"));
796 printf(_(" --no-manifest suppress generation of backup manifest\n"));
797 printf(_(" --sync-method=METHOD set method for syncing files to disk\n"));
798 printf(_(" -V, --version output version information, then exit\n"));
799 printf(_(" -?, --help show this help, then exit\n"));
800
801 printf(_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
802 printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
803}
804
805/*
806 * Try to parse a string as a non-zero OID without leading zeroes.
807 *
808 * If it works, return true and set *result to the answer, else return false.
809 */
810static bool
812{
813 Oid oid;
814 char *ep;
815
816 errno = 0;
817 oid = strtoul(s, &ep, 10);
818 if (errno != 0 || *ep != '\0' || oid < 1 || oid > PG_UINT32_MAX)
819 return false;
820
821 *result = oid;
822 return true;
823}
824
825/*
826 * Copy files from the input directory to the output directory, reconstructing
827 * full files from incremental files as required.
828 *
829 * If processing a user-defined tablespace, the tsoid should be the OID
830 * of that tablespace and input_directory and output_directory should be the
831 * toplevel input and output directories for that tablespace. Otherwise,
832 * tsoid should be InvalidOid and input_directory and output_directory should
833 * be the main input and output directories.
834 *
835 * relative_path is the path beneath the given input and output directories
836 * that we are currently processing. If NULL, it indicates that we're
837 * processing the input and output directories themselves.
838 *
839 * n_prior_backups is the number of prior backups that we have available.
840 * This doesn't count the very last backup, which is referenced by
841 * input_directory, just the older ones. prior_backup_dirs is an array of
842 * the locations of those previous backups.
843 */
844static void
846 char *input_directory,
847 char *output_directory,
848 char *relative_path,
849 int n_prior_backups,
850 char **prior_backup_dirs,
853 cb_options *opt)
854{
855 char ifulldir[MAXPGPATH];
856 char ofulldir[MAXPGPATH];
858 DIR *dir;
859 struct dirent *de;
860 bool is_pg_tblspc = false;
861 bool is_pg_wal = false;
862 bool is_incremental_dir = false;
864 pg_checksum_type checksum_type;
865
866 /*
867 * Classify this directory.
868 *
869 * We set is_pg_tblspc only for the toplevel pg_tblspc directory, because
870 * the symlinks in that specific directory require special handling.
871 *
872 * We set is_pg_wal for the toplevel WAL directory and all of its
873 * subdirectories, because those files are not included in the backup
874 * manifest and hence need special treatment. (Since incremental backup
875 * does not exist in pre-v10 versions, we don't have to worry about the
876 * old pg_xlog naming.)
877 *
878 * We set is_incremental_dir for directories that can contain incremental
879 * files requiring reconstruction. If such files occur outside these
880 * directories, we want to just copy them straight to the output
881 * directory. This is to protect against a user creating a file with a
882 * strange name like INCREMENTAL.config and then complaining that
883 * incremental backups don't work properly. The test here is a bit tricky:
884 * incremental files occur in subdirectories of base, in pg_global itself,
885 * and in subdirectories of pg_tblspc only if in-place tablespaces are
886 * used.
887 */
888 if (OidIsValid(tsoid))
889 is_incremental_dir = true;
890 else if (relative_path != NULL)
891 {
893 is_pg_wal = (strcmp(relative_path, "pg_wal") == 0 ||
894 strncmp(relative_path, "pg_wal/", 7) == 0);
895 is_incremental_dir = strncmp(relative_path, "base/", 5) == 0 ||
896 strcmp(relative_path, "global") == 0 ||
898 }
899
900 /*
901 * If we're under pg_wal, then we don't need checksums, because these
902 * files aren't included in the backup manifest. Otherwise use whatever
903 * type of checksum is configured.
904 */
905 if (!is_pg_wal)
906 checksum_type = opt->manifest_checksums;
907 else
908 checksum_type = CHECKSUM_TYPE_NONE;
909
910 /*
911 * Append the relative path to the input and output directories, and
912 * figure out the appropriate prefix to add to files in this directory
913 * when looking them up in a backup manifest.
914 */
915 if (relative_path == NULL)
916 {
919 if (OidIsValid(tsoid))
921 else
922 manifest_prefix[0] = '\0';
923 }
924 else
925 {
930 if (OidIsValid(tsoid))
931 snprintf(manifest_prefix, MAXPGPATH, "%s/%u/%s/",
933 else
935 }
936
937 /*
938 * Toplevel output directories have already been created by the time this
939 * function is called, but any subdirectories are our responsibility.
940 */
941 if (relative_path != NULL)
942 {
943 if (opt->dry_run)
944 pg_log_debug("would create directory \"%s\"", ofulldir);
945 else
946 {
947 pg_log_debug("creating directory \"%s\"", ofulldir);
949 pg_fatal("could not create directory \"%s\": %m", ofulldir);
950 }
951 }
952
953 /* It's time to scan the directory. */
954 if ((dir = opendir(ifulldir)) == NULL)
955 pg_fatal("could not open directory \"%s\": %m", ifulldir);
956 while (errno = 0, (de = readdir(dir)) != NULL)
957 {
959 char ifullpath[MAXPGPATH];
960 char ofullpath[MAXPGPATH];
962 Oid oid = InvalidOid;
963 int checksum_length = 0;
964 uint8 *checksum_payload = NULL;
965 pg_checksum_context checksum_ctx;
966
967 /* Ignore "." and ".." entries. */
968 if (strcmp(de->d_name, ".") == 0 ||
969 strcmp(de->d_name, "..") == 0)
970 continue;
971
972 /* Construct input path. */
973 snprintf(ifullpath, MAXPGPATH, "%s/%s", ifulldir, de->d_name);
974
975 /* Figure out what kind of directory entry this is. */
977 if (type == PGFILETYPE_ERROR)
978 exit(1);
979
980 /*
981 * If we're processing pg_tblspc, then check whether the filename
982 * looks like it could be a tablespace OID. If so, and if the
983 * directory entry is a symbolic link or a directory, skip it.
984 *
985 * Our goal here is to ignore anything that would have been considered
986 * by scan_for_existing_tablespaces to be a tablespace.
987 */
988 if (is_pg_tblspc && parse_oid(de->d_name, &oid) &&
990 continue;
991
992 /* If it's a directory, recurse. */
993 if (type == PGFILETYPE_DIR)
994 {
996
997 /* Append new pathname component to relative path. */
998 if (relative_path == NULL)
1000 else
1002 de->d_name);
1003
1004 /* And recurse. */
1009 manifests, mwriter, opt);
1010 continue;
1011 }
1012
1013 /* Skip anything that's not a regular file. */
1014 if (type != PGFILETYPE_REG)
1015 {
1016 if (type == PGFILETYPE_LNK)
1017 pg_log_warning("skipping symbolic link \"%s\"", ifullpath);
1018 else
1019 pg_log_warning("skipping special file \"%s\"", ifullpath);
1020 continue;
1021 }
1022
1023 /*
1024 * Skip the backup_label and backup_manifest files; they require
1025 * special handling and are handled elsewhere.
1026 */
1027 if (relative_path == NULL &&
1028 (strcmp(de->d_name, "backup_label") == 0 ||
1029 strcmp(de->d_name, "backup_manifest") == 0))
1030 continue;
1031
1032 /*
1033 * If it's an incremental file, hand it off to the reconstruction
1034 * code, which will figure out what to do.
1035 */
1036 if (is_incremental_dir &&
1037 strncmp(de->d_name, INCREMENTAL_PREFIX,
1039 {
1040 /* Output path should not include "INCREMENTAL." prefix. */
1042 de->d_name + INCREMENTAL_PREFIX_LENGTH);
1043
1044
1045 /* Manifest path likewise omits incremental prefix. */
1047 de->d_name + INCREMENTAL_PREFIX_LENGTH);
1048
1049 /* Reconstruction logic will do the rest. */
1052 de->d_name + INCREMENTAL_PREFIX_LENGTH,
1055 manifests,
1057 checksum_type,
1058 &checksum_length,
1059 &checksum_payload,
1060 opt->copy_method,
1061 opt->debug,
1062 opt->dry_run);
1063 }
1064 else
1065 {
1066 /* Construct the path that the backup_manifest will use. */
1068 de->d_name);
1069
1070 /*
1071 * It's not an incremental file, so we need to copy the entire
1072 * file to the output directory.
1073 *
1074 * If a checksum of the required type already exists in the
1075 * backup_manifest for the final input directory, we can save some
1076 * work by reusing that checksum instead of computing a new one.
1077 */
1078 if (checksum_type != CHECKSUM_TYPE_NONE &&
1080 {
1081 manifest_file *mfile;
1082
1085 if (mfile == NULL)
1086 {
1087 char *bmpath;
1088
1089 /*
1090 * The directory is out of sync with the backup_manifest,
1091 * so emit a warning.
1092 */
1093 bmpath = psprintf("%s/%s", input_directory,
1094 "backup_manifest");
1095 pg_log_warning("manifest file \"%s\" contains no entry for file \"%s\"",
1097 pfree(bmpath);
1098 }
1099 else if (mfile->checksum_type == checksum_type)
1100 {
1101 checksum_length = mfile->checksum_length;
1102 checksum_payload = mfile->checksum_payload;
1103 }
1104 }
1105
1106 /*
1107 * If we're reusing a checksum, then we don't need copy_file() to
1108 * compute one for us, but otherwise, it needs to compute whatever
1109 * type of checksum we need.
1110 */
1111 if (checksum_length != 0)
1112 pg_checksum_init(&checksum_ctx, CHECKSUM_TYPE_NONE);
1113 else
1114 pg_checksum_init(&checksum_ctx, checksum_type);
1115
1116 /* Actually copy the file. */
1117 snprintf(ofullpath, MAXPGPATH, "%s/%s", ofulldir, de->d_name);
1118 copy_file(ifullpath, ofullpath, &checksum_ctx,
1119 opt->copy_method, opt->dry_run);
1120
1121 /*
1122 * If copy_file() performed a checksum calculation for us, then
1123 * save the results (except in dry-run mode, when there's no
1124 * point).
1125 */
1126 if (checksum_ctx.type != CHECKSUM_TYPE_NONE && !opt->dry_run)
1127 {
1128 checksum_payload = pg_malloc(PG_CHECKSUM_MAX_LENGTH);
1129 checksum_length = pg_checksum_final(&checksum_ctx,
1130 checksum_payload);
1131 }
1132 }
1133
1134 /* Generate manifest entry, if needed. */
1135 if (mwriter != NULL)
1136 {
1137 struct stat sb;
1138
1139 /*
1140 * In order to generate a manifest entry, we need the file size
1141 * and mtime. We have no way to know the correct mtime except to
1142 * stat() the file, so just do that and get the size as well.
1143 *
1144 * If we didn't need the mtime here, we could try to obtain the
1145 * file size from the reconstruction or file copy process above,
1146 * although that is actually not convenient in all cases. If we
1147 * write the file ourselves then clearly we can keep a count of
1148 * bytes, but if we use something like CopyFile() then it's
1149 * trickier. Since we have to stat() anyway to get the mtime,
1150 * there's no point in worrying about it.
1151 */
1152 if (stat(ofullpath, &sb) < 0)
1153 pg_fatal("could not stat file \"%s\": %m", ofullpath);
1154
1155 /* OK, now do the work. */
1157 sb.st_size, sb.st_mtime,
1158 checksum_type, checksum_length,
1159 checksum_payload);
1160 }
1161
1162 /* Avoid leaking memory. */
1163 if (checksum_payload != NULL)
1164 pg_free(checksum_payload);
1165 }
1166
1167 closedir(dir);
1168}
1169
1170/*
1171 * Add a directory to the list of output directories to clean up.
1172 */
1173static void
1174remember_to_cleanup_directory(char *target_path, bool rmtopdir)
1175{
1177
1178 dir->target_path = target_path;
1179 dir->rmtopdir = rmtopdir;
1180 dir->next = cleanup_dir_list;
1181 cleanup_dir_list = dir;
1182}
1183
1184/*
1185 * Empty out the list of directories scheduled for cleanup at exit.
1186 *
1187 * We want to remove the output directories only on a failure, so call this
1188 * function when we know that the operation has succeeded.
1189 *
1190 * Since we only expect this to be called when we're about to exit, we could
1191 * just set cleanup_dir_list to NULL and be done with it, but we free the
1192 * memory to be tidy.
1193 */
1194static void
1196{
1197 while (cleanup_dir_list != NULL)
1198 {
1200
1202 pfree(dir);
1203 }
1204}
1205
1206/*
1207 * Scan the pg_tblspc directory of the final input backup to get a canonical
1208 * list of what tablespaces are part of the backup.
1209 *
1210 * 'pathname' should be the path to the toplevel backup directory for the
1211 * final backup in the backup chain.
1212 */
1213static cb_tablespace *
1215{
1216 char pg_tblspc[MAXPGPATH];
1217 DIR *dir;
1218 struct dirent *de;
1220
1221 snprintf(pg_tblspc, MAXPGPATH, "%s/%s", pathname, PG_TBLSPC_DIR);
1222 pg_log_debug("scanning \"%s\"", pg_tblspc);
1223
1224 if ((dir = opendir(pg_tblspc)) == NULL)
1225 pg_fatal("could not open directory \"%s\": %m", pg_tblspc);
1226
1227 while (errno = 0, (de = readdir(dir)) != NULL)
1228 {
1229 Oid oid;
1230 char tblspcdir[MAXPGPATH];
1231 char link_target[MAXPGPATH];
1232 int link_length;
1233 cb_tablespace *ts;
1236
1237 /* Silently ignore "." and ".." entries. */
1238 if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0)
1239 continue;
1240
1241 /* Construct full pathname. */
1242 snprintf(tblspcdir, MAXPGPATH, "%s/%s", pg_tblspc, de->d_name);
1243
1244 /* Ignore any file name that doesn't look like a proper OID. */
1245 if (!parse_oid(de->d_name, &oid))
1246 {
1247 pg_log_debug("skipping \"%s\" because the filename is not a legal tablespace OID",
1248 tblspcdir);
1249 continue;
1250 }
1251
1252 /* Only symbolic links and directories are tablespaces. */
1254 if (type == PGFILETYPE_ERROR)
1255 exit(1);
1257 {
1258 pg_log_debug("skipping \"%s\" because it is neither a symbolic link nor a directory",
1259 tblspcdir);
1260 continue;
1261 }
1262
1263 /* Create a new tablespace object. */
1265 ts->oid = oid;
1266
1267 /*
1268 * If it's a link, it's not an in-place tablespace. Otherwise, it must
1269 * be a directory, and thus an in-place tablespace.
1270 */
1271 if (type == PGFILETYPE_LNK)
1272 {
1274
1275 /* Read the link target. */
1277 if (link_length < 0)
1278 pg_fatal("could not read symbolic link \"%s\": %m",
1279 tblspcdir);
1280 if (link_length >= sizeof(link_target))
1281 pg_fatal("target of symbolic link \"%s\" is too long", tblspcdir);
1282 link_target[link_length] = '\0';
1284 pg_fatal("target of symbolic link \"%s\" is relative", tblspcdir);
1285
1286 /* Canonicalize the link target. */
1288
1289 /*
1290 * Find the corresponding tablespace mapping and copy the relevant
1291 * details into the new tablespace entry.
1292 */
1293 for (tsmap = opt->tsmappings; tsmap != NULL; tsmap = tsmap->next)
1294 {
1295 if (strcmp(tsmap->old_dir, link_target) == 0)
1296 {
1297 strlcpy(ts->old_dir, tsmap->old_dir, MAXPGPATH);
1298 strlcpy(ts->new_dir, tsmap->new_dir, MAXPGPATH);
1299 ts->in_place = false;
1300 break;
1301 }
1302 }
1303
1304 /* Every non-in-place tablespace must be mapped. */
1305 if (tsmap == NULL)
1306 pg_fatal("tablespace at \"%s\" has no tablespace mapping",
1307 link_target);
1308 }
1309 else
1310 {
1311 /*
1312 * For an in-place tablespace, there's no separate directory, so
1313 * we just record the paths within the data directories.
1314 */
1315 snprintf(ts->old_dir, MAXPGPATH, "%s/%s", pg_tblspc, de->d_name);
1316 snprintf(ts->new_dir, MAXPGPATH, "%s/%s/%s", opt->output,
1317 PG_TBLSPC_DIR, de->d_name);
1318 ts->in_place = true;
1319 }
1320
1321 /* Tablespaces should not share a directory. */
1322 for (otherts = tslist; otherts != NULL; otherts = otherts->next)
1323 if (strcmp(ts->new_dir, otherts->new_dir) == 0)
1324 pg_fatal("tablespaces with OIDs %u and %u both point at directory \"%s\"",
1325 otherts->oid, oid, ts->new_dir);
1326
1327 /* Add this tablespace to the list. */
1328 ts->next = tslist;
1329 tslist = ts;
1330 }
1331
1332 if (closedir(dir) != 0)
1333 pg_fatal("could not close directory \"%s\": %m", pg_tblspc);
1334
1335 return tslist;
1336}
1337
1338/*
1339 * Read a file into a StringInfo.
1340 *
1341 * fd is used for the actual file I/O, filename for error reporting purposes.
1342 * A file longer than maxlen is a fatal error.
1343 */
1344static void
1345slurp_file(int fd, char *filename, StringInfo buf, int maxlen)
1346{
1347 struct stat st;
1348 ssize_t rb;
1349
1350 /* Check file size, and complain if it's too large. */
1351 if (fstat(fd, &st) != 0)
1352 pg_fatal("could not stat file \"%s\": %m", filename);
1353 if (st.st_size > maxlen)
1354 pg_fatal("file \"%s\" is too large", filename);
1355
1356 /* Make sure we have enough space. */
1358
1359 /* Read the data. */
1360 rb = read(fd, &buf->data[buf->len], st.st_size);
1361
1362 /*
1363 * We don't expect any concurrent changes, so we should read exactly the
1364 * expected number of bytes.
1365 */
1366 if (rb != st.st_size)
1367 {
1368 if (rb < 0)
1369 pg_fatal("could not read file \"%s\": %m", filename);
1370 else
1371 pg_fatal("could not read file \"%s\": read %zd of %lld",
1372 filename, rb, (long long int) st.st_size);
1373 }
1374
1375 /* Adjust buffer length for new data and restore trailing-\0 invariant */
1376 buf->len += rb;
1377 buf->data[buf->len] = '\0';
1378}
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)
static void help(void)
Definition pg_config.c:71
uint8_t uint8
Definition c.h:681
#define PG_UINT32_MAX
Definition c.h:733
#define PG_TEXTDOMAIN(domain)
Definition c.h:1362
uint64_t uint64
Definition c.h:684
uint32_t uint32
Definition c.h:683
#define OidIsValid(objectId)
Definition c.h:917
@ PG_DATA_CHECKSUM_OFF
Definition checksum.h:28
uint32 result
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
pg_checksum_type
@ CHECKSUM_TYPE_NONE
@ CHECKSUM_TYPE_CRC32C
void set_pglocale_pgservice(const char *argv0, const char *app)
Definition exec.c:430
int main(void)
ControlFileData * get_controlfile_by_exact_path(const char *ControlFilePath, bool *crc_ok_p)
CopyMethod
Definition copy_file.h:20
@ COPY_METHOD_CLONE
Definition copy_file.h:21
@ COPY_METHOD_LINK
Definition copy_file.h:27
@ COPY_METHOD_COPY
Definition copy_file.h:22
@ COPY_METHOD_COPY_FILE_RANGE
Definition copy_file.h:23
void copy_file(const char *fromfile, const char *tofile)
Definition copydir.c:134
int closedir(DIR *)
Definition dirent.c:127
struct dirent * readdir(DIR *)
Definition dirent.c:78
DIR * opendir(const char *)
Definition dirent.c:33
Datum arg
Definition elog.c:1323
#define _(x)
Definition elog.c:96
void * pg_malloc(size_t size)
Definition fe_memutils.c:53
void pg_free(void *ptr)
#define pg_malloc0_object(type)
Definition fe_memutils.h:61
#define pg_malloc_object(type)
Definition fe_memutils.h:60
uint32 get_pg_version(const char *datadir, char **version_str)
Definition version.c:44
void SetDataDirectoryCreatePerm(int dataDirMode)
Definition file_perm.c:34
int pg_dir_create_mode
Definition file_perm.c:18
PGFileType get_dirent_type(const char *path, const struct dirent *de, bool look_through_symlinks, int elevel)
Definition file_utils.c:547
PGFileType
Definition file_utils.h:19
@ PGFILETYPE_LNK
Definition file_utils.h:24
@ PGFILETYPE_DIR
Definition file_utils.h:23
@ PGFILETYPE_REG
Definition file_utils.h:22
@ PGFILETYPE_ERROR
Definition file_utils.h:20
DataDirSyncMethod
Definition file_utils.h:28
@ DATA_DIR_SYNC_METHOD_FSYNC
Definition file_utils.h:29
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
Definition getopt_long.c:60
#define no_argument
Definition getopt_long.h:25
#define required_argument
Definition getopt_long.h:26
#define close(a)
Definition win32.h:12
#define read(a, b, c)
Definition win32.h:13
int i
Definition isn.c:77
static pg_noreturn void manifest_data ** load_backup_manifests(int n_backups, char **backup_directories)
void pg_logging_increase_verbosity(void)
Definition logging.c:187
void pg_logging_init(const char *argv0)
Definition logging.c:85
#define pg_log_error(...)
Definition logging.h:108
#define pg_log_info_detail(...)
Definition logging.h:129
#define pg_log_error_hint(...)
Definition logging.h:114
#define pg_log_info(...)
Definition logging.h:126
#define pg_log_warning_hint(...)
Definition logging.h:123
@ PG_LOG_ERROR
Definition logging.h:43
#define pg_log_debug(...)
Definition logging.h:135
const char * progname
Definition main.c:44
void pfree(void *pointer)
Definition mcxt.c:1619
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)
#define pg_fatal(...)
static cb_tablespace * scan_for_existing_tablespaces(char *pathname, cb_options *opt)
static void remember_to_cleanup_directory(char *target_path, bool rmtopdir)
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
#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
static void slurp_file(int fd, char *filename, StringInfo buf, int maxlen)
static bool parse_oid(char *s, Oid *result)
static void reset_directory_cleanup_list(void)
#define MAXPGPATH
#define PG_CONTROL_VERSION
Definition pg_control.h:25
static char * filename
Definition pg_dumpall.c:120
PGDLLIMPORT int optind
Definition getopt.c:47
PGDLLIMPORT char * optarg
Definition getopt.c:49
static char buf[DEFAULT_XLOG_SEG_SIZE]
#define pg_log_warning(...)
Definition pgfnames.c:24
int pg_mkdir_p(char *path, int omode)
Definition pgmkdirp.c:57
#define is_absolute_path(filename)
Definition port.h:105
void canonicalize_path(char *path)
Definition path.c:337
int pg_check_dir(const char *dir)
Definition pgcheckdir.c:33
#define snprintf
Definition port.h:261
const char * get_progname(const char *argv0)
Definition path.c:669
#define printf(...)
Definition port.h:267
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition strlcpy.c:45
#define InvalidOid
unsigned int Oid
char * c
static int fd(const char *x, int i)
static int fb(int x)
char * psprintf(const char *fmt,...)
Definition psprintf.c:43
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)
Definition reconstruct.c:88
#define PG_TBLSPC_DIR_SLASH
Definition relpath.h:42
#define PG_TBLSPC_DIR
Definition relpath.h:41
bool rmtree(const char *path, bool rmtopdir)
Definition rmtree.c:50
void destroyStringInfo(StringInfo str)
Definition stringinfo.c:409
StringInfo makeStringInfo(void)
Definition stringinfo.c:72
void resetStringInfo(StringInfo str)
Definition stringinfo.c:126
void enlargeStringInfo(StringInfo str, int needed)
Definition stringinfo.c:337
uint32 pg_control_version
Definition pg_control.h:133
uint32 data_checksum_version
Definition pg_control.h:232
uint64 system_identifier
Definition pg_control.h:118
Definition dirent.c:26
struct cb_cleanup_dir * next
cb_tablespace_mapping * tsmappings
DataDirSyncMethod sync_method
CopyMethod copy_method
pg_checksum_type manifest_checksums
struct cb_tablespace_mapping * next
char new_dir[MAXPGPATH]
char old_dir[MAXPGPATH]
char new_dir[MAXPGPATH]
struct cb_tablespace * next
char old_dir[MAXPGPATH]
uint8 * checksum_payload
pg_checksum_type checksum_type
pg_checksum_type type
__int64 st_size
Definition win32_port.h:263
unsigned short st_mode
Definition win32_port.h:258
#define GET_PG_MAJORVERSION_NUM(v)
Definition version.h:19
const char * type
#define stat
Definition win32_port.h:74
#define mkdir(a, b)
Definition win32_port.h:80
#define fstat
Definition win32_port.h:73
#define symlink(oldpath, newpath)
Definition win32_port.h:225
#define readlink(path, buf, size)
Definition win32_port.h:226
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)
Definition xlogdefs.h:47
uint64 XLogRecPtr
Definition xlogdefs.h:21
#define InvalidXLogRecPtr
Definition xlogdefs.h:28
uint32 TimeLineID
Definition xlogdefs.h:63