98 uint8 **checksum_payload,
298 char *path =
psprintf(
"%s/backup_manifest",
305 pg_log_warning(
"manifest file \"%s\" contains no entry for file \"%s\"",
313 *checksum_payload =
pg_malloc(*checksum_length);
336 &checksum_ctx, copy_method,
dry_run);
337 else if (
sidx == 0 &&
source[0]->header_length != 0)
339 pg_fatal(
"full backup contains unexpected incremental file \"%s\"",
346 &checksum_ctx, copy_method,
424 pg_fatal(
"file \"%s\" is too short: expected %llu, found %llu",
427 (
unsigned long long)
sb.st_size);
466 pg_fatal(
"file \"%s\" has bad incremental magic number (0x%x, expected 0x%x)",
472 pg_fatal(
"file \"%s\" has block count %u in excess of segment size %u",
477 sizeof(
rf->truncation_block_length));
479 pg_fatal(
"file \"%s\" has truncation block length %u in excess of segment size %u",
483 if (
rf->num_blocks > 0)
485 rf->relative_block_numbers =
492 rf->header_length =
sizeof(magic) +
sizeof(
rf->num_blocks) +
493 sizeof(
rf->truncation_block_length) +
501 if ((
rf->num_blocks > 0) && ((
rf->header_length %
BLCKSZ) != 0))
537 int rb =
read(
rf->fd, buffer, length);
542 pg_fatal(
"could not read file \"%s\": %m",
rf->filename);
544 pg_fatal(
"could not read file \"%s\": read %d of %u",
545 rf->filename,
rb, length);
572 unsigned current_block = 0;
576 pg_log_debug(
"would reconstruct \"%s\" (%u blocks, checksum %s)",
580 pg_log_debug(
"reconstructing \"%s\" (%u blocks, checksum %s)",
690#if defined(HAVE_COPY_FILE_RANGE)
706 pg_fatal(
"error while copying file range from \"%s\" to \"%s\": %m",
723 pg_fatal(
"could not update checksum of file \"%s\"",
726 pg_fatal(
"copy_file_range not supported on this platform");
763 pg_fatal(
"could not write file \"%s\": wrote %d of %d",
769 pg_fatal(
"could not update checksum of file \"%s\"",
788 pg_fatal(
"could not read from file \"%s\", offset %llu: read %d of %d",
#define INCREMENTAL_MAGIC
#define Assert(condition)
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
@ COPY_METHOD_COPY_FILE_RANGE
void copy_file(const char *fromfile, const char *tofile)
void * pg_malloc(size_t size)
void * pg_malloc0(size_t size)
#define pg_log_debug(...)
char * pstrdup(const char *in)
void pfree(void *pointer)
static rewind_source * source
#define pg_log_warning(...)
static int fd(const char *x, int i)
char * psprintf(const char *fmt,...)
static rfile * make_rfile(char *filename, bool missing_ok)
static rfile * make_incremental_rfile(char *filename)
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)
static void read_block(rfile *s, off_t off, uint8 *buffer)
static void read_bytes(rfile *rf, void *buffer, unsigned length)
static void write_reconstructed_file(char *input_filename, char *output_filename, unsigned block_length, rfile **sourcemap, off_t *offsetmap, pg_checksum_context *checksum_ctx, CopyMethod copy_method, bool debug, bool dry_run)
static unsigned find_reconstructed_block_length(rfile *s)
static void write_block(int fd, char *output_filename, uint8 *buffer, pg_checksum_context *checksum_ctx)
void resetStringInfo(StringInfo str)
void appendStringInfo(StringInfo str, const char *fmt,...)
void initStringInfo(StringInfo str)
pg_checksum_type checksum_type
off_t highest_offset_read
BlockNumber * relative_block_numbers
unsigned truncation_block_length