PostgreSQL Source Code git master
|
#include "postgres_fe.h"
#include <dirent.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <time.h>
#include "common/logging.h"
#include "common/parse_manifest.h"
#include "fe_utils/simple_list.h"
#include "getopt_long.h"
#include "limits.h"
#include "pg_verifybackup.h"
#include "pgtime.h"
Go to the source code of this file.
Data Structures | |
struct | tar_file |
Macros | |
#define | ESTIMATED_BYTES_PER_MANIFEST_LINE 100 |
#define | READ_CHUNK_SIZE (128 * 1024) |
Typedefs | |
typedef struct tar_file | tar_file |
Functions | |
static manifest_data * | parse_manifest_file (char *manifest_path) |
static void | verifybackup_version_cb (JsonManifestParseContext *context, int manifest_version) |
static void | verifybackup_system_identifier (JsonManifestParseContext *context, 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) |
static void | verifybackup_per_wal_range_cb (JsonManifestParseContext *context, TimeLineID tli, XLogRecPtr start_lsn, XLogRecPtr end_lsn) |
static void | report_manifest_error (JsonManifestParseContext *context, const char *fmt,...) pg_attribute_printf(2 |
static void | pg_attribute_noreturn () |
static void | verify_tar_backup (verifier_context *context, DIR *dir) |
static void | verify_plain_backup_directory (verifier_context *context, char *relpath, char *fullpath, DIR *dir) |
static void | verify_plain_backup_file (verifier_context *context, char *relpath, char *fullpath) |
static void | verify_control_file (const char *controlpath, uint64 manifest_system_identifier) |
static void | precheck_tar_backup_file (verifier_context *context, char *relpath, char *fullpath, SimplePtrList *tarfiles) |
static void | verify_tar_file (verifier_context *context, char *relpath, char *fullpath, astreamer *streamer) |
static void | report_extra_backup_files (verifier_context *context) |
static void | verify_backup_checksums (verifier_context *context) |
static void | verify_file_checksum (verifier_context *context, manifest_file *m, char *fullpath, uint8 *buffer) |
static void | parse_required_wal (verifier_context *context, char *pg_waldump_path, char *wal_directory) |
static astreamer * | create_archive_verifier (verifier_context *context, char *archive_name, Oid tblspc_oid, pg_compress_algorithm compress_algo) |
static void | progress_report (bool finished) |
static void | usage (void) |
int | main (int argc, char **argv) |
void | report_backup_error (verifier_context *context, const char *pg_restrict fmt,...) |
void | report_fatal_error (const char *pg_restrict fmt,...) |
bool | should_ignore_relpath (verifier_context *context, const char *relpath) |
Variables | |
static const char * | progname |
static bool | show_progress = false |
static uint64 | total_size = 0 |
static uint64 | done_size = 0 |
#define ESTIMATED_BYTES_PER_MANIFEST_LINE 100 |
Definition at line 41 of file pg_verifybackup.c.
#define READ_CHUNK_SIZE (128 * 1024) |
Definition at line 46 of file pg_verifybackup.c.
|
static |
Definition at line 1291 of file pg_verifybackup.c.
References Assert, astreamer_gzip_decompressor_new(), astreamer_lz4_decompressor_new(), astreamer_tar_parser_new(), astreamer_verify_content_new(), astreamer_zstd_decompressor_new(), verifier_context::format, PG_COMPRESSION_GZIP, PG_COMPRESSION_LZ4, and PG_COMPRESSION_ZSTD.
Referenced by verify_tar_backup().
int main | ( | int | argc, |
char ** | argv | ||
) |
Definition at line 117 of file pg_verifybackup.c.
References _, arg, canonicalize_path(), exit(), find_my_exec(), find_other_exec(), get_progname(), getopt_long(), MAXPGPATH, no_argument, opendir(), optarg, optind, parse_manifest_file(), parse_required_wal(), pfree(), pg_fatal, pg_log_error, pg_log_error_hint, pg_logging_init(), pg_malloc(), PG_TEXTDOMAIN, printf, progname, psprintf(), pstrdup(), report_extra_backup_files(), report_fatal_error(), required_argument, set_pglocale_pgservice(), show_progress, simple_string_list_append(), stat, strlcpy(), usage(), verify_backup_checksums(), verify_plain_backup_directory(), and verify_tar_backup().
|
static |
Definition at line 391 of file pg_verifybackup.c.
References close, JsonManifestParseContext::error_cb, ESTIMATED_BYTES_PER_MANIFEST_LINE, fd(), manifest_data::files, fstat, json_parse_manifest(), json_parse_manifest_incremental_chunk(), json_parse_manifest_incremental_init(), json_parse_manifest_incremental_shutdown(), Max, Min, JsonManifestParseContext::per_file_cb, JsonManifestParseContext::per_wal_range_cb, pfree(), PG_BINARY, pg_fatal, pg_malloc(), pg_malloc0(), PG_UINT32_MAX, JsonManifestParseContext::private_data, read, READ_CHUNK_SIZE, report_fatal_error(), report_manifest_error(), stat::st_size, JsonManifestParseContext::system_identifier_cb, verifybackup_per_file_cb(), verifybackup_per_wal_range_cb(), verifybackup_system_identifier(), verifybackup_version_cb(), and JsonManifestParseContext::version_cb.
Referenced by main().
|
static |
Definition at line 1200 of file pg_verifybackup.c.
References manifest_wal_range::end_lsn, fflush(), LSN_FORMAT_ARGS, manifest, verifier_context::manifest, manifest_wal_range::next, psprintf(), report_backup_error(), manifest_wal_range::start_lsn, and manifest_wal_range::tli.
Referenced by main().
static void pg_attribute_noreturn | ( | ) |
|
static |
Definition at line 880 of file pg_verifybackup.c.
References Assert, tar_file::compress_algorithm, verifier_context::format, InvalidOid, OID_MAX, PG_COMPRESSION_GZIP, PG_COMPRESSION_LZ4, PG_COMPRESSION_NONE, PG_COMPRESSION_ZSTD, pg_malloc(), pstrdup(), tar_file::relpath, relpath, report_backup_error(), S_ISREG, show_progress, simple_ptr_list_append(), stat::st_mode, stat::st_size, stat, tar_file::tblspc_oid, and total_size.
Referenced by verify_tar_backup().
|
static |
Definition at line 1327 of file pg_verifybackup.c.
References _, done_size, fprintf, last_progress_report, now(), show_progress, snprintf, total_size, and UINT64_FORMAT.
Referenced by verify_backup_checksums(), verify_file_checksum(), verify_tar_backup(), and verify_tar_file().
void report_backup_error | ( | verifier_context * | context, |
const char *pg_restrict | fmt, | ||
... | |||
) |
Definition at line 1231 of file pg_verifybackup.c.
References exit(), verifier_context::exit_on_error, fmt, gettext, PG_LOG_ERROR, pg_log_generic_v(), PG_LOG_PRIMARY, verifier_context::saw_any_error, va_end(), and va_start().
Referenced by member_compute_checksum(), member_verify_checksum(), member_verify_header(), parse_required_wal(), precheck_tar_backup_file(), report_extra_backup_files(), verify_file_checksum(), verify_plain_backup_directory(), verify_plain_backup_file(), verify_tar_backup(), and verify_tar_file().
|
static |
Definition at line 1038 of file pg_verifybackup.c.
References manifest, verifier_context::manifest, manifest_file::matched, manifest_file::pathname, report_backup_error(), and should_ignore_relpath().
Referenced by main().
void report_fatal_error | ( | const char *pg_restrict | fmt, |
... | |||
) |
Definition at line 1248 of file pg_verifybackup.c.
References exit(), fmt, gettext, PG_LOG_ERROR, pg_log_generic_v(), PG_LOG_PRIMARY, va_end(), and va_start().
Referenced by main(), member_verify_control_data(), parse_manifest_file(), verify_control_file(), and verifybackup_per_file_cb().
|
static |
Definition at line 508 of file pg_verifybackup.c.
References exit(), fmt, gettext, PG_LOG_ERROR, pg_log_generic_v(), PG_LOG_PRIMARY, va_end(), and va_start().
Referenced by parse_manifest_file().
bool should_ignore_relpath | ( | verifier_context * | context, |
const char * | relpath | ||
) |
Definition at line 1267 of file pg_verifybackup.c.
References SimpleStringList::head, verifier_context::ignore_list, SimpleStringListCell::next, relpath, and SimpleStringListCell::val.
Referenced by member_verify_header(), report_extra_backup_files(), verify_backup_checksums(), verify_plain_backup_directory(), and verify_tar_backup().
|
static |
|
static |
Definition at line 1058 of file pg_verifybackup.c.
References verifier_context::backup_directory, manifest, verifier_context::manifest, manifest_file::pathname, pfree(), pg_malloc(), progress_report(), psprintf(), READ_CHUNK_SIZE, should_ignore_relpath(), should_verify_checksum, and verify_file_checksum().
Referenced by main().
|
static |
Definition at line 754 of file pg_verifybackup.c.
References get_controlfile_by_exact_path(), pfree(), PG_CONTROL_VERSION, ControlFileData::pg_control_version, pg_log_debug, report_fatal_error(), and ControlFileData::system_identifier.
Referenced by verify_plain_backup_file().
|
static |
Definition at line 1098 of file pg_verifybackup.c.
References manifest_file::checksum_length, manifest_file::checksum_payload, manifest_file::checksum_type, close, done_size, fd(), manifest_file::pathname, PG_BINARY, pg_checksum_final(), pg_checksum_init(), PG_CHECKSUM_MAX_LENGTH, pg_checksum_update(), progress_report(), read, READ_CHUNK_SIZE, relpath, report_backup_error(), and manifest_file::size.
Referenced by verify_backup_checksums().
|
static |
Definition at line 615 of file pg_verifybackup.c.
References closedir(), dirent::d_name, filename, verifier_context::ignore_list, opendir(), pfree(), psprintf(), pstrdup(), readdir(), relpath, report_backup_error(), should_ignore_relpath(), simple_string_list_append(), and verify_plain_backup_file().
Referenced by main(), and verify_plain_backup_file().
|
static |
Definition at line 668 of file pg_verifybackup.c.
References manifest_data::files, verifier_context::ignore_list, verifier_context::manifest, relpath, report_backup_error(), S_ISDIR, S_ISREG, should_verify_checksum, show_progress, simple_string_list_append(), verifier_context::skip_checksums, stat::st_mode, stat::st_size, stat, manifest_data::system_identifier, total_size, verify_control_file(), verify_plain_backup_directory(), and manifest_data::version.
Referenced by verify_plain_backup_directory().
|
static |
Definition at line 789 of file pg_verifybackup.c.
References Assert, astreamer_finalize(), astreamer_free(), verifier_context::backup_directory, closedir(), tar_file::compress_algorithm, create_archive_verifier(), dirent::d_name, filename, verifier_context::format, SimplePtrList::head, SimplePtrListCell::next, pfree(), precheck_tar_backup_file(), progress_report(), psprintf(), SimplePtrListCell::ptr, readdir(), tar_file::relpath, report_backup_error(), should_ignore_relpath(), simple_ptr_list_destroy(), tar_file::tblspc_oid, and verify_tar_file().
Referenced by main().
|
static |
Definition at line 992 of file pg_verifybackup.c.
References astreamer_content(), ASTREAMER_UNKNOWN, close, done_size, fd(), PG_BINARY, pg_free(), pg_log_debug, pg_malloc(), progress_report(), read, READ_CHUNK_SIZE, relpath, and report_backup_error().
Referenced by verify_tar_backup().
|
static |
Definition at line 549 of file pg_verifybackup.c.
References manifest_file::bad, manifest_file::checksum_length, manifest_file::checksum_payload, manifest_file::checksum_type, manifest, manifest_file::matched, JsonManifestParseContext::private_data, report_fatal_error(), size, and manifest_file::size.
Referenced by parse_manifest_file().
|
static |
Definition at line 578 of file pg_verifybackup.c.
References manifest, palloc(), JsonManifestParseContext::private_data, and range().
Referenced by parse_manifest_file().
|
static |
Definition at line 536 of file pg_verifybackup.c.
References manifest, and JsonManifestParseContext::private_data.
Referenced by parse_manifest_file().
|
static |
Definition at line 523 of file pg_verifybackup.c.
References manifest, and JsonManifestParseContext::private_data.
Referenced by parse_manifest_file().
|
static |
Definition at line 111 of file pg_verifybackup.c.
Referenced by progress_report(), verify_file_checksum(), and verify_tar_file().
|
static |
Definition at line 104 of file pg_verifybackup.c.
|
static |
Definition at line 107 of file pg_verifybackup.c.
Referenced by main(), precheck_tar_backup_file(), progress_report(), and verify_plain_backup_file().
|
static |
Definition at line 110 of file pg_verifybackup.c.
Referenced by precheck_tar_backup_file(), progress_report(), and verify_plain_backup_file().