42#define ESTIMATED_BYTES_PER_MANIFEST_LINE 100
47#define READ_CHUNK_SIZE (128 * 1024)
61 int manifest_version);
63 uint64 manifest_system_identifier);
65 const char *pathname,
uint64 size,
68 uint8 *checksum_payload);
86 uint64 manifest_system_identifier);
153 memset(&context, 0,
sizeof(context));
157 if (
strcmp(argv[1],
"--help") == 0 ||
strcmp(argv[1],
"-?") == 0)
162 if (
strcmp(argv[1],
"--version") == 0 ||
strcmp(argv[1],
"-V") == 0)
195 context.exit_on_error =
true;
211 context.format =
'p';
213 context.format =
't';
215 pg_fatal(
"invalid backup format \"%s\", must be \"plain\" or \"tar\"",
228 context.skip_checksums =
true;
254 pg_log_error(
"too many command-line arguments (first is \"%s\")",
262 pg_fatal(
"cannot specify both %s and %s",
263 "-P/--progress",
"-q/--quiet");
282 pg_fatal(
"program \"%s\" is needed by %s but was not found in the same directory as \"%s\"",
283 "pg_waldump",
"pg_verifybackup",
full_path);
285 pg_fatal(
"program \"%s\" was found by \"%s\" but was not the same version as %s",
286 "pg_waldump",
full_path,
"pg_verifybackup");
293 context.backup_directory);
305 dir =
opendir(context.backup_directory);
308 context.backup_directory);
316 if (context.format ==
'\0')
321 path =
psprintf(
"%s/%s", context.backup_directory,
"PG_VERSION");
323 context.format =
'p';
332 context.format =
't';
341 if (context.format ==
'p')
360 if (context.format ==
'p' && !context.skip_checksums)
371 if (context.format ==
'p')
381 "Or you must use -n/--no-parse-wal when verifying a tar-format backup.");
397 if (!context.saw_any_error && !quiet)
398 printf(
_(
"backup successfully verified\n"));
400 return context.saw_any_error ? 1 : 0;
448 if (
statbuf.st_size <= chunk_size)
457 pg_fatal(
"could not read file \"%s\": read %d of %lld",
495 pg_fatal(
"could not read file \"%s\": read %lld of %lld",
498 (
long long int)
statbuf.st_size);
540 int manifest_version)
545 manifest->version = manifest_version;
553 uint64 manifest_system_identifier)
558 manifest->system_identifier = manifest_system_identifier;
566 const char *pathname,
uint64 size,
568 int checksum_length,
uint8 *checksum_payload)
604 range->start_lsn = start_lsn;
605 range->end_lsn = end_lsn;
632 char *fullpath,
DIR *dir)
640 "could not open directory \"%s\": %m", fullpath);
672 "could not close directory \"%s\": %m", fullpath);
690 if (
stat(fullpath, &
sb) != 0)
693 "could not stat file or directory \"%s\": %m",
716 "\"%s\" is not a regular file or directory",
726 "\"%s\" is present on disk but not in the manifest",
735 if (m->size !=
sb.st_size)
738 "\"%s\" has size %llu on disk but size %llu in the manifest",
739 relpath, (
unsigned long long)
sb.st_size,
740 (
unsigned long long) m->size);
791 manifest_system_identifier,
844 "could not close directory \"%s\": %m",
863 tar->compress_algorithm);
915 if (
stat(fullpath, &
sb) != 0)
918 "could not stat file or directory \"%s\": %m",
927 "file \"%s\" is not a regular file",
963 "file \"%s\" is not expected in a tar format backup",
967 tblspc_oid = (
Oid) num;
974 "file \"%s\" is not expected in a tar format backup",
997 tar->tblspc_oid = tblspc_oid;
998 tar->compress_algorithm = compress_algorithm;
1071 "\"%s\" is present in the manifest but not on disk",
1122 char *fullpath,
uint8 *buffer)
1191 "file \"%s\" should contain %" PRIu64 " bytes, but read %" PRIu64,
1201 "could not finalize checksum of file \"%s\"",
1209 "file \"%s\" has checksum of length %d, but expected %d",
1213 "checksum mismatch for file \"%s\"",
1239 "WAL parsing failed for timeline %u",
1296 char *v = cell->
val;
1298 while (*v !=
'\0' && *r == *v)
1301 if (*v ==
'\0' && (*r ==
'\0' || *r ==
'/'))
1373 _(
"%*s/%s kB (%d%%) verified"),
1390 printf(
_(
"%s verifies a backup against the backup manifest.\n\n"),
progname);
1393 printf(
_(
" -e, --exit-on-error exit immediately on error\n"));
1394 printf(
_(
" -F, --format=p|t backup format (plain, tar)\n"));
1395 printf(
_(
" -i, --ignore=RELATIVE_PATH ignore indicated path\n"));
1396 printf(
_(
" -m, --manifest-path=PATH use specified path for manifest\n"));
1397 printf(
_(
" -n, --no-parse-wal do not try to parse WAL files\n"));
1398 printf(
_(
" -P, --progress show progress information\n"));
1399 printf(
_(
" -q, --quiet do not print any output, except for errors\n"));
1400 printf(
_(
" -s, --skip-checksums skip checksum verification\n"));
1401 printf(
_(
" -w, --wal-path=PATH use specified path for WAL files\n"));
1402 printf(
_(
" -V, --version output version information, then exit\n"));
1403 printf(
_(
" -?, --help show this help, then exit\n"));
static void astreamer_free(astreamer *streamer)
static void astreamer_content(astreamer *streamer, astreamer_member *member, const char *data, int len, astreamer_archive_context context)
static void astreamer_finalize(astreamer *streamer)
astreamer * astreamer_gzip_decompressor_new(astreamer *next)
astreamer * astreamer_lz4_decompressor_new(astreamer *next)
astreamer * astreamer_tar_parser_new(astreamer *next)
astreamer * astreamer_verify_content_new(astreamer *next, verifier_context *context, char *archive_name, Oid tblspc_oid)
astreamer * astreamer_zstd_decompressor_new(astreamer *next)
Datum now(PG_FUNCTION_ARGS)
#define Assert(condition)
#define PG_TEXTDOMAIN(domain)
#define pg_attribute_printf(f, a)
int pg_checksum_final(pg_checksum_context *context, uint8 *output)
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
int find_my_exec(const char *argv0, char *retpath)
void set_pglocale_pgservice(const char *argv0, const char *app)
int find_other_exec(const char *argv0, const char *target, const char *versionstr, char *retpath)
bool parse_tar_compress_algorithm(const char *fname, pg_compress_algorithm *algorithm)
ControlFileData * get_controlfile_by_exact_path(const char *ControlFilePath, bool *crc_ok_p)
#define fprintf(file, fmt, msg)
struct dirent * readdir(DIR *)
DIR * opendir(const char *)
void * pg_malloc(size_t size)
#define pg_malloc_array(type, count)
#define palloc_object(type)
#define pg_malloc0_object(type)
#define pg_malloc_object(type)
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
#define required_argument
void pg_logging_init(const char *argv0)
void pg_log_generic_v(enum pg_log_level level, enum pg_log_part part, const char *pg_restrict fmt, va_list ap)
#define pg_log_error(...)
#define pg_log_error_hint(...)
#define pg_log_debug(...)
char * pstrdup(const char *in)
void pfree(void *pointer)
void json_parse_manifest(JsonManifestParseContext *context, const char *buffer, size_t size)
JsonManifestParseIncrementalState * json_parse_manifest_incremental_init(JsonManifestParseContext *context)
void json_parse_manifest_incremental_shutdown(JsonManifestParseIncrementalState *incstate)
void json_parse_manifest_incremental_chunk(JsonManifestParseIncrementalState *incstate, const char *chunk, size_t size, bool is_last)
static pg_time_t last_progress_report
#define PG_CONTROL_VERSION
PGDLLIMPORT char * optarg
static void verify_backup_checksums(verifier_context *context)
static manifest_data * parse_manifest_file(char *manifest_path)
static void verify_tar_file(verifier_context *context, char *relpath, char *fullpath, astreamer *streamer)
void report_fatal_error(const char *pg_restrict fmt,...)
static void verifybackup_version_cb(JsonManifestParseContext *context, int manifest_version)
static void verifybackup_system_identifier(JsonManifestParseContext *context, uint64 manifest_system_identifier)
bool should_ignore_relpath(verifier_context *context, const char *relpath)
static void verifybackup_per_wal_range_cb(JsonManifestParseContext *context, TimeLineID tli, XLogRecPtr start_lsn, XLogRecPtr end_lsn)
static void verify_plain_backup_directory(verifier_context *context, char *relpath, char *fullpath, DIR *dir)
static void report_extra_backup_files(verifier_context *context)
#define ESTIMATED_BYTES_PER_MANIFEST_LINE
static void precheck_tar_backup_file(verifier_context *context, char *relpath, char *fullpath, SimplePtrList *tarfiles, char **base_archive_path, char **wal_archive_path)
static void progress_report(bool finished)
static void parse_required_wal(verifier_context *context, char *pg_waldump_path, char *wal_path)
static astreamer * create_archive_verifier(verifier_context *context, char *archive_name, Oid tblspc_oid, pg_compress_algorithm compress_algo)
static bool show_progress
static pg_noreturn void report_manifest_error(JsonManifestParseContext *context, const char *fmt,...) pg_attribute_printf(2
void report_backup_error(verifier_context *context, const char *pg_restrict fmt,...)
static pg_noreturn void static void verify_tar_backup(verifier_context *context, DIR *dir, char **base_archive_path, char **wal_archive_path)
static const char * progname
static void verify_plain_backup_file(verifier_context *context, char *relpath, char *fullpath)
static void verify_file_checksum(verifier_context *context, manifest_file *m, char *fullpath, uint8 *buffer)
static void verify_control_file(const char *controlpath, uint64 manifest_system_identifier)
static void verifybackup_per_file_cb(JsonManifestParseContext *context, const char *pathname, uint64 size, pg_checksum_type checksum_type, int checksum_length, uint8 *checksum_payload)
#define should_verify_checksum(m)
void canonicalize_path(char *path)
const char * get_progname(const char *argv0)
size_t strlcpy(char *dst, const char *src, size_t siz)
static int fd(const char *x, int i)
char * psprintf(const char *fmt,...)
static struct cvec * range(struct vars *v, chr a, chr b, int cases)
#define relpath(rlocator, forknum)
void simple_ptr_list_destroy(SimplePtrList *list)
void simple_string_list_append(SimpleStringList *list, const char *val)
void simple_ptr_list_append(SimplePtrList *list, void *ptr)
uint32 pg_control_version
json_manifest_per_wal_range_callback per_wal_range_cb
json_manifest_system_identifier_callback system_identifier_cb
json_manifest_error_callback error_cb
json_manifest_per_file_callback per_file_cb
json_manifest_version_callback version_cb
struct SimplePtrListCell * next
char val[FLEXIBLE_ARRAY_MEMBER]
struct SimpleStringListCell * next
SimpleStringListCell * head
manifest_files_hash * files
pg_checksum_type checksum_type
pg_compress_algorithm compress_algorithm
SimpleStringList ignore_list
#define XLOG_CONTROL_FILE
#define LSN_FORMAT_ARGS(lsn)