pg_verifybackup: TAR format backup verification
Amul Sul <sulamul@gmail.com>
From: Amul Sul <sulamul@gmail.com>
To: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2024-07-09T09:53:39Z
Lists: pgsql-hackers
Attachments
- v1-0006-Refactor-split-verify_file_checksum-function.patch (application/x-patch) patch v1-0006
- v1-0008-pg_verifybackup-Add-backup-format-and-compression.patch (application/x-patch) patch v1-0008
- v1-0010-pg_verifybackup-Tests-and-document.patch (application/x-patch) patch v1-0010
- v1-0007-Refactor-split-verify_control_file.patch (application/x-patch) patch v1-0007
- v1-0009-pg_verifybackup-Read-tar-files-and-verify-its-con.patch (application/x-patch) patch v1-0009
- v1-0005-Refactor-split-verify_backup_file-function.patch (application/x-patch) patch v1-0005
- v1-0004-Refactor-move-some-part-of-pg_verifybackup.c-to-p.patch (application/x-patch) patch v1-0004
- v1-0002-Refactor-Add-astreamer_inject.h-and-move-related-.patch (application/x-patch) patch v1-0002
- v1-0001-Refactor-Rename-all-bbstreamer-references-to-astr.patch (application/x-patch) patch v1-0001
- v1-0003-Refactor-move-astreamer-files-to-fe_utils-to-make.patch (application/x-patch) patch v1-0003
Hi, Currently, pg_verifybackup only works with plain (directory) format backups. This proposal aims to support tar-format backups too. We will read the tar files from start to finish and verify each file inside against the backup_manifest information, similar to how it verifies plain files. We are introducing new options to pg_verifybackup: -F, --format=p|t and -Z, --compress=METHOD, which allow users to specify the backup format and compression type, similar to the options available in pg_basebackup. If these options are not provided, the backup format and compression type will be automatically detected. To determine the format, we will search for PG_VERSION file in the backup directory — if found, it indicates a plain backup; otherwise, it is a tar-format backup. For the compression type, we will check the extension of base.tar.xxx file of tar-format backup. Refer to patch 0008 for the details. The main challenge is to structure the code neatly. For plain-format backups, we verify bytes directly from the files. For tar-format backups, we read bytes from the tar file of the specific file we care about. We need an abstraction to handle both formats smoothly, without using many if statements or special cases. To achieve this goal, we need to reuse existing infrastructure without duplicating code, and for that, the major work involved here is the code refactoring. Here is a breakdown of the work: 1. BBSTREAMER Rename and Relocate: BBSTREAMER, currently used in pg_basebackup for reading and decompressing TAR files; can also be used for pg_verifybackup. In the future, it could support other tools like pg_combinebackup for merging TAR backups without extraction, and pg_waldump for verifying WAL files from the tar backup. For that accessibility, BBSTREAMER needs to be relocated to a shared directory. Moreover, renaming BBSTREAMER to ASTREAMER (short for Archive Streamer) would better indicate its general application across multiple tools. Moving it to src/fe_utils directory is appropriate, given its frontend infrastructure use. 2. pg_verifybackup Code Refactoring: The existing code for plain backup verification will be split into separate files or functions, so it can also be reused for tar backup verification. 3. Adding TAR Backup Verification: Finally, patches will be added to implement TAR backup verification, along with tests and documentation. Patches 0001-0003 focus on renaming and relocating BBSTREAMER, patches 0004-0007 on splitting the existing verification code, and patches 0008-0010 on adding TAR backup verification capabilities, tests, and documentation. The last set could be a single patch but is split to make the review easier. Please take a look at the attached patches and share your comments, suggestions, or any ways to enhance them. Your feedback is greatly appreciated. Thank you ! -- Regards, Amul Sul EDB: http://www.enterprisedb.com
Commits
-
Adjust json_manifest_per_file_callback API in one more place.
- 554d3a18f362 18.0 landed
-
File size in a backup manifest should use uint64, not size_t.
- d94cf5ca7fad 18.0 landed
-
Fix some pg_verifybackup issues reported by Coverity.
- fc1b2ce0ee9c 18.0 landed
-
pg_verifybackup: Move some declarations to new pg_verifybackup.h
- aa2d6b15d6d6 18.0 landed
-
pg_verifybackup: Move skip_checksums into verifier_context.
- af99d44a889f 18.0 landed
-
Improve file header comments for astramer code.
- 22b4a1b561f8 18.0 landed
-
Move astreamer (except astreamer_inject) to fe_utils.
- f80b09bac87d 18.0 landed
-
Move recovery injector astreamer to a separate header file.
- 53b2c921a0f9 18.0 landed
-
Rename bbstreamer to astreamer.
- 3c905698114d 18.0 landed