pg_combinebackup: Add -k, --link option.
authorRobert Haas <rhaas@postgresql.org>
Mon, 17 Mar 2025 18:03:14 +0000 (14:03 -0400)
committerRobert Haas <rhaas@postgresql.org>
Mon, 17 Mar 2025 18:03:14 +0000 (14:03 -0400)
commit99aeb84703177308c1541e2d11c09fdc59acb724
tree8dd572c268bba0ff07ef3ec8296c350d5f31753d
parented762e94253d5dd7810da13b8dd802baa876c55e
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 <barthisrael@gmail.com>
Co-authored-by: Robert Haas <robertmhaas@gmail.com> (cosmetic changes)
Reviewed-by: Vignesh C <vignesh21@gmail.com>
Discussion: http://postgr.es/m/CA+TgmoaEFsYHsMefNaNkU=2SnMRufKE3eVJxvAaX=OWgcnPmPg@mail.gmail.com
doc/src/sgml/ref/pg_combinebackup.sgml
src/bin/pg_combinebackup/copy_file.c
src/bin/pg_combinebackup/copy_file.h
src/bin/pg_combinebackup/meson.build
src/bin/pg_combinebackup/pg_combinebackup.c
src/bin/pg_combinebackup/t/010_hardlink.pl [new file with mode: 0644]