summaryrefslogtreecommitdiff
path: root/src/bin/pg_combinebackup/pg_combinebackup.c
diff options
context:
space:
mode:
authorRobert Haas2025-03-17 18:03:14 +0000
committerRobert Haas2025-03-17 18:03:14 +0000
commit99aeb84703177308c1541e2d11c09fdc59acb724 (patch)
tree8dd572c268bba0ff07ef3ec8296c350d5f31753d /src/bin/pg_combinebackup/pg_combinebackup.c
parented762e94253d5dd7810da13b8dd802baa876c55e (diff)
pg_combinebackup: Add -k, --link option.
This is similar to pg_upgrade's --link option, except that here we won't typically be able to use it for every input file: sometimes we will need to reconstruct a complete backup from blocks stored in different files. However, when a whole file does need to be copied, we can use an optimized copying strategy: see the existing --clone and --copy-file-range options and the code to use CopyFile() on Windows. This commit adds a new strategy: add a hard link to an existing file. Making a hard link doesn't actually copy anything, but it makes sense for the code to treat it as doing so. This is useful when the input directories are merely staging directories that will be removed once the restore is complete. In such cases, there is no need to actually copy the data, and making a bunch of new hard links can be very quick. However, it would be quite dangerous to use it if the input directories might later be reused for any other purpose, since starting postgres on the output directory would destructively modify the input directories. For that reason, using this new option causes pg_combinebackup to emit a warning about the danger involved. Author: Israel Barth Rubio <[email protected]> Co-authored-by: Robert Haas <[email protected]> (cosmetic changes) Reviewed-by: Vignesh C <[email protected]> Discussion: http://postgr.es/m/CA+TgmoaEFsYHsMefNaNkU=2SnMRufKE3eVJxvAaX=OWgcnPmPg@mail.gmail.com
Diffstat (limited to 'src/bin/pg_combinebackup/pg_combinebackup.c')
-rw-r--r--src/bin/pg_combinebackup/pg_combinebackup.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/bin/pg_combinebackup/pg_combinebackup.c b/src/bin/pg_combinebackup/pg_combinebackup.c
index 5864ec574fb..d480dc74436 100644
--- a/src/bin/pg_combinebackup/pg_combinebackup.c
+++ b/src/bin/pg_combinebackup/pg_combinebackup.c
@@ -135,6 +135,7 @@ main(int argc, char *argv[])
{"no-sync", no_argument, NULL, 'N'},
{"output", required_argument, NULL, 'o'},
{"tablespace-mapping", required_argument, NULL, 'T'},
+ {"link", no_argument, NULL, 'k'},
{"manifest-checksums", required_argument, NULL, 1},
{"no-manifest", no_argument, NULL, 2},
{"sync-method", required_argument, NULL, 3},
@@ -172,7 +173,7 @@ main(int argc, char *argv[])
opt.copy_method = COPY_METHOD_COPY;
/* process command-line options */
- while ((c = getopt_long(argc, argv, "dnNo:T:",
+ while ((c = getopt_long(argc, argv, "dknNo:T:",
long_options, &optindex)) != -1)
{
switch (c)
@@ -181,6 +182,9 @@ main(int argc, char *argv[])
opt.debug = true;
pg_logging_increase_verbosity();
break;
+ case 'k':
+ opt.copy_method = COPY_METHOD_LINK;
+ break;
case 'n':
opt.dry_run = true;
break;
@@ -424,6 +428,11 @@ main(int argc, char *argv[])
}
}
+ /* Warn about the possibility of compromising the backups, when link mode */
+ if (opt.copy_method == COPY_METHOD_LINK)
+ pg_log_warning("--link mode was used; any modifications to the output "
+ "directory may destructively modify input directories");
+
/* It's a success, so don't remove the output directories. */
reset_directory_cleanup_list();
exit(0);
@@ -761,6 +770,7 @@ help(const char *progname)
printf(_(" %s [OPTION]... DIRECTORY...\n"), progname);
printf(_("\nOptions:\n"));
printf(_(" -d, --debug generate lots of debugging output\n"));
+ printf(_(" -k, --link link files instead of copying\n"));
printf(_(" -n, --dry-run do not actually do anything\n"));
printf(_(" -N, --no-sync do not wait for changes to be written safely to disk\n"));
printf(_(" -o, --output=DIRECTORY output directory\n"));