pgbackrest.git / summary / log / commit / refs
commit db75ffd27037d690a11eb02902f929250fe2bf5b
Author: Stefan Fercot <stefan.fercot@enterprisedb.com>
Commit: GitHub <noreply@github.com>
Date: Thu Aug 25 14:12:22 2022 +0000
Support --set in JSON output for info command.
Allow detailed information (e.g. error list, tablespace list) in JSON output that is already available in text output with the --set option.
doc/xml/release.xml | 13 +
src/command/info/info.c | 24 +-
test/src/module/command/infoTest.c | 488 ++++++++++++++++++++++++++++++++++++-
3 files changed, 505 insertions(+), 20 deletions(-)
diff --git a/doc/xml/release.xml b/doc/xml/release.xml
index f62946792..c7e03348f 100644
--- a/doc/xml/release.xml
+++ b/doc/xml/release.xml
@@ -32,6 +32,19 @@
</release-feature-list>
<release-improvement-list>
+ <release-item>
+ <github-issue id="1484"/>
+ <github-pull-request id="1501"/>
+
+ <release-item-contributor-list>
+ <release-item-ideator id="anton.kurochkin"/>
+ <release-item-contributor id="stefan.fercot"/>
+ <release-item-reviewer id="david.steele"/>
+ </release-item-contributor-list>
+
+ <p>Support <br-option>--set</br-option> in JSON output for <cmd>info</cmd> command.</p>
+ </release-item>
+
<release-item>
<github-issue id="1816"/>
<github-pull-request id="1819"/>
diff --git a/src/command/info/info.c b/src/command/info/info.c
index d6492a724..8599b6a77 100644
--- a/src/command/info/info.c
+++ b/src/command/info/info.c
@@ -405,7 +405,6 @@ backupListAdd(
// Flags used to decide what data to add
const bool outputJson = cfgOptionStrId(cfgOptOutput) == CFGOPTVAL_OUTPUT_JSON;
- const bool backupLabelMatch = backupLabel != NULL && strEq(backupData->backupLabel, backupLabel);
// main keys
kvPut(varKv(backupInfo), BACKUP_KEY_LABEL_VAR, VARSTR(backupData->backupLabel));
@@ -463,7 +462,7 @@ backupListAdd(
kvPut(varKv(backupInfo), BACKUP_KEY_ERROR_VAR, backupData->backupError);
// Add start/stop backup lsn info to json output or --set text
- if ((outputJson || backupLabelMatch) && backupData->backupLsnStart != NULL && backupData->backupLsnStop != NULL)
+ if ((outputJson || backupLabel != NULL) && backupData->backupLsnStart != NULL && backupData->backupLsnStop != NULL)
{
KeyValue *const lsnInfo = kvPutKv(varKv(backupInfo), BACKUP_KEY_LSN_VAR);
kvPut(lsnInfo, KEY_START_VAR, VARSTR(backupData->backupLsnStart));
@@ -471,11 +470,11 @@ backupListAdd(
}
// Add annotations to json output or --set text
- if ((outputJson || backupLabelMatch) && backupData->backupAnnotation != NULL)
+ if ((outputJson || backupLabel != NULL) && backupData->backupAnnotation != NULL)
kvPut(varKv(backupInfo), BACKUP_KEY_ANNOTATION_VAR, backupData->backupAnnotation);
// If a backup label was specified and this is that label, then get the data from the loaded manifest
- if (backupLabelMatch)
+ if (backupLabel != NULL)
{
// Get the list of databases in this backup
VariantList *databaseSection = varLstNew();
@@ -632,12 +631,15 @@ backupList(
InfoRepoData *repoData = &stanzaData->repoList[backupNextRepoIdx];
InfoBackupData backupData = infoBackupData(repoData->backupInfo, repoData->backupIdx);
repoData->backupIdx++;
+ backupTotalProcessed++;
+
+ // Don't add the backup data to the backup section if a backup label was specified but this is not it
+ if (backupLabel != NULL && !strEq(backupData.backupLabel, backupLabel))
+ continue;
// Add the backup data to the backup section
if (!cfgOptionTest(cfgOptType) || cfgOptionStrId(cfgOptType) == backupData.backupType)
backupListAdd(backupSection, &backupData, backupLabel, repoData);
-
- backupTotalProcessed++;
}
FUNCTION_TEST_RETURN_VOID();
@@ -1079,11 +1081,6 @@ formatTextDb(
for (unsigned int backupIdx = 0; backupIdx < varLstSize(backupSection); backupIdx++)
{
KeyValue *backupInfo = varKv(varLstGet(backupSection, backupIdx));
-
- // If a backup label was specified but this is not it then continue
- if (backupLabel != NULL && !strEq(varStr(kvGet(backupInfo, BACKUP_KEY_LABEL_VAR)), backupLabel))
- continue;
-
KeyValue *backupDbInfo = varKv(kvGet(backupInfo, KEY_DATABASE_VAR));
unsigned int backupDbId = varUInt(kvGet(backupDbInfo, DB_KEY_ID_VAR));
unsigned int backupRepoKey = varUInt(kvGet(backupDbInfo, KEY_REPO_KEY_VAR));
@@ -1279,11 +1276,6 @@ infoRender(void)
const String *backupLabel = cfgOptionStrNull(cfgOptSet);
bool backupFound = false;
- // Since the --set option depends on the --stanza option, the parser will error before this if the backup label is
- // specified but a stanza is not
- if (backupLabel != NULL && cfgOptionStrId(cfgOptOutput) != CFGOPTVAL_OUTPUT_TEXT)
- THROW(ConfigError, "option '" CFGOPT_SET "' is currently only valid for " CFGOPTVAL_OUTPUT_TEXT_Z " output");
-
// Initialize the repo index
unsigned int repoIdxMin = 0;
unsigned int repoTotal = cfgOptionGroupIdxTotal(cfgOptGrpRepo);
diff --git a/test/src/module/command/infoTest.c b/test/src/module/command/infoTest.c
index 4192b92d4..eacf05b30 100644
--- a/test/src/module/command/infoTest.c
+++ b/test/src/module/command/infoTest.c
@@ -1580,6 +1580,45 @@ testRun(void)
" repo2: aes-256-cbc\n",
"text, multi-repo, backup not found");
+ hrnCfgArgRawZ(argList2, cfgOptOutput, "json");
+ HRN_CFG_LOAD(cfgCmdInfo, argList2);
+
+ TEST_RESULT_STR_Z(
+ infoRender(),
+ "["
+ "{"
+ "\"archive\":[],"
+ "\"backup\":[],"
+ "\"cipher\":\"mixed\","
+ "\"db\":[],"
+ "\"name\":\"stanza1\","
+ "\"repo\":["
+ "{"
+ "\"cipher\":\"none\","
+ "\"key\":1,"
+ "\"status\":{"
+ "\"code\":6,"
+ "\"message\":\"requested backup not found\""
+ "}"
+ "},"
+ "{"
+ "\"cipher\":\"aes-256-cbc\","
+ "\"key\":2,"
+ "\"status\":{"
+ "\"code\":6,"
+ "\"message\":\"requested backup not found\""
+ "}"
+ "}"
+ "],"
+ "\"status\":{"
+ "\"code\":6,"
+ "\"lock\":{\"backup\":{\"held\":false}},"
+ "\"message\":\"requested backup not found\""
+ "}"
+ "}"
+ "]",
+ "json, multi-repo, backup not found");
+
//--------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("multi-repo: backup set requested on single repo, with 1 checksum error");
@@ -1615,6 +1654,115 @@ testRun(void)
" error list: base/16384/17000\n",
"text - backup set requested");
+ hrnCfgArgRawZ(argList2, cfgOptOutput, "json");
+ HRN_CFG_LOAD(cfgCmdInfo, argList2);
+
+ TEST_RESULT_STR_Z(
+ infoRender(),
+ "["
+ "{"
+ "\"archive\":["
+ "{"
+ "\"database\":{"
+ "\"id\":1,"
+ "\"repo-key\":1"
+ "},"
+ "\"id\":\"9.4-1\","
+ "\"max\":\"000000020000000000000003\","
+ "\"min\":\"000000010000000000000002\""
+ "},"
+ "{"
+ "\"database\":{"
+ "\"id\":2,"
+ "\"repo-key\":1"
+ "},"
+ "\"id\":\"9.5-2\","
+ "\"max\":\"000000010000000000000005\","
+ "\"min\":\"000000010000000000000002\""
+ "}"
+ "],"
+ "\"backup\":["
+ "{"
+ "\"archive\":{"
+ "\"start\":\"000000010000000000000003\","
+ "\"stop\":null"
+ "},"
+ "\"backrest\":{"
+ "\"format\":5,"
+ "\"version\":\"2.08dev\""
+ "},"
+ "\"database\":{"
+ "\"id\":1,"
+ "\"repo-key\":1"
+ "},"
+ "\"database-ref\":["
+ "{\"name\":\"mail\",\"oid\":16456},"
+ "{\"name\":\"postgres\",\"oid\":12173}"
+ "],"
+ "\"error\":true,"
+ "\"error-list\":[\"base/16384/17000\"],"
+ "\"info\":{"
+ "\"delta\":8428,"
+ "\"repository\":{"
+ "\"delta\":346,"
+ "\"size\":2369186"
+ "},"
+ "\"size\":20162900"
+ "},"
+ "\"label\":\"20181119-152138F_20181119-152155I\","
+ "\"link\":["
+ "{\"destination\":\"../pg_config/pg_hba.conf\",\"name\":\"pg_hba.conf\"},"
+ "{\"destination\":\"../pg_stat\",\"name\":\"pg_stat\"}"
+ "],"
+ "\"lsn\":{\"start\":\"285/89000028\",\"stop\":\"285/89001F88\"},"
+ "\"prior\":\"20181119-152138F_20181119-152152D\","
+ "\"reference\":[\"20181119-152138F\",\"20181119-152138F_20181119-152152D\"],"
+ "\"tablespace\":["
+ "{\"destination\":\"/tblspc/ts1\",\"name\":\"ts1\",\"oid\":1},"
+ "{\"destination\":\"/tblspc/ts12\",\"name\":\"ts12\",\"oid\":12}"
+ "],"
+ "\"timestamp\":{"
+ "\"start\":1542640915,"
+ "\"stop\":1542640917"
+ "},"
+ "\"type\":\"incr\""
+ "}"
+ "],"
+ "\"cipher\":\"none\","
+ "\"db\":["
+ "{"
+ "\"id\":1,"
+ "\"repo-key\":1,"
+ "\"system-id\":6625592122879095702,"
+ "\"version\":\"9.4\""
+ "},"
+ "{"
+ "\"id\":2,"
+ "\"repo-key\":1,"
+ "\"system-id\":6626363367545678089,"
+ "\"version\":\"9.5\""
+ "}"
+ "],"
+ "\"name\":\"stanza1\","
+ "\"repo\":["
+ "{"
+ "\"cipher\":\"none\","
+ "\"key\":1,"
+ "\"status\":{"
+ "\"code\":0,"
+ "\"message\":\"ok\""
+ "}"
+ "}"
+ "],"
+ "\"status\":{"
+ "\"code\":0,"
+ "\"lock\":{\"backup\":{\"held\":false}},"
+ "\"message\":\"ok\""
+ "}"
+ "}"
+ "]",
+ "json - backup set requested");
+
//--------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("multi-repo: filter by backup type");
@@ -1691,13 +1839,136 @@ testRun(void)
" error list: base/16384/17000\n",
"text - multi-repo, backup set requested, found on repo2, report stanza and db over all repos");
- //--------------------------------------------------------------------------------------------------------------------------
- TEST_TITLE("option 'set' not valid for json output");
-
hrnCfgArgRawZ(argList2, cfgOptOutput, "json");
HRN_CFG_LOAD(cfgCmdInfo, argList2);
- TEST_ERROR(strZ(infoRender()), ConfigError, "option 'set' is currently only valid for text output");
+ TEST_RESULT_STR_Z(
+ infoRender(),
+ "["
+ "{"
+ "\"archive\":["
+ "{"
+ "\"database\":{"
+ "\"id\":1,"
+ "\"repo-key\":1"
+ "},"
+ "\"id\":\"9.4-1\","
+ "\"max\":\"000000020000000000000003\","
+ "\"min\":\"000000010000000000000002\""
+ "},"
+ "{"
+ "\"database\":{"
+ "\"id\":2,"
+ "\"repo-key\":1"
+ "},"
+ "\"id\":\"9.5-2\","
+ "\"max\":\"000000010000000000000005\","
+ "\"min\":\"000000010000000000000002\""
+ "},"
+ "{"
+ "\"database\":{"
+ "\"id\":1,"
+ "\"repo-key\":2"
+ "},"
+ "\"id\":\"9.5-1\","
+ "\"max\":\"000000010000000000000004\","
+ "\"min\":\"000000010000000000000003\""
+ "}"
+ "],"
+ "\"backup\":["
+ "{"
+ "\"archive\":{"
+ "\"start\":\"000000010000000000000004\","
+ "\"stop\":\"000000010000000000000004\""
+ "},"
+ "\"backrest\":{"
+ "\"format\":5,"
+ "\"version\":\"2.30\""
+ "},"
+ "\"database\":{"
+ "\"id\":1,"
+ "\"repo-key\":2"
+ "},"
+ "\"database-ref\":["
+ "{\"name\":\"mail\",\"oid\":16456},"
+ "{\"name\":\"postgres\",\"oid\":12173}"
+ "],"
+ "\"error\":true,"
+ "\"error-list\":[\"base/16384/17000\"],"
+ "\"info\":{"
+ "\"delta\":26897020,"
+ "\"repository\":{"
+ "\"delta\":3100,"
+ "\"size\":3159000"
+ "},"
+ "\"size\":26897000"
+ "},"
+ "\"label\":\"20201116-200000F\","
+ "\"link\":["
+ "{\"destination\":\"../pg_config/pg_hba.conf\",\"name\":\"pg_hba.conf\"},"
+ "{\"destination\":\"../pg_stat\",\"name\":\"pg_stat\"}"
+ "],"
+ "\"prior\":null,"
+ "\"reference\":null,"
+ "\"tablespace\":["
+ "{\"destination\":\"/tblspc/ts1\",\"name\":\"ts1\",\"oid\":1},"
+ "{\"destination\":\"/tblspc/ts12\",\"name\":\"ts12\",\"oid\":12}"
+ "],"
+ "\"timestamp\":{"
+ "\"start\":1605556800,"
+ "\"stop\":1605556805"
+ "},"
+ "\"type\":\"full\""
+ "}"
+ "],"
+ "\"cipher\":\"mixed\","
+ "\"db\":["
+ "{"
+ "\"id\":1,"
+ "\"repo-key\":1,"
+ "\"system-id\":6625592122879095702,"
+ "\"version\":\"9.4\""
+ "},"
+ "{"
+ "\"id\":2,"
+ "\"repo-key\":1,"
+ "\"system-id\":6626363367545678089,"
+ "\"version\":\"9.5\""
+ "},"
+ "{"
+ "\"id\":1,"
+ "\"repo-key\":2,"
+ "\"system-id\":6626363367545678089,"
+ "\"version\":\"9.5\""
+ "}"
+ "],"
+ "\"name\":\"stanza1\","
+ "\"repo\":["
+ "{"
+ "\"cipher\":\"none\","
+ "\"key\":1,"
+ "\"status\":{"
+ "\"code\":0,"
+ "\"message\":\"ok\""
+ "}"
+ "},"
+ "{"
+ "\"cipher\":\"aes-256-cbc\","
+ "\"key\":2,"
+ "\"status\":{"
+ "\"code\":0,"
+ "\"message\":\"ok\""
+ "}"
+ "}"
+ "],"
+ "\"status\":{"
+ "\"code\":0,"
+ "\"lock\":{\"backup\":{\"held\":false}},"
+ "\"message\":\"ok\""
+ "}"
+ "}"
+ "]",
+ "json - multi-repo, backup set requested, found on repo2, report stanza and db over all repos");
//--------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("backup set requested but no links, multiple checksum errors");
@@ -1765,10 +2036,118 @@ testRun(void)
" error list: base/16384/17000, base/32768/33000\n",
"text - backup set requested, no links");
+ hrnCfgArgRawZ(argList2, cfgOptOutput, "json");
+ HRN_CFG_LOAD(cfgCmdInfo, argList2);
+
+ TEST_RESULT_STR_Z(
+ infoRender(),
+ "["
+ "{"
+ "\"archive\":["
+ "{"
+ "\"database\":{"
+ "\"id\":1,"
+ "\"repo-key\":1"
+ "},"
+ "\"id\":\"9.4-1\","
+ "\"max\":\"000000020000000000000003\","
+ "\"min\":\"000000010000000000000002\""
+ "},"
+ "{"
+ "\"database\":{"
+ "\"id\":2,"
+ "\"repo-key\":1"
+ "},"
+ "\"id\":\"9.5-2\","
+ "\"max\":\"000000010000000000000005\","
+ "\"min\":\"000000010000000000000002\""
+ "}"
+ "],"
+ "\"backup\":["
+ "{"
+ "\"archive\":{"
+ "\"start\":\"000000010000000000000003\","
+ "\"stop\":null"
+ "},"
+ "\"backrest\":{"
+ "\"format\":5,"
+ "\"version\":\"2.08dev\""
+ "},"
+ "\"database\":{"
+ "\"id\":1,\"repo-key\":1"
+ "},"
+ "\"database-ref\":["
+ "{\"name\":\"mail\",\"oid\":16456},"
+ "{\"name\":\"postgres\",\"oid\":12173}"
+ "],"
+ "\"error\":true,"
+ "\"error-list\":[\"base/16384/17000\",\"base/32768/33000\"],"
+ "\"info\":{"
+ "\"delta\":8428,"
+ "\"repository\":{"
+ "\"delta\":346,"
+ "\"size\":2369186"
+ "},"
+ "\"size\":20162900"
+ "},"
+ "\"label\":\"20181119-152138F_20181119-152155I\","
+ "\"link\":null,"
+ "\"lsn\":{"
+ "\"start\":\"285/89000028\","
+ "\"stop\":\"285/89001F88\""
+ "},"
+ "\"prior\":\"20181119-152138F_20181119-152152D\","
+ "\"reference\":[\"20181119-152138F\",\"20181119-152138F_20181119-152152D\"],"
+ "\"tablespace\":null,"
+ "\"timestamp\":{"
+ "\"start\":1542640915,"
+ "\"stop\":1542640917"
+ "},"
+ "\"type\":\"incr\""
+ "}"
+ "],"
+ "\"cipher\":\"none\","
+ "\"db\":["
+ "{"
+ "\"id\":1,"
+ "\"repo-key\":1,"
+ "\"system-id\":6625592122879095702,"
+ "\"version\":\"9.4\""
+ "},"
+ "{"
+ "\"id\":2,"
+ "\"repo-key\":1,"
+ "\"system-id\":6626363367545678089,"
+ "\"version\":\"9.5\""
+ "}"
+ "],"
+ "\"name\":\"stanza1\","
+ "\"repo\":["
+ "{"
+ "\"cipher\":\"none\","
+ "\"key\":1,"
+ "\"status\":{"
+ "\"code\":0,"
+ "\"message\":\"ok\""
+ "}"
+ "}"
+ "],"
+ "\"status\":{"
+ "\"code\":0,"
+ "\"lock\":{\"backup\":{\"held\":false}},"
+ "\"message\":\"ok\""
+ "}"
+ "}"
+ "]",
+ "json - backup set requested, no links");
+
//--------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("backup set requested but no databases, no checksum error");
// Using the same configuration from previous test
+ argList2 = strLstDup(argListTextStanzaOpt);
+ hrnCfgArgRawZ(argList2, cfgOptSet, "20181119-152138F_20181119-152155I");
+ hrnCfgArgRawZ(argList2, cfgOptRepo, "1");
HRN_CFG_LOAD(cfgCmdInfo, argList2);
#define TEST_MANIFEST_NO_DB \
@@ -1826,6 +2205,107 @@ testRun(void)
" database list: none\n",
"text - backup set requested, no db and no checksum error");
+ hrnCfgArgRawZ(argList2, cfgOptOutput, "json");
+ HRN_CFG_LOAD(cfgCmdInfo, argList2);
+
+ TEST_RESULT_STR_Z(
+ infoRender(),
+ "["
+ "{"
+ "\"archive\":["
+ "{"
+ "\"database\":{"
+ "\"id\":1,"
+ "\"repo-key\":1"
+ "},"
+ "\"id\":\"9.4-1\","
+ "\"max\":\"000000020000000000000003\","
+ "\"min\":\"000000010000000000000002\""
+ "},"
+ "{"
+ "\"database\":{"
+ "\"id\":2,"
+ "\"repo-key\":1"
+ "},"
+ "\"id\":\"9.5-2\","
+ "\"max\":\"000000010000000000000005\","
+ "\"min\":\"000000010000000000000002\""
+ "}"
+ "],"
+ "\"backup\":["
+ "{"
+ "\"archive\":{"
+ "\"start\":\"000000010000000000000003\","
+ "\"stop\":null"
+ "},"
+ "\"backrest\":{"
+ "\"format\":5,"
+ "\"version\":\"2.08dev\""
+ "},"
+ "\"database\":{"
+ "\"id\":1,"
+ "\"repo-key\":1"
+ "},"
+ "\"database-ref\":[],"
+ "\"info\":{"
+ "\"delta\":8428,"
+ "\"repository\":{"
+ "\"delta\":346,"
+ "\"size\":2369186"
+ "},"
+ "\"size\":20162900"
+ "},"
+ "\"label\":\"20181119-152138F_20181119-152155I\","
+ "\"link\":null,"
+ "\"lsn\":{"
+ "\"start\":\"285/89000028\","
+ "\"stop\":\"285/89001F88\""
+ "},"
+ "\"prior\":\"20181119-152138F_20181119-152152D\","
+ "\"reference\":[\"20181119-152138F\",\"20181119-152138F_20181119-152152D\"],"
+ "\"tablespace\":null,"
+ "\"timestamp\":{"
+ "\"start\":1542640915,"
+ "\"stop\":1542640917"
+ "},"
+ "\"type\":\"incr\""
+ "}"
+ "],"
+ "\"cipher\":\"none\","
+ "\"db\":["
+ "{"
+ "\"id\":1,"
+ "\"repo-key\":1,"
+ "\"system-id\":6625592122879095702,"
+ "\"version\":\"9.4\""
+ "},"
+ "{"
+ "\"id\":2,"
+ "\"repo-key\":1,"
+ "\"system-id\":6626363367545678089,"
+ "\"version\":\"9.5\""
+ "}"
+ "],"
+ "\"name\":\"stanza1\","
+ "\"repo\":["
+ "{"
+ "\"cipher\":\"none\","
+ "\"key\":1,"
+ "\"status\":{"
+ "\"code\":0,"
+ "\"message\":\"ok\""
+ "}"
+ "}"
+ "],"
+ "\"status\":{"
+ "\"code\":0,"
+ "\"lock\":{\"backup\":{\"held\":false}},"
+ "\"message\":\"ok\""
+ "}"
+ "}"
+ "]",
+ "json - backup set requested, no db and no checksum error");
+
//--------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("backup set requested with missing backup lsn stop location");
[parent: 381fd0a5a4de]