Debian Codegraph @

src/bin/pg_verifybackup/pg_verifybackup.h

raw
1 /*-------------------------------------------------------------------------
2 *
3 * pg_verifybackup.h
4 * Verify a backup against a backup manifest.
5 *
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 * src/bin/pg_verifybackup/pg_verifybackup.h
10 *
11 *-------------------------------------------------------------------------
12 */
13
14 #ifndef PG_VERIFYBACKUP_H
15 #define PG_VERIFYBACKUP_H
16
17 #include "common/controldata_utils.h"
18 #include "common/hashfn_unstable.h"
19 #include "common/logging.h"
20 #include "common/parse_manifest.h"
21 #include "fe_utils/astreamer.h"
22 #include "fe_utils/simple_list.h"
23
24 /*
25 * Each file described by the manifest file is parsed to produce an object
26 * like this.
27 */
28 typedef struct manifest_file
29 {
30 uint32 status; /* hash status */
31 const char *pathname;
32 uint64 size;
33 pg_checksum_type checksum_type;
34 int checksum_length;
35 uint8 *checksum_payload;
36 bool matched;
37 bool bad;
38 } manifest_file;
39
40 #define should_verify_checksum(m) \
41 (((m)->matched) && !((m)->bad) && (((m)->checksum_type) != CHECKSUM_TYPE_NONE))
42
43 /*
44 * Define a hash table which we can use to store information about the files
45 * mentioned in the backup manifest.
46 */
47 #define SH_PREFIX manifest_files
48 #define SH_ELEMENT_TYPE manifest_file
49 #define SH_KEY_TYPE const char *
50 #define SH_KEY pathname
51 #define SH_HASH_KEY(tb, key) hash_string(key)
52 #define SH_EQUAL(tb, a, b) (strcmp(a, b) == 0)
53 #define SH_SCOPE static inline
54 #define SH_RAW_ALLOCATOR pg_malloc0
55 #define SH_DECLARE
56 #define SH_DEFINE
57 #include "lib/simplehash.h"
58
59 /*
60 * Each WAL range described by the manifest file is parsed to produce an
61 * object like this.
62 */
63 typedef struct manifest_wal_range
64 {
65 TimeLineID tli;
66 XLogRecPtr start_lsn;
67 XLogRecPtr end_lsn;
68 struct manifest_wal_range *next;
69 struct manifest_wal_range *prev;
70 } manifest_wal_range;
71
72 /*
73 * All the data parsed from a backup_manifest file.
74 */
75 typedef struct manifest_data
76 {
77 int version;
78 uint64 system_identifier;
79 manifest_files_hash *files;
80 manifest_wal_range *first_wal_range;
81 manifest_wal_range *last_wal_range;
82 } manifest_data;
83
84 /*
85 * All of the context information we need while checking a backup manifest.
86 */
87 typedef struct verifier_context
88 {
89 manifest_data *manifest;
90 char *backup_directory;
91 SimpleStringList ignore_list;
92 char format; /* backup format: p(lain)/t(ar) */
93 bool skip_checksums;
94 bool exit_on_error;
95 bool saw_any_error;
96 } verifier_context;
97
98 extern void report_backup_error(verifier_context *context,
99 const char *pg_restrict fmt,...)
100 pg_attribute_printf(2, 3);
101 pg_noreturn extern void report_fatal_error(const char *pg_restrict fmt,...)
102 pg_attribute_printf(1, 2);
103 extern bool should_ignore_relpath(verifier_context *context,
104 const char *relpath);
105
106 extern astreamer *astreamer_verify_content_new(astreamer *next,
107 verifier_context *context,
108 char *archive_name,
109 Oid tblspc_oid);
110
111 #endif /* PG_VERIFYBACKUP_H */