PostgreSQL Source Code git master
Loading...
Searching...
No Matches
reconstruct.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * reconstruct.c
4 * Reconstruct full file from incremental file and backup chain.
5 *
6 * Copyright (c) 2017-2026, PostgreSQL Global Development Group
7 *
8 * IDENTIFICATION
9 * src/bin/pg_combinebackup/reconstruct.c
10 *
11 *-------------------------------------------------------------------------
12 */
13#include "postgres_fe.h"
14
15#include <unistd.h>
16
18#include "common/file_perm.h"
19#include "common/logging.h"
20#include "copy_file.h"
21#include "lib/stringinfo.h"
22#include "reconstruct.h"
23#include "storage/block.h"
24
25/*
26 * An rfile stores the data that we need in order to be able to use some file
27 * on disk for reconstruction. For any given output file, we create one rfile
28 * per backup that we need to consult when we constructing that output file.
29 *
30 * If we find a full version of the file in the backup chain, then only
31 * filename and fd are initialized; the remaining fields are 0 or NULL.
32 * For an incremental file, header_length, num_blocks, relative_block_numbers,
33 * and truncation_block_length are also set.
34 *
35 * num_blocks_read and highest_offset_read always start out as 0.
36 */
48
49static void debug_reconstruction(int n_source,
50 rfile **sources,
51 bool dry_run);
52static unsigned find_reconstructed_block_length(const rfile *s);
53static rfile *make_incremental_rfile(const char *filename);
54static rfile *make_rfile(const char *filename, bool missing_ok);
55static void write_reconstructed_file(const char *input_filename,
56 const char *output_filename,
57 unsigned block_length,
59 const off_t *offsetmap,
60 pg_checksum_context *checksum_ctx,
61 CopyMethod copy_method,
62 bool debug,
63 bool dry_run);
64static void read_bytes(const rfile *rf, void *buffer, size_t length);
65static void write_block(int fd, const char *output_filename,
66 const uint8 *buffer,
67 pg_checksum_context *checksum_ctx);
68static void read_block(const rfile *s, off_t off, uint8 *buffer);
69
70/*
71 * Reconstruct a full file from an incremental file and a chain of prior
72 * backups.
73 *
74 * input_filename should be the path to the incremental file, and
75 * output_filename should be the path where the reconstructed file is to be
76 * written.
77 *
78 * relative_path should be the path to the directory containing this file,
79 * relative to the root of the backup (NOT relative to the root of the
80 * tablespace). It must always end with a trailing slash. bare_file_name
81 * should be the name of the file within that directory, without
82 * "INCREMENTAL.".
83 *
84 * n_prior_backups is the number of prior backups, and prior_backup_dirs is
85 * an array of pathnames where those backups can be found.
86 */
87void
89 char *output_filename,
90 char *relative_path,
91 char *bare_file_name,
93 char **prior_backup_dirs,
95 char *manifest_path,
96 pg_checksum_type checksum_type,
97 int *checksum_length,
98 uint8 **checksum_payload,
99 CopyMethod copy_method,
100 bool debug,
101 bool dry_run)
102{
103 rfile **source;
107 unsigned block_length;
108 unsigned sidx = n_prior_backups;
109 bool full_copy_possible = true;
110 int copy_source_index = -1;
112 pg_checksum_context checksum_ctx;
113
114 /* Sanity check the relative_path. */
115 Assert(relative_path[0] != '\0');
117
118 /*
119 * Every block must come either from the latest version of the file or
120 * from one of the prior backups.
121 */
123
124 /*
125 * Use the information from the latest incremental file to figure out how
126 * long the reconstructed file should be.
127 */
131
132 /*
133 * For each block in the output file, we need to know from which file we
134 * need to obtain it and at what offset in that file it's stored.
135 * sourcemap gives us the first of these things, and offsetmap the latter.
136 */
139
140 /*
141 * Every block that is present in the newest incremental file should be
142 * sourced from that file. If it precedes the truncation_block_length,
143 * it's a block that we would otherwise have had to find in an older
144 * backup and thus reduces the number of blocks remaining to be found by
145 * one; otherwise, it's an extra block that needs to be included in the
146 * output but would not have needed to be found in an older backup if it
147 * had not been present.
148 */
149 for (unsigned i = 0; i < latest_source->num_blocks; ++i)
150 {
151 BlockNumber b = latest_source->relative_block_numbers[i];
152
155 offsetmap[b] = latest_source->header_length + (i * BLCKSZ);
156
157 /*
158 * A full copy of a file from an earlier backup is only possible if no
159 * blocks are needed from any later incremental file.
160 */
161 full_copy_possible = false;
162 }
163
164 while (1)
165 {
167 rfile *s;
168
169 /*
170 * Move to the next backup in the chain. If there are no more, then
171 * we're done.
172 */
173 if (sidx == 0)
174 break;
175 --sidx;
176
177 /*
178 * Look for the full file in the previous backup. If not found, then
179 * look for an incremental file instead.
180 */
183 if ((s = make_rfile(source_filename, true)) == NULL)
184 {
185 snprintf(source_filename, MAXPGPATH, "%s/%sINCREMENTAL.%s",
188 }
189 source[sidx] = s;
190
191 /*
192 * If s->header_length == 0, then this is a full file; otherwise, it's
193 * an incremental file.
194 */
195 if (s->header_length == 0)
196 {
197 struct stat sb;
200
201 /* We need to know the length of the file. */
202 if (fstat(s->fd, &sb) < 0)
203 pg_fatal("could not stat file \"%s\": %m", s->filename);
204
205 /*
206 * Since we found a full file, source all blocks from it that
207 * exist in the file.
208 *
209 * Note that there may be blocks that don't exist either in this
210 * file or in any incremental file but that precede
211 * truncation_block_length. These are, presumably, zero-filled
212 * blocks that result from the server extending the file but
213 * taking no action on those blocks that generated any WAL.
214 *
215 * Sadly, we have no way of validating that this is really what
216 * happened, and neither does the server. From its perspective,
217 * an unmodified block that contains data looks exactly the same
218 * as a zero-filled block that never had any data: either way,
219 * it's not mentioned in any WAL summary and the server has no
220 * reason to read it. From our perspective, all we know is that
221 * nobody had a reason to back up the block. That certainly means
222 * that the block didn't exist at the time of the full backup, but
223 * the supposition that it was all zeroes at the time of every
224 * later backup is one that we can't validate.
225 */
226 blocklength = sb.st_size / BLCKSZ;
227 for (b = 0; b < latest_source->truncation_block_length; ++b)
228 {
229 if (sourcemap[b] == NULL && b < blocklength)
230 {
231 sourcemap[b] = s;
232 offsetmap[b] = b * BLCKSZ;
233 }
234 }
235
236 /*
237 * If a full copy looks possible, check whether the resulting file
238 * should be exactly as long as the source file is. If so, a full
239 * copy is acceptable, otherwise not.
240 */
242 {
244
248 if (expected_length == sb.st_size)
249 {
250 copy_source = s;
252 }
253 }
254
255 /* We don't need to consider any further sources. */
256 break;
257 }
258
259 /*
260 * Since we found another incremental file, source all blocks from it
261 * that we need but don't yet have.
262 */
263 for (unsigned i = 0; i < s->num_blocks; ++i)
264 {
266
267 if (b < latest_source->truncation_block_length &&
268 sourcemap[b] == NULL)
269 {
270 sourcemap[b] = s;
271 offsetmap[b] = s->header_length + (i * BLCKSZ);
272
273 /*
274 * A full copy of a file from an earlier backup is only
275 * possible if no blocks are needed from any later incremental
276 * file.
277 */
278 full_copy_possible = false;
279 }
280 }
281 }
282
283 /*
284 * If a checksum of the required type already exists in the
285 * backup_manifest for the relevant input directory, we can save some work
286 * by reusing that checksum instead of computing a new one.
287 */
289 checksum_type != CHECKSUM_TYPE_NONE)
290 {
291 manifest_file *mfile;
292
295 if (mfile == NULL)
296 {
297 char *path = psprintf("%s/backup_manifest",
299
300 /*
301 * The directory is out of sync with the backup_manifest, so emit
302 * a warning.
303 */
304 pg_log_warning("manifest file \"%s\" contains no entry for file \"%s\"",
305 path,
307 pfree(path);
308 }
309 else if (mfile->checksum_type == checksum_type)
310 {
311 *checksum_length = mfile->checksum_length;
312 *checksum_payload = pg_malloc(*checksum_length);
313 memcpy(*checksum_payload, mfile->checksum_payload,
314 *checksum_length);
315 checksum_type = CHECKSUM_TYPE_NONE;
316 }
317 }
318
319 /* Prepare for checksum calculation, if required. */
320 pg_checksum_init(&checksum_ctx, checksum_type);
321
322 /*
323 * If the full file can be created by copying a file from an older backup
324 * in the chain without needing to overwrite any blocks or truncate the
325 * result, then forget about performing reconstruction and just copy that
326 * file in its entirety.
327 *
328 * If we have only incremental files, and there's no full file at any
329 * point in the backup chain, something has gone wrong. Emit an error.
330 *
331 * Otherwise, reconstruct.
332 */
333 if (copy_source != NULL)
335 &checksum_ctx, copy_method, dry_run);
336 else if (sidx == 0 && source[0]->header_length != 0)
337 {
338 pg_fatal("full backup contains unexpected incremental file \"%s\"",
339 source[0]->filename);
340 }
341 else
342 {
345 &checksum_ctx, copy_method,
346 debug, dry_run);
348 }
349
350 /* Save results of checksum calculation. */
351 if (checksum_type != CHECKSUM_TYPE_NONE)
352 {
353 *checksum_payload = pg_malloc(PG_CHECKSUM_MAX_LENGTH);
354 *checksum_length = pg_checksum_final(&checksum_ctx,
355 *checksum_payload);
356 }
357
358 /*
359 * Close files and release memory.
360 */
361 for (int i = 0; i <= n_prior_backups; ++i)
362 {
363 rfile *s = source[i];
364
365 if (s == NULL)
366 continue;
367 if (close(s->fd) != 0)
368 pg_fatal("could not close file \"%s\": %m", s->filename);
371 pg_free(s->filename);
372 pg_free(s);
373 }
377}
378
379/*
380 * Perform post-reconstruction logging and sanity checks.
381 */
382static void
384{
385 for (int i = 0; i < n_source; ++i)
386 {
387 rfile *s = sources[i];
388
389 /* Ignore source if not used. */
390 if (s == NULL)
391 continue;
392
393 /* If no data is needed from this file, we can ignore it. */
394 if (s->num_blocks_read == 0)
395 continue;
396
397 /* Debug logging. */
398 if (dry_run)
399 pg_log_debug("would have read %u blocks from \"%s\"",
401 else
402 pg_log_debug("read %u blocks from \"%s\"",
404
405 /*
406 * In dry-run mode, we don't actually try to read data from the file,
407 * but we do try to verify that the file is long enough that we could
408 * have read the data if we'd tried.
409 *
410 * If this fails, then it means that a non-dry-run attempt would fail,
411 * complaining of not being able to read the required bytes from the
412 * file.
413 */
414 if (dry_run)
415 {
416 struct stat sb;
417
418 if (fstat(s->fd, &sb) < 0)
419 pg_fatal("could not stat file \"%s\": %m", s->filename);
420 if (sb.st_size < s->highest_offset_read)
421 pg_fatal("file \"%s\" is too short: expected %lld, found %lld",
422 s->filename,
423 (long long) s->highest_offset_read,
424 (long long) sb.st_size);
425 }
426 }
427}
428
429/*
430 * When we perform reconstruction using an incremental file, the output file
431 * should be at least as long as the truncation_block_length. Any blocks
432 * present in the incremental file increase the output length as far as is
433 * necessary to include those blocks.
434 */
435static unsigned
437{
439 unsigned i;
440
441 for (i = 0; i < s->num_blocks; ++i)
444
445 return block_length;
446}
447
448/*
449 * Initialize an incremental rfile, reading the header so that we know which
450 * blocks it contains.
451 */
452static rfile *
454{
455 rfile *rf;
456 unsigned magic;
457
458 rf = make_rfile(filename, false);
459
460 /* Read and validate magic number. */
461 read_bytes(rf, &magic, sizeof(magic));
462 if (magic != INCREMENTAL_MAGIC)
463 pg_fatal("file \"%s\" has bad incremental magic number (0x%x, expected 0x%x)",
465
466 /* Read block count. */
467 read_bytes(rf, &rf->num_blocks, sizeof(rf->num_blocks));
468 if (rf->num_blocks > RELSEG_SIZE)
469 pg_fatal("file \"%s\" has block count %u in excess of segment size %u",
470 filename, rf->num_blocks, RELSEG_SIZE);
471
472 /* Read truncation block length. */
473 read_bytes(rf, &rf->truncation_block_length,
474 sizeof(rf->truncation_block_length));
475 if (rf->truncation_block_length > RELSEG_SIZE)
476 pg_fatal("file \"%s\" has truncation block length %u in excess of segment size %u",
477 filename, rf->truncation_block_length, RELSEG_SIZE);
478
479 /* Read block numbers if there are any. */
480 if (rf->num_blocks > 0)
481 {
482 rf->relative_block_numbers =
483 pg_malloc0_array(BlockNumber, rf->num_blocks);
484 read_bytes(rf, rf->relative_block_numbers,
485 sizeof(BlockNumber) * rf->num_blocks);
486 }
487
488 /* Remember length of header. */
489 rf->header_length = sizeof(magic) + sizeof(rf->num_blocks) +
490 sizeof(rf->truncation_block_length) +
491 sizeof(BlockNumber) * rf->num_blocks;
492
493 /*
494 * Round header length to a multiple of BLCKSZ, so that blocks contents
495 * are properly aligned. Only do this when the file actually has data for
496 * some blocks.
497 */
498 if ((rf->num_blocks > 0) && ((rf->header_length % BLCKSZ) != 0))
499 rf->header_length += (BLCKSZ - (rf->header_length % BLCKSZ));
500
501 return rf;
502}
503
504/*
505 * Allocate and perform basic initialization of an rfile.
506 */
507static rfile *
508make_rfile(const char *filename, bool missing_ok)
509{
510 rfile *rf;
511
513 rf->filename = pstrdup(filename);
514 if ((rf->fd = open(filename, O_RDONLY | PG_BINARY, 0)) < 0)
515 {
516 if (missing_ok && errno == ENOENT)
517 {
518 pfree(rf->filename);
519 pg_free(rf);
520 return NULL;
521 }
522 pg_fatal("could not open file \"%s\": %m", filename);
523 }
524
525 return rf;
526}
527
528/*
529 * Read the indicated number of bytes from an rfile into the buffer.
530 */
531static void
532read_bytes(const rfile *rf, void *buffer, size_t length)
533{
534 ssize_t rb;
535
536 rb = read(rf->fd, buffer, length);
537
538 if (rb != length)
539 {
540 if (rb < 0)
541 pg_fatal("could not read file \"%s\": %m", rf->filename);
542 else
543 pg_fatal("could not read file \"%s\": read %zd of %zu",
544 rf->filename, rb, length);
545 }
546}
547
548/*
549 * Write out a reconstructed file.
550 */
551static void
553 const char *output_filename,
554 unsigned block_length,
556 const off_t *offsetmap,
557 pg_checksum_context *checksum_ctx,
558 CopyMethod copy_method,
559 bool debug,
560 bool dry_run)
561{
562 int wfd = -1;
563 unsigned i;
564 unsigned zero_blocks = 0;
565
566 /* Debugging output. */
567 if (debug)
568 {
570 unsigned start_of_range = 0;
571 unsigned current_block = 0;
572
573 /* Basic information about the output file to be produced. */
574 if (dry_run)
575 pg_log_debug("would reconstruct \"%s\" (%u blocks, checksum %s)",
577 pg_checksum_type_name(checksum_ctx->type));
578 else
579 pg_log_debug("reconstructing \"%s\" (%u blocks, checksum %s)",
581 pg_checksum_type_name(checksum_ctx->type));
582
583 /* Print out the plan for reconstructing this file. */
585 while (current_block < block_length)
586 {
587 rfile *s = sourcemap[current_block];
588
589 /* Extend range, if possible. */
590 if (current_block + 1 < block_length &&
591 s == sourcemap[current_block + 1])
592 {
593 ++current_block;
594 continue;
595 }
596
597 /* Add details about this range. */
598 if (s == NULL)
599 {
600 if (current_block == start_of_range)
601 appendStringInfo(&debug_buf, " %u:zero", current_block);
602 else
603 appendStringInfo(&debug_buf, " %u-%u:zero",
604 start_of_range, current_block);
605 }
606 else
607 {
608 if (current_block == start_of_range)
610 current_block, s->filename,
611 (uint64) offsetmap[current_block]);
612 else
614 start_of_range, current_block,
615 s->filename,
616 (uint64) offsetmap[current_block]);
617 }
618
619 /* Begin new range. */
620 start_of_range = ++current_block;
621
622 /* If the output is very long or we are done, dump it now. */
623 if (current_block == block_length || debug_buf.len > 1024)
624 {
625 pg_log_debug("reconstruction plan:%s", debug_buf.data);
627 }
628 }
629
630 /* Free memory. */
631 pfree(debug_buf.data);
632 }
633
634 /* Open the output file, except in dry_run mode. */
635 if (!dry_run &&
639 pg_fatal("could not open file \"%s\": %m", output_filename);
640
641 /* Read and write the blocks as required. */
642 for (i = 0; i < block_length; ++i)
643 {
644 uint8 buffer[BLCKSZ];
645 rfile *s = sourcemap[i];
646
647 /* Update accounting information. */
648 if (s == NULL)
649 ++zero_blocks;
650 else
651 {
652 s->num_blocks_read++;
654 offsetmap[i] + BLCKSZ);
655 }
656
657 /* Skip the rest of this in dry-run mode. */
658 if (dry_run)
659 continue;
660
661 /* Read or zero-fill the block as appropriate. */
662 if (s == NULL)
663 {
664 /*
665 * New block not mentioned in the WAL summary. Should have been an
666 * uninitialized block, so just zero-fill it.
667 */
668 memset(buffer, 0, BLCKSZ);
669
670 /* Write out the block, update the checksum if needed. */
671 write_block(wfd, output_filename, buffer, checksum_ctx);
672
673 /* Nothing else to do for zero-filled blocks. */
674 continue;
675 }
676
677 /* Copy the block using the appropriate copy method. */
678 if (copy_method != COPY_METHOD_COPY_FILE_RANGE)
679 {
680 /*
681 * Read the block from the correct source file, and then write it
682 * out, possibly with a checksum update.
683 */
684 read_block(s, offsetmap[i], buffer);
685 write_block(wfd, output_filename, buffer, checksum_ctx);
686 }
687 else /* use copy_file_range */
688 {
689#if defined(HAVE_COPY_FILE_RANGE)
690 /* copy_file_range modifies the offset, so use a local copy */
691 off_t off = offsetmap[i];
692 size_t nwritten = 0;
693
694 /*
695 * Retry until we've written all the bytes (the offset is updated
696 * by copy_file_range, and so is the wfd file offset).
697 */
698 do
699 {
700 ssize_t wb;
701
702 wb = copy_file_range(s->fd, &off, wfd, NULL, BLCKSZ - nwritten, 0);
703
704 if (wb < 0)
705 pg_fatal("error while copying file range from \"%s\" to \"%s\": %m",
707 else if (wb == 0)
708 pg_fatal("unexpected end of file while copying file range from \"%s\" to \"%s\"",
710
711 nwritten += wb;
712
713 } while (BLCKSZ > nwritten);
714
715 /*
716 * When checksum calculation not needed, we're done, otherwise
717 * read the block and pass it to the checksum calculation.
718 */
719 if (checksum_ctx->type == CHECKSUM_TYPE_NONE)
720 continue;
721
722 read_block(s, offsetmap[i], buffer);
723
724 if (pg_checksum_update(checksum_ctx, buffer, BLCKSZ) < 0)
725 pg_fatal("could not update checksum of file \"%s\"",
727#else
728 pg_fatal("copy_file_range not supported on this platform");
729#endif
730 }
731 }
732
733 /* Debugging output. */
734 if (zero_blocks > 0)
735 {
736 if (dry_run)
737 pg_log_debug("would have zero-filled %u blocks", zero_blocks);
738 else
739 pg_log_debug("zero-filled %u blocks", zero_blocks);
740 }
741
742 /* Close the output file. */
743 if (wfd >= 0 && close(wfd) != 0)
744 pg_fatal("could not close file \"%s\": %m", output_filename);
745}
746
747/*
748 * Write the block into the file (using the file descriptor), and
749 * if needed update the checksum calculation.
750 *
751 * The buffer is expected to contain BLCKSZ bytes. The filename is
752 * provided only for the error message.
753 */
754static void
756 const uint8 *buffer, pg_checksum_context *checksum_ctx)
757{
758 ssize_t wb;
759
760 if ((wb = write(fd, buffer, BLCKSZ)) != BLCKSZ)
761 {
762 if (wb < 0)
763 pg_fatal("could not write file \"%s\": %m", output_filename);
764 else
765 pg_fatal("could not write file \"%s\": wrote %zd of %zu",
766 output_filename, wb, (size_t) BLCKSZ);
767 }
768
769 /* Update the checksum computation. */
770 if (pg_checksum_update(checksum_ctx, buffer, BLCKSZ) < 0)
771 pg_fatal("could not update checksum of file \"%s\"",
773}
774
775/*
776 * Read a block of data (BLCKSZ bytes) into the buffer.
777 */
778static void
779read_block(const rfile *s, off_t off, uint8 *buffer)
780{
781 ssize_t rb;
782
783 /* Read the block from the correct source, except if dry-run. */
784 rb = pg_pread(s->fd, buffer, BLCKSZ, off);
785 if (rb != BLCKSZ)
786 {
787 if (rb < 0)
788 pg_fatal("could not read from file \"%s\": %m", s->filename);
789 else
790 pg_fatal("could not read from file \"%s\", offset %lld: read %zd of %zu",
791 s->filename, (long long) off, rb, (size_t) BLCKSZ);
792 }
793}
#define INCREMENTAL_MAGIC
uint32 BlockNumber
Definition block.h:31
uint8_t uint8
Definition c.h:681
#define Max(x, y)
Definition c.h:1125
#define Assert(condition)
Definition c.h:1002
#define PG_BINARY
Definition c.h:1431
#define UINT64_FORMAT
Definition c.h:694
uint64_t uint64
Definition c.h:684
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
int pg_checksum_final(pg_checksum_context *context, uint8 *output)
char * pg_checksum_type_name(pg_checksum_type type)
int pg_checksum_update(pg_checksum_context *context, const uint8 *input, size_t len)
int pg_checksum_init(pg_checksum_context *context, pg_checksum_type type)
#define PG_CHECKSUM_MAX_LENGTH
pg_checksum_type
@ CHECKSUM_TYPE_NONE
CopyMethod
Definition copy_file.h:20
@ COPY_METHOD_COPY_FILE_RANGE
Definition copy_file.h:23
void copy_file(const char *fromfile, const char *tofile)
Definition copydir.c:134
char * output_filename
Definition ecpg.c:24
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_malloc0_array(type, count)
Definition fe_memutils.h:67
int pg_file_create_mode
Definition file_perm.c:19
static bool debug
Definition initdb.c:161
#define close(a)
Definition win32.h:12
#define write(a, b, c)
Definition win32.h:14
#define read(a, b, c)
Definition win32.h:13
int b
Definition isn.c:74
int i
Definition isn.c:77
#define pg_log_debug(...)
Definition logging.h:135
char * pstrdup(const char *in)
Definition mcxt.c:1910
void pfree(void *pointer)
Definition mcxt.c:1619
#define pg_fatal(...)
#define MAXPGPATH
static bool dry_run
static char * filename
Definition pg_dumpall.c:120
static rewind_source * source
Definition pg_rewind.c:89
#define pg_log_warning(...)
Definition pgfnames.c:24
#define pg_pread
Definition port.h:248
#define snprintf
Definition port.h:261
static int fd(const char *x, int i)
static int fb(int x)
char * input_filename
char * psprintf(const char *fmt,...)
Definition psprintf.c:43
static void read_block(const rfile *s, off_t off, uint8 *buffer)
static void debug_reconstruction(int n_source, rfile **sources, bool dry_run)
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
static void write_block(int fd, const char *output_filename, const uint8 *buffer, pg_checksum_context *checksum_ctx)
static void read_bytes(const rfile *rf, void *buffer, size_t length)
static rfile * make_rfile(const char *filename, bool missing_ok)
static rfile * make_incremental_rfile(const char *filename)
static unsigned find_reconstructed_block_length(const rfile *s)
static void write_reconstructed_file(const char *input_filename, const char *output_filename, unsigned block_length, rfile **sourcemap, const off_t *offsetmap, pg_checksum_context *checksum_ctx, CopyMethod copy_method, bool debug, bool dry_run)
void resetStringInfo(StringInfo str)
Definition stringinfo.c:126
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition stringinfo.c:145
void initStringInfo(StringInfo str)
Definition stringinfo.c:97
uint8 * checksum_payload
pg_checksum_type checksum_type
pg_checksum_type type
off_t highest_offset_read
Definition reconstruct.c:46
BlockNumber * relative_block_numbers
Definition reconstruct.c:43
int fd
Definition reconstruct.c:40
unsigned num_blocks
Definition reconstruct.c:42
size_t header_length
Definition reconstruct.c:41
unsigned num_blocks_read
Definition reconstruct.c:45
char * filename
Definition reconstruct.c:39
unsigned truncation_block_length
Definition reconstruct.c:44
#define fstat
Definition win32_port.h:73