1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2026-10-23 21:28:56 +03:00

Refactor backup file into an included module.

backupFile() is only called by the backup protocol handler so include file.c into protocol.c directly, matching how the rest of the backup module is included into backup.c. This makes backupFile() static and removes the file.h header and build entry. The BackupFile/BackupFileResult structs are only used by backupFile() and the protocol handler so they become file-private as well.

The BackupCopyResult enum is still needed by the backup process to interpret protocol job results so move it to protocol.h.
This commit is contained in:
David Steele
2026-07-24 21:03:01 +07:00
parent dde4fe3cd2
commit 6f47bd90ad
7 changed files with 64 additions and 100 deletions

View File

@@ -11,7 +11,6 @@ Backup Command
#include "command/archive/find.h"
#include "command/backup/backup.h"
#include "command/backup/common.h"
#include "command/backup/file.h"
#include "command/backup/protocol.h"
#include "command/check/common.h"
#include "command/control/common.h"

View File

@@ -1,26 +1,3 @@
/***********************************************************************************************************************************
Backup File
***********************************************************************************************************************************/
#include <build.h>
#include <string.h>
#include "command/backup/blockIncr.h"
#include "command/backup/file.h"
#include "command/backup/pageChecksum.h"
#include "common/crypto/cipherBlock.h"
#include "common/crypto/hash.h"
#include "common/debug.h"
#include "common/io/bufferRead.h"
#include "common/io/filter/group.h"
#include "common/io/filter/size.h"
#include "common/io/io.h"
#include "common/log.h"
#include "common/regExp.h"
#include "common/type/convert.h"
#include "common/type/json.h"
#include "storage/helper.h"
/***********************************************************************************************************************************
Helper functions
***********************************************************************************************************************************/
@@ -35,8 +12,48 @@ segmentNumber(const String *const pgFile)
FUNCTION_TEST_RETURN(UINT, regExpMatchOne(STRDEF("\\.[0-9]+$"), pgFile) ? cvtZToUInt(strrchr(strZ(pgFile), '.') + 1) : 0);
}
/**********************************************************************************************************************************/
FN_EXTERN List *
/***********************************************************************************************************************************
Copy a file from the PostgreSQL data directory to the repository
***********************************************************************************************************************************/
typedef struct BackupFile
{
const String *pgFile; // Pg file to backup
bool pgFileDelta; // Checksum pg file before copying
bool pgFileIgnoreMissing; // Ignore missing pg file
uint64_t pgFileSize; // Expected pg file size
uint64_t pgFileSizeOriginal; // Original size (from manifest build)
bool pgFileCopyExactSize; // Copy only pg expected size
const Buffer *pgFileChecksum; // Expected pg file checksum
bool pgFileChecksumPage; // Validate page checksums?
bool pgFilePageHeaderCheck; // Validate page headers?
size_t blockIncrSize; // Perform block incremental on this file?
size_t blockIncrChecksumSize; // Block checksum size
uint64_t blockIncrSuperSize; // Size of the super block
const String *blockIncrMapPriorFile; // File containing prior block incremental map (NULL if none)
uint64_t blockIncrMapPriorOffset; // Offset of prior block incremental map
uint64_t blockIncrMapPriorSize; // Size of prior block incremental map
const String *manifestFile; // Repo file
const Buffer *repoFileChecksum; // Expected repo file checksum
uint64_t repoFileSize; // Expected repo file size
bool manifestFileResume; // Checksum repo file before copying
bool manifestFileHasReference; // Reference to prior backup, if any
} BackupFile;
typedef struct BackupFileResult
{
const String *manifestFile; // Manifest file
BackupCopyResult backupCopyResult;
bool repoInvalid; // File was recopied because repo file was invalid
uint64_t copySize;
const Buffer *copyChecksum; // Checksum of pg file
const Buffer *repoChecksum; // Checksum of repo file (including compression, etc.)
uint64_t bundleOffset; // Offset in bundle if any
uint64_t repoSize;
uint64_t blockIncrMapSize; // Size of block incremental map (0 if no map)
Pack *pageChecksumResult;
} BackupFileResult;
static List *
backupFile(
const String *const repoFile, const uint64_t bundleId, const bool bundleRaw, const unsigned int blockIncrReference,
const CompressType repoFileCompressType, const int repoFileCompressLevel, const CipherType cipherType,

View File

@@ -1,71 +0,0 @@
/***********************************************************************************************************************************
Backup File
***********************************************************************************************************************************/
#ifndef COMMAND_BACKUP_FILE_H
#define COMMAND_BACKUP_FILE_H
#include "common/compress/helper.h"
#include "common/crypto/common.h"
#include "common/type/keyValue.h"
#include "postgres/interface.h"
/***********************************************************************************************************************************
Backup file types
***********************************************************************************************************************************/
typedef enum
{
backupCopyResultChecksum,
backupCopyResultCopy,
backupCopyResultSkip,
backupCopyResultNoOp,
backupCopyResultTruncate,
} BackupCopyResult;
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/
// Copy a file from the PostgreSQL data directory to the repository
typedef struct BackupFile
{
const String *pgFile; // Pg file to backup
bool pgFileDelta; // Checksum pg file before copying
bool pgFileIgnoreMissing; // Ignore missing pg file
uint64_t pgFileSize; // Expected pg file size
uint64_t pgFileSizeOriginal; // Original size (from manifest build)
bool pgFileCopyExactSize; // Copy only pg expected size
const Buffer *pgFileChecksum; // Expected pg file checksum
bool pgFileChecksumPage; // Validate page checksums?
bool pgFilePageHeaderCheck; // Validate page headers?
size_t blockIncrSize; // Perform block incremental on this file?
size_t blockIncrChecksumSize; // Block checksum size
uint64_t blockIncrSuperSize; // Size of the super block
const String *blockIncrMapPriorFile; // File containing prior block incremental map (NULL if none)
uint64_t blockIncrMapPriorOffset; // Offset of prior block incremental map
uint64_t blockIncrMapPriorSize; // Size of prior block incremental map
const String *manifestFile; // Repo file
const Buffer *repoFileChecksum; // Expected repo file checksum
uint64_t repoFileSize; // Expected repo file size
bool manifestFileResume; // Checksum repo file before copying
bool manifestFileHasReference; // Reference to prior backup, if any
} BackupFile;
typedef struct BackupFileResult
{
const String *manifestFile; // Manifest file
BackupCopyResult backupCopyResult;
bool repoInvalid; // File was recopied because repo file was invalid
uint64_t copySize;
const Buffer *copyChecksum; // Checksum of pg file
const Buffer *repoChecksum; // Checksum of repo file (including compression, etc.)
uint64_t bundleOffset; // Offset in bundle if any
uint64_t repoSize;
uint64_t blockIncrMapSize; // Size of block incremental map (0 if no map)
Pack *pageChecksumResult;
} BackupFileResult;
FN_EXTERN List *backupFile(
const String *repoFile, uint64_t bundleId, bool bundleRaw, unsigned int blockIncrReference, CompressType repoFileCompressType,
int repoFileCompressLevel, CipherType cipherType, const String *cipherPass, const String *pgVersionForce, PgPageSize pageSize,
const List *fileList);
#endif

View File

@@ -3,17 +3,25 @@ Backup Protocol Handler
***********************************************************************************************************************************/
#include <build.h>
#include "command/backup/file.h"
#include "command/backup/blockIncr.h"
#include "command/backup/pageChecksum.h"
#include "command/backup/protocol.h"
#include "common/compress/helper.h"
#include "common/crypto/cipherBlock.h"
#include "common/crypto/hash.h"
#include "common/debug.h"
#include "common/io/bufferRead.h"
#include "common/io/filter/size.h"
#include "common/io/io.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/regExp.h"
#include "common/type/json.h"
#include "config/config.h"
#include "storage/helper.h"
#include "command/backup/file.c.inc"
/**********************************************************************************************************************************/
FN_EXTERN ProtocolServerResult *
backupFileProtocol(PackRead *const param)

View File

@@ -7,6 +7,18 @@ Backup Protocol Handler
#include "common/type/pack.h"
#include "protocol/server.h"
/***********************************************************************************************************************************
Backup file types
***********************************************************************************************************************************/
typedef enum
{
backupCopyResultChecksum,
backupCopyResultCopy,
backupCopyResultSkip,
backupCopyResultNoOp,
backupCopyResultTruncate,
} BackupCopyResult;
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/

View File

@@ -138,7 +138,6 @@ src_pgbackrest = [
'command/backup/common.c',
'command/backup/pageChecksum.c',
'command/backup/protocol.c',
'command/backup/file.c',
'command/check/check.c',
'command/check/common.c',
'command/check/report.c',

View File

@@ -950,7 +950,7 @@ unit:
- command/backup/common
- command/backup/complete.inc: included
- command/backup/db.inc: included
- command/backup/file
- command/backup/file.inc: included
- command/backup/incr.inc: included
- command/backup/label.inc: included
- command/backup/option.inc: included