@@ -74,7 +74,9 @@ pg_noreturn static void report_manifest_error(JsonManifestParseContext *context,
7474 const char * fmt ,...)
7575 pg_attribute_printf (2 , 3 );
7676
77- static void verify_tar_backup (verifier_context * context , DIR * dir );
77+ static void verify_tar_backup (verifier_context * context , DIR * dir ,
78+ char * * base_archive_path ,
79+ char * * wal_archive_path );
7880static void verify_plain_backup_directory (verifier_context * context ,
7981 char * relpath , char * fullpath ,
8082 DIR * dir );
@@ -83,7 +85,9 @@ static void verify_plain_backup_file(verifier_context *context, char *relpath,
8385static void verify_control_file (const char * controlpath ,
8486 uint64 manifest_system_identifier );
8587static void precheck_tar_backup_file (verifier_context * context , char * relpath ,
86- char * fullpath , SimplePtrList * tarfiles );
88+ char * fullpath , SimplePtrList * tarfiles ,
89+ char * * base_archive_path ,
90+ char * * wal_archive_path );
8791static void verify_tar_file (verifier_context * context , char * relpath ,
8892 char * fullpath , astreamer * streamer );
8993static void report_extra_backup_files (verifier_context * context );
@@ -136,6 +140,8 @@ main(int argc, char **argv)
136140 bool no_parse_wal = false;
137141 bool quiet = false;
138142 char * wal_path = NULL ;
143+ char * base_archive_path = NULL ;
144+ char * wal_archive_path = NULL ;
139145 char * pg_waldump_path = NULL ;
140146 DIR * dir ;
141147
@@ -327,17 +333,6 @@ main(int argc, char **argv)
327333 pfree (path );
328334 }
329335
330- /*
331- * XXX: In the future, we should consider enhancing pg_waldump to read WAL
332- * files from an archive.
333- */
334- if (!no_parse_wal && context .format == 't' )
335- {
336- pg_log_error ("pg_waldump cannot read tar files" );
337- pg_log_error_hint ("You must use -n/--no-parse-wal when verifying a tar-format backup." );
338- exit (1 );
339- }
340-
341336 /*
342337 * Perform the appropriate type of verification appropriate based on the
343338 * backup format. This will close 'dir'.
@@ -346,7 +341,7 @@ main(int argc, char **argv)
346341 verify_plain_backup_directory (& context , NULL , context .backup_directory ,
347342 dir );
348343 else
349- verify_tar_backup (& context , dir );
344+ verify_tar_backup (& context , dir , & base_archive_path , & wal_archive_path );
350345
351346 /*
352347 * The "matched" flag should now be set on every entry in the hash table.
@@ -364,9 +359,28 @@ main(int argc, char **argv)
364359 if (context .format == 'p' && !context .skip_checksums )
365360 verify_backup_checksums (& context );
366361
367- /* By default, look for the WAL in the backup directory, too. */
362+ /*
363+ * By default, WAL files are expected to be found in the backup directory
364+ * for plain-format backups. In the case of tar-format backups, if a
365+ * separate WAL archive is not found, the WAL files are most likely
366+ * included within the main data directory archive.
367+ */
368368 if (wal_path == NULL )
369- wal_path = psprintf ("%s/pg_wal" , context .backup_directory );
369+ {
370+ if (context .format == 'p' )
371+ wal_path = psprintf ("%s/pg_wal" , context .backup_directory );
372+ else if (wal_archive_path )
373+ wal_path = wal_archive_path ;
374+ else if (base_archive_path )
375+ wal_path = base_archive_path ;
376+ else
377+ {
378+ pg_log_error ("wal archive not found" );
379+ pg_log_error_hint ("Specify the correct path using the option -w/--wal-path."
380+ "Or you must use -n/--no-parse-wal when verifying a tar-format backup." );
381+ exit (1 );
382+ }
383+ }
370384
371385 /*
372386 * Try to parse the required ranges of WAL records, unless we were told
@@ -787,7 +801,8 @@ verify_control_file(const char *controlpath, uint64 manifest_system_identifier)
787801 * close when we're done with it.
788802 */
789803static void
790- verify_tar_backup (verifier_context * context , DIR * dir )
804+ verify_tar_backup (verifier_context * context , DIR * dir , char * * base_archive_path ,
805+ char * * wal_archive_path )
791806{
792807 struct dirent * dirent ;
793808 SimplePtrList tarfiles = {NULL , NULL };
@@ -816,7 +831,8 @@ verify_tar_backup(verifier_context *context, DIR *dir)
816831 char * fullpath ;
817832
818833 fullpath = psprintf ("%s/%s" , context -> backup_directory , filename );
819- precheck_tar_backup_file (context , filename , fullpath , & tarfiles );
834+ precheck_tar_backup_file (context , filename , fullpath , & tarfiles ,
835+ base_archive_path , wal_archive_path );
820836 pfree (fullpath );
821837 }
822838 }
@@ -875,11 +891,13 @@ verify_tar_backup(verifier_context *context, DIR *dir)
875891 *
876892 * The arguments to this function are mostly the same as the
877893 * verify_plain_backup_file. The additional argument outputs a list of valid
878- * tar files.
894+ * tar files, along with the full paths to the main archive and the WAL
895+ * directory archive.
879896 */
880897static void
881898precheck_tar_backup_file (verifier_context * context , char * relpath ,
882- char * fullpath , SimplePtrList * tarfiles )
899+ char * fullpath , SimplePtrList * tarfiles ,
900+ char * * base_archive_path , char * * wal_archive_path )
883901{
884902 struct stat sb ;
885903 Oid tblspc_oid = InvalidOid ;
@@ -918,9 +936,17 @@ precheck_tar_backup_file(verifier_context *context, char *relpath,
918936 * extension such as .gz, .lz4, or .zst.
919937 */
920938 if (strncmp ("base" , relpath , 4 ) == 0 )
939+ {
921940 suffix = relpath + 4 ;
941+
942+ * base_archive_path = pstrdup (fullpath );
943+ }
922944 else if (strncmp ("pg_wal" , relpath , 6 ) == 0 )
945+ {
923946 suffix = relpath + 6 ;
947+
948+ * wal_archive_path = pstrdup (fullpath );
949+ }
924950 else
925951 {
926952 /* Expected a <tablespaceoid>.tar file here. */
0 commit comments