PostgreSQL Source Code: src/bin/pg_verifybackup/pg_verifybackup.c File Reference (original) (raw)
119{
120 static struct option long_options[] = {
121 {"exit-on-error", no_argument, NULL, 'e'},
125 {"no-parse-wal", no_argument, NULL, 'n'},
128 {"skip-checksums", no_argument, NULL, 's'},
130 {NULL, 0, NULL, 0}
131 };
132
133 int c;
135 char *manifest_path = NULL;
136 bool no_parse_wal = false;
137 bool quiet = false;
138 char *wal_directory = NULL;
139 char *pg_waldump_path = NULL;
140 DIR *dir;
141
145
146 memset(&context, 0, sizeof(context));
147
148 if (argc > 1)
149 {
150 if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
151 {
153 exit(0);
154 }
155 if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
156 {
157 puts("pg_verifybackup (PostgreSQL) " PG_VERSION);
158 exit(0);
159 }
160 }
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
182
183 while ((c = getopt_long(argc, argv, "eF:i:m:nPqsw:", long_options, NULL)) != -1)
184 {
185 switch (c)
186 {
187 case 'e':
189 break;
190 case 'i':
191 {
193
196 break;
197 }
198 case 'm':
201 break;
202 case 'F':
203 if (strcmp(optarg, "p") == 0 || strcmp(optarg, "plain") == 0)
204 context.format = 'p';
205 else if (strcmp(optarg, "t") == 0 || strcmp(optarg, "tar") == 0)
206 context.format = 't';
207 else
208 pg_fatal("invalid backup format \"%s\", must be \"plain\" or \"tar\"",
210 break;
211 case 'n':
212 no_parse_wal = true;
213 break;
214 case 'P':
216 break;
217 case 'q':
218 quiet = true;
219 break;
220 case 's':
222 break;
223 case 'w':
226 break;
227 default:
228
230 exit(1);
231 }
232 }
233
234
236 {
237 pg_log_error("no backup directory specified");
239 exit(1);
240 }
243
244
246 {
247 pg_log_error("too many command-line arguments (first is \"%s\")",
250 exit(1);
251 }
252
253
255 pg_fatal("cannot specify both %s and %s",
256 "-P/--progress", "-q/--quiet");
257
258
259 if (!no_parse_wal)
260 {
261 int ret;
262
265 "pg_waldump (PostgreSQL) " PG_VERSION "\n",
266 pg_waldump_path);
267 if (ret < 0)
268 {
270
273
274 if (ret == -1)
275 pg_fatal("program \"%s\" is needed by %s but was not found in the same directory as \"%s\"",
276 "pg_waldump", "pg_verifybackup", full_path);
277 else
278 pg_fatal("program \"%s\" was found by \"%s\" but was not the same version as %s",
279 "pg_waldump", full_path, "pg_verifybackup");
280 }
281 }
282
283
284 if (manifest_path == NULL)
285 manifest_path = psprintf("%s/backup_manifest",
287
288
289 if (wal_directory == NULL)
291
292
293
294
295
296
298
299
300
301
303 if (dir == NULL)
306
307
308
309
310
311
312
313 if (context.format == '\0')
314 {
315 struct stat sb;
316 char *path;
317
319 if (stat(path, &sb) == 0)
320 context.format = 'p';
321 else if (errno != ENOENT)
322 {
323 pg_log_error("could not stat file \"%s\": %m", path);
324 exit(1);
325 }
326 else
327 {
328
329 context.format = 't';
330 }
332 }
333
334
335
336
337
338 if (!no_parse_wal && context.format == 't')
339 {
340 pg_log_error("pg_waldump cannot read tar files");
341 pg_log_error_hint("You must use -n/--no-parse-wal when verifying a tar-format backup.");
342 exit(1);
343 }
344
345
346
347
348
349 if (context.format == 'p')
351 dir);
352 else
354
355
356
357
358
359
361
362
363
364
365
366
367
370
371
372
373
374
375 if (!no_parse_wal)
377
378
379
380
381
383 printf(_("backup successfully verified\n"));
384
386}
#define PG_TEXTDOMAIN(domain)
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)
DIR * opendir(const char *)
void * pg_malloc(size_t size)
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)
#define pg_log_error(...)
#define pg_log_error_hint(...)
char * pstrdup(const char *in)
void pfree(void *pointer)
PGDLLIMPORT char * optarg
static void verify_backup_checksums(verifier_context *context)
static manifest_data * parse_manifest_file(char *manifest_path)
void report_fatal_error(const char *pg_restrict fmt,...)
static void verify_plain_backup_directory(verifier_context *context, char *relpath, char *fullpath, DIR *dir)
static void report_extra_backup_files(verifier_context *context)
static bool show_progress
static void parse_required_wal(verifier_context *context, char *pg_waldump_path, char *wal_directory)
static const char * progname
static pg_noreturn void static void verify_tar_backup(verifier_context *context, DIR *dir)
void canonicalize_path(char *path)
const char * get_progname(const char *argv0)
size_t strlcpy(char *dst, const char *src, size_t siz)
char * psprintf(const char *fmt,...)
void simple_string_list_append(SimpleStringList *list, const char *val)
SimpleStringList ignore_list