mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-04-15 11:36:40 +02:00
Add backup management functions to InfoBackup.
Allow current backups to be listed and deleted. Also expose some constants required by expire and stanza-* commands. Contributed by Cynthia Shang.
This commit is contained in:
parent
44bafc127d
commit
c64c9c0590
@ -42,6 +42,14 @@
|
||||
|
||||
<p>Rename <code>info*New()</code> functions to <code>info*NewLoad()</code>.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<release-item-contributor-list>
|
||||
<release-item-contributor id="cynthia.shang"/>
|
||||
</release-item-contributor-list>
|
||||
|
||||
<p>Add backup management functions to <code>InfoBackup</code>.</p>
|
||||
</release-item>
|
||||
</release-development-list>
|
||||
</release-core-list>
|
||||
|
||||
|
@ -409,7 +409,7 @@ info/info.o: info/info.c build.auto.h common/assert.h common/crypto/cipherBlock.
|
||||
info/infoArchive.o: info/infoArchive.c build.auto.h common/assert.h common/crypto/common.h common/debug.h common/error.auto.h common/error.h common/ini.h common/io/filter/filter.h common/io/filter/group.h common/io/read.h common/io/write.h common/log.h common/logLevel.h common/macro.h common/memContext.h common/object.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h info/info.h info/infoArchive.h info/infoPg.h postgres/interface.h storage/helper.h storage/info.h storage/read.h storage/storage.h storage/write.h
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) $(CMAKE) -c info/infoArchive.c -o info/infoArchive.o
|
||||
|
||||
info/infoBackup.o: info/infoBackup.c build.auto.h common/assert.h common/crypto/common.h common/debug.h common/error.auto.h common/error.h common/ini.h common/io/filter/filter.h common/io/filter/group.h common/io/read.h common/io/write.h common/log.h common/logLevel.h common/macro.h common/memContext.h common/object.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/json.h common/type/keyValue.h common/type/list.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h info/info.h info/infoBackup.h info/infoManifest.h info/infoPg.h postgres/interface.h storage/helper.h storage/info.h storage/read.h storage/storage.h storage/write.h
|
||||
info/infoBackup.o: info/infoBackup.c build.auto.h common/assert.h common/crypto/common.h common/debug.h common/error.auto.h common/error.h common/ini.h common/io/filter/filter.h common/io/filter/group.h common/io/read.h common/io/write.h common/log.h common/logLevel.h common/macro.h common/memContext.h common/object.h common/regExp.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/json.h common/type/keyValue.h common/type/list.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h info/info.h info/infoBackup.h info/infoManifest.h info/infoPg.h postgres/interface.h storage/helper.h storage/info.h storage/read.h storage/storage.h storage/write.h
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) $(CMAKE) -c info/infoBackup.c -o info/infoBackup.o
|
||||
|
||||
info/infoManifest.o: info/infoManifest.c build.auto.h common/error.auto.h common/error.h common/memContext.h common/type/buffer.h common/type/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h info/infoManifest.h
|
||||
|
@ -23,8 +23,6 @@ Info Handler
|
||||
/***********************************************************************************************************************************
|
||||
Internal constants
|
||||
***********************************************************************************************************************************/
|
||||
#define INFO_COPY_EXT ".copy"
|
||||
|
||||
STRING_STATIC(INFO_SECTION_BACKREST_STR, "backrest");
|
||||
STRING_STATIC(INFO_SECTION_CIPHER_STR, "cipher");
|
||||
|
||||
|
@ -19,6 +19,8 @@ typedef struct Info Info;
|
||||
/***********************************************************************************************************************************
|
||||
Constants
|
||||
***********************************************************************************************************************************/
|
||||
#define INFO_COPY_EXT ".copy"
|
||||
|
||||
#define INFO_KEY_FORMAT "backrest-format"
|
||||
STRING_DECLARE(INFO_KEY_VERSION_STR);
|
||||
#define INFO_KEY_VERSION "backrest-version"
|
||||
|
@ -21,6 +21,7 @@ typedef struct InfoArchive InfoArchive;
|
||||
Archive info filename
|
||||
***********************************************************************************************************************************/
|
||||
#define INFO_ARCHIVE_FILE "archive.info"
|
||||
#define REGEX_ARCHIVE_DIR_DB_VERSION "^[0-9]+(\\.[0-9]+)*-[0-9]+$"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Constructor
|
||||
|
@ -12,7 +12,9 @@ Backup Info Handler
|
||||
#include "common/ini.h"
|
||||
#include "common/log.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/ini.h"
|
||||
#include "common/object.h"
|
||||
#include "common/regExp.h"
|
||||
#include "common/type/json.h"
|
||||
#include "common/type/list.h"
|
||||
#include "info/info.h"
|
||||
@ -310,6 +312,67 @@ infoBackupData(const InfoBackup *this, unsigned int backupDataIdx)
|
||||
FUNCTION_LOG_RETURN(INFO_BACKUP_DATA, *((InfoBackupData *)lstGet(this->backup, backupDataIdx)));
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Delete a backup from the current backup list
|
||||
***********************************************************************************************************************************/
|
||||
void
|
||||
infoBackupDataDelete(const InfoBackup *this, const String *backupDeleteLabel)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelTrace);
|
||||
FUNCTION_LOG_PARAM(INFO_BACKUP, this);
|
||||
FUNCTION_LOG_PARAM(STRING, backupDeleteLabel);
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
ASSERT(this != NULL);
|
||||
|
||||
for (unsigned int idx = 0; idx < infoBackupDataTotal(this); idx++)
|
||||
{
|
||||
InfoBackupData backupData = infoBackupData(this, idx);
|
||||
|
||||
if (strCmp(backupData.backupLabel, backupDeleteLabel) == 0)
|
||||
lstRemove(this->backup, idx);
|
||||
}
|
||||
|
||||
FUNCTION_LOG_RETURN_VOID();
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Return a list of current backup labels, applying a regex expression if provided
|
||||
***********************************************************************************************************************************/
|
||||
StringList *
|
||||
infoBackupDataLabelList(const InfoBackup *this, const String *expression)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelTrace);
|
||||
FUNCTION_LOG_PARAM(INFO_BACKUP, this);
|
||||
FUNCTION_LOG_PARAM(STRING, expression);
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
ASSERT(this != NULL);
|
||||
|
||||
// Return a 0 sized list if no current backups or none matching the filter
|
||||
StringList *result = strLstNew();
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
// Prepare regexp if an expression was passed
|
||||
RegExp *regExp = (expression == NULL) ? NULL : regExpNew(expression);
|
||||
|
||||
// For each backup label, compare it to the filter (if any) and sort it for return
|
||||
for (unsigned int backupLabelIdx = 0; backupLabelIdx < infoBackupDataTotal(this); backupLabelIdx++)
|
||||
{
|
||||
InfoBackupData backupData = infoBackupData(this, backupLabelIdx);
|
||||
|
||||
if (regExp == NULL || regExpMatch(regExp, backupData.backupLabel))
|
||||
{
|
||||
strLstAdd(result, backupData.backupLabel);
|
||||
}
|
||||
}
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
FUNCTION_LOG_RETURN(STRING_LIST, result);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Render as string for logging
|
||||
***********************************************************************************************************************************/
|
||||
|
@ -13,6 +13,7 @@ Object type
|
||||
typedef struct InfoBackup InfoBackup;
|
||||
|
||||
#include "common/type/string.h"
|
||||
#include "common/type/stringList.h"
|
||||
#include "info/infoPg.h"
|
||||
#include "storage/storage.h"
|
||||
|
||||
@ -61,6 +62,15 @@ Functions
|
||||
***********************************************************************************************************************************/
|
||||
unsigned int infoBackupCheckPg(
|
||||
const InfoBackup *this, unsigned int pgVersion, uint64_t pgSystemId, uint32_t pgCatalogVersion, uint32_t pgControlVersion);
|
||||
// Remove a backup from the current section
|
||||
void infoBackupDataDelete(const InfoBackup *this, const String *backupDeleteLabel);
|
||||
void infoBackupSave(
|
||||
InfoBackup *this, const Storage *storage, const String *fileName, CipherType cipherType, const String *cipherPass);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
infoBackupDataLabelList - get a list of current backup labels
|
||||
***********************************************************************************************************************************/
|
||||
StringList *infoBackupDataLabelList(const InfoBackup *this, const String *expression);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Getters
|
||||
|
@ -9,6 +9,8 @@ Manifest Info Handler
|
||||
/***********************************************************************************************************************************
|
||||
Constants
|
||||
***********************************************************************************************************************************/
|
||||
#define INFO_MANIFEST_FILE "backup.manifest"
|
||||
|
||||
#define INFO_MANIFEST_KEY_BACKUP_ARCHIVE_START "backup-archive-start"
|
||||
VARIANT_DECLARE(INFO_MANIFEST_KEY_BACKUP_ARCHIVE_START_VAR);
|
||||
#define INFO_MANIFEST_KEY_BACKUP_ARCHIVE_STOP "backup-archive-stop"
|
||||
|
@ -4,6 +4,7 @@ Test Backup Info Handler
|
||||
#include "storage/storage.intern.h"
|
||||
|
||||
#include "common/harnessInfo.h"
|
||||
#include "command/backup/common.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Test Run
|
||||
@ -91,7 +92,8 @@ testRun(void)
|
||||
TEST_RESULT_VOID(infoBackupFree(infoBackup), "infoBackupFree() - free backup info");
|
||||
}
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("infoBackupData(), infoBackupDataTotal(), infoBackupDataToLog()"))
|
||||
if (testBegin(
|
||||
"infoBackupData(), infoBackupDataTotal(), infoBackupDataToLog(), infoBackupDataLabelList(), infoBackupDataDelete()"))
|
||||
{
|
||||
// File exists, backup:current section exists
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
@ -195,6 +197,34 @@ testRun(void)
|
||||
TEST_RESULT_BOOL(backupData.optionHardlink, false, " option hardlink");
|
||||
TEST_RESULT_BOOL(backupData.optionOnline, true, " option online");
|
||||
|
||||
// infoBackupDataLabelList and infoBackupDataDelete
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_RESULT_STR(
|
||||
strPtr(strLstJoin(strLstSort(infoBackupDataLabelList(infoBackup, NULL), sortOrderAsc), ", ")),
|
||||
"20161219-212741F, 20161219-212741F_20161219-212803D, 20161219-212741F_20161219-212918I", "infoBackupDataLabelList without expression");
|
||||
TEST_RESULT_STR(
|
||||
strPtr(strLstJoin(strLstSort(infoBackupDataLabelList(
|
||||
infoBackup, backupRegExpP(.full=true, .differential=true, .incremental=true)), sortOrderAsc), ", ")),
|
||||
"20161219-212741F, 20161219-212741F_20161219-212803D, 20161219-212741F_20161219-212918I", "infoBackupDataLabelList with expression");
|
||||
TEST_RESULT_STR(
|
||||
strPtr(strLstJoin(infoBackupDataLabelList(infoBackup, backupRegExpP(.full=true)), ", ")),
|
||||
"20161219-212741F", " full=true");
|
||||
TEST_RESULT_STR(
|
||||
strPtr(strLstJoin(infoBackupDataLabelList(infoBackup, backupRegExpP(.differential=true)), ", ")),
|
||||
"20161219-212741F_20161219-212803D", "differential=true");
|
||||
TEST_RESULT_STR(
|
||||
strPtr(strLstJoin(infoBackupDataLabelList(infoBackup, backupRegExpP(.incremental=true)), ", ")),
|
||||
"20161219-212741F_20161219-212918I", "incremental=true");
|
||||
|
||||
TEST_RESULT_VOID(infoBackupDataDelete(infoBackup, strNew("20161219-212741F_20161219-212918I")), "delete a backup");
|
||||
TEST_RESULT_STR(
|
||||
strPtr(strLstJoin(strLstSort(infoBackupDataLabelList(infoBackup, NULL), sortOrderAsc), ", ")),
|
||||
"20161219-212741F, 20161219-212741F_20161219-212803D", " backup deleted");
|
||||
|
||||
TEST_RESULT_VOID(infoBackupDataDelete(infoBackup, strNew("20161219-212741F_20161219-212803D")), "delete all backups");
|
||||
TEST_RESULT_VOID(infoBackupDataDelete(infoBackup, strNew("20161219-212741F")), " deleted");
|
||||
TEST_RESULT_UINT(strLstSize(infoBackupDataLabelList(infoBackup, NULL)), 0, " no backups remain");
|
||||
|
||||
// infoBackupDataToLog
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_RESULT_STR(
|
||||
|
Loading…
x
Reference in New Issue
Block a user