1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-12 10:04:14 +02:00

Add db-exclude option.

Restore excluding the specified databases. Databases excluded will be restored as sparse, zeroed files to save space but still allow PostgreSQL to perform recovery. After recovery, those databases will not be accessible but can be removed with the drop database command. The --db-exclude option can be passed multiple times to specify more than one database to exclude.

When used in combination with the --db-include option, --db-exclude will only apply to standard system databases (template0, template1, and postgres).
This commit is contained in:
Stefan Fercot 2021-04-19 21:01:00 +02:00 committed by GitHub
parent a75b413ac2
commit 292f836f12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 268 additions and 17 deletions

View File

@ -950,11 +950,22 @@
<example>off</example>
</config-key>
<!-- CONFIG - RESTORE SECTION - DB-EXCLUDE KEY -->
<config-key id="db-exclude" name="Exclude Database">
<summary>Restore excluding the specified databases.</summary>
<text>Databases excluded will be restored as sparse, zeroed files to save space but still allow <postgres/> to perform recovery. After recovery, those databases will not be accessible but can be removed with the <id>drop database</id> command. The <setting>{[dash]}-db-exclude</setting> option can be passed multiple times to specify more than one database to exclude.
When used in combination with the <setting>{[dash]}-db-include</setting> option, <setting>{[dash]}-db-exclude</setting> will only apply to standard system databases (<id>template0</id>, <id>template1</id>, and <id>postgres</id>).</text>
<example>db_main</example>
</config-key>
<!-- CONFIG - RESTORE SECTION - DB-INCLUDE KEY -->
<config-key id="db-include" name="Include Database">
<summary>Restore only specified databases.</summary>
<text>This feature allows only selected databases to be restored. Databases not specifically included will be restored as sparse, zeroed files to save space but still allow <postgres/> to perform recovery. After recovery the databases that were not included will not be accessible but can be removed with the <id>drop database</id> command. <admonition type="note">built-in databases (<id>template0</id>, <id>template1</id>, and <id>postgres</id>) are always restored.</admonition>The <setting>{[dash]}-db-include</setting> option can be passed multiple times to specify more than one database to include.
<text>This feature allows only selected databases to be restored. Databases not specifically included will be restored as sparse, zeroed files to save space but still allow <postgres/> to perform recovery. After recovery, the databases that were not included will not be accessible but can be removed with the <id>drop database</id> command. <admonition type="note">built-in databases (<id>template0</id>, <id>template1</id>, and <id>postgres</id>) are always restored unless specifically excluded.</admonition>The <setting>{[dash]}-db-include</setting> option can be passed multiple times to specify more than one database to include.
See <link page="user-guide" section="/restore/option-db-include">Restore Selected Databases</link> for additional information and caveats.</text>

View File

@ -13,6 +13,22 @@
<release-list>
<release date="XXXX-XX-XX" version="2.34dev" title="UNDER DEVELOPMENT">
<release-core-list>
<release-improvement-list>
<release-item>
<github-issue id="986"/>
<github-pull-request id="1337"/>
<release-item-contributor-list>
<release-item-contributor id="stefan.fercot"/>
<release-item-reviewer id="cynthia.shang"/>
</release-item-contributor-list>
<p>Add <br-option>db-exclude</br-option> option.</p>
</release-item>
</release-improvement-list>
</release-core-list>
<release-doc-list>
<release-improvement-list>
<release-item>

View File

@ -1130,6 +1130,15 @@ option:
command-role:
default: {}
db-exclude:
section: global
type: list
required: false
command:
restore: {}
command-role:
default: {}
db-include:
section: global
type: list

View File

@ -1384,6 +1384,41 @@ static const unsigned char helpDataPack[] =
0x65, 0x74, 0x20, 0x74, 0x6F, 0x20, 0x2F, 0x63, 0x6F, 0x6E, 0x66, 0x2F, 0x70, 0x67, 0x62, 0x61, 0x63, 0x6B, 0x72, 0x65,
0x73, 0x74, 0x2F, 0x63, 0x6F, 0x6E, 0x66, 0x2E, 0x64, 0x2E,
// db-exclude option
// -------------------------------------------------------------------------------------------------------------------------
pckTypeStr << 4 | 0x0B, 0x07, // Section
0x72, 0x65, 0x73, 0x74, 0x6F, 0x72, 0x65,
pckTypeStr << 4 | 0x08, 0x2A, // Summary
0x52, 0x65, 0x73, 0x74, 0x6F, 0x72, 0x65, 0x20, 0x65, 0x78, 0x63, 0x6C, 0x75, 0x64, 0x69, 0x6E, 0x67, 0x20, 0x74, 0x68,
0x65, 0x20, 0x73, 0x70, 0x65, 0x63, 0x69, 0x66, 0x69, 0x65, 0x64, 0x20, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65,
0x73, 0x2E,
pckTypeStr << 4 | 0x08, 0xDE, 0x03, // Description
0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x73, 0x20, 0x65, 0x78, 0x63, 0x6C, 0x75, 0x64, 0x65, 0x64, 0x20, 0x77,
0x69, 0x6C, 0x6C, 0x20, 0x62, 0x65, 0x20, 0x72, 0x65, 0x73, 0x74, 0x6F, 0x72, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20, 0x73,
0x70, 0x61, 0x72, 0x73, 0x65, 0x2C, 0x20, 0x7A, 0x65, 0x72, 0x6F, 0x65, 0x64, 0x20, 0x66, 0x69, 0x6C, 0x65, 0x73, 0x20,
0x74, 0x6F, 0x20, 0x73, 0x61, 0x76, 0x65, 0x20, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x62, 0x75, 0x74, 0x20, 0x73, 0x74,
0x69, 0x6C, 0x6C, 0x20, 0x61, 0x6C, 0x6C, 0x6F, 0x77, 0x20, 0x50, 0x6F, 0x73, 0x74, 0x67, 0x72, 0x65, 0x53, 0x51, 0x4C,
0x20, 0x74, 0x6F, 0x20, 0x70, 0x65, 0x72, 0x66, 0x6F, 0x72, 0x6D, 0x20, 0x72, 0x65, 0x63, 0x6F, 0x76, 0x65, 0x72, 0x79,
0x2E, 0x20, 0x41, 0x66, 0x74, 0x65, 0x72, 0x20, 0x72, 0x65, 0x63, 0x6F, 0x76, 0x65, 0x72, 0x79, 0x2C, 0x20, 0x74, 0x68,
0x6F, 0x73, 0x65, 0x20, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x73, 0x20, 0x77, 0x69, 0x6C, 0x6C, 0x20, 0x6E,
0x6F, 0x74, 0x20, 0x62, 0x65, 0x20, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x69, 0x62, 0x6C, 0x65, 0x20, 0x62, 0x75, 0x74,
0x20, 0x63, 0x61, 0x6E, 0x20, 0x62, 0x65, 0x20, 0x72, 0x65, 0x6D, 0x6F, 0x76, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68,
0x20, 0x74, 0x68, 0x65, 0x20, 0x64, 0x72, 0x6F, 0x70, 0x20, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x20, 0x63,
0x6F, 0x6D, 0x6D, 0x61, 0x6E, 0x64, 0x2E, 0x20, 0x54, 0x68, 0x65, 0x20, 0x2D, 0x2D, 0x64, 0x62, 0x2D, 0x65, 0x78, 0x63,
0x6C, 0x75, 0x64, 0x65, 0x20, 0x6F, 0x70, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x63, 0x61, 0x6E, 0x20, 0x62, 0x65, 0x20, 0x70,
0x61, 0x73, 0x73, 0x65, 0x64, 0x20, 0x6D, 0x75, 0x6C, 0x74, 0x69, 0x70, 0x6C, 0x65, 0x20, 0x74, 0x69, 0x6D, 0x65, 0x73,
0x20, 0x74, 0x6F, 0x20, 0x73, 0x70, 0x65, 0x63, 0x69, 0x66, 0x79, 0x20, 0x6D, 0x6F, 0x72, 0x65, 0x20, 0x74, 0x68, 0x61,
0x6E, 0x20, 0x6F, 0x6E, 0x65, 0x20, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x20, 0x74, 0x6F, 0x20, 0x65, 0x78,
0x63, 0x6C, 0x75, 0x64, 0x65, 0x2E, 0x0A, 0x0A,
0x57, 0x68, 0x65, 0x6E, 0x20, 0x75, 0x73, 0x65, 0x64, 0x20, 0x69, 0x6E, 0x20, 0x63, 0x6F, 0x6D, 0x62, 0x69, 0x6E, 0x61,
0x74, 0x69, 0x6F, 0x6E, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, 0x68, 0x65, 0x20, 0x2D, 0x2D, 0x64, 0x62, 0x2D, 0x69,
0x6E, 0x63, 0x6C, 0x75, 0x64, 0x65, 0x20, 0x6F, 0x70, 0x74, 0x69, 0x6F, 0x6E, 0x2C, 0x20, 0x2D, 0x2D, 0x64, 0x62, 0x2D,
0x65, 0x78, 0x63, 0x6C, 0x75, 0x64, 0x65, 0x20, 0x77, 0x69, 0x6C, 0x6C, 0x20, 0x6F, 0x6E, 0x6C, 0x79, 0x20, 0x61, 0x70,
0x70, 0x6C, 0x79, 0x20, 0x74, 0x6F, 0x20, 0x73, 0x74, 0x61, 0x6E, 0x64, 0x61, 0x72, 0x64, 0x20, 0x73, 0x79, 0x73, 0x74,
0x65, 0x6D, 0x20, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x73, 0x20, 0x28, 0x74, 0x65, 0x6D, 0x70, 0x6C, 0x61,
0x74, 0x65, 0x30, 0x2C, 0x20, 0x74, 0x65, 0x6D, 0x70, 0x6C, 0x61, 0x74, 0x65, 0x31, 0x2C, 0x20, 0x61, 0x6E, 0x64, 0x20,
0x70, 0x6F, 0x73, 0x74, 0x67, 0x72, 0x65, 0x73, 0x29, 0x2E,
// db-include option
// -------------------------------------------------------------------------------------------------------------------------
pckTypeStr << 4 | 0x0B, 0x07, // Section
@ -1391,7 +1426,7 @@ static const unsigned char helpDataPack[] =
pckTypeStr << 4 | 0x08, 0x21, // Summary
0x52, 0x65, 0x73, 0x74, 0x6F, 0x72, 0x65, 0x20, 0x6F, 0x6E, 0x6C, 0x79, 0x20, 0x73, 0x70, 0x65, 0x63, 0x69, 0x66, 0x69,
0x65, 0x64, 0x20, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x73, 0x2E,
pckTypeStr << 4 | 0x08, 0xC4, 0x04, // Description
pckTypeStr << 4 | 0x08, 0xE2, 0x04, // Description
0x54, 0x68, 0x69, 0x73, 0x20, 0x66, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x20, 0x61, 0x6C, 0x6C, 0x6F, 0x77, 0x73, 0x20,
0x6F, 0x6E, 0x6C, 0x79, 0x20, 0x73, 0x65, 0x6C, 0x65, 0x63, 0x74, 0x65, 0x64, 0x20, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61,
0x73, 0x65, 0x73, 0x20, 0x74, 0x6F, 0x20, 0x62, 0x65, 0x20, 0x72, 0x65, 0x73, 0x74, 0x6F, 0x72, 0x65, 0x64, 0x2E, 0x20,
@ -1402,18 +1437,19 @@ static const unsigned char helpDataPack[] =
0x73, 0x61, 0x76, 0x65, 0x20, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x62, 0x75, 0x74, 0x20, 0x73, 0x74, 0x69, 0x6C, 0x6C,
0x20, 0x61, 0x6C, 0x6C, 0x6F, 0x77, 0x20, 0x50, 0x6F, 0x73, 0x74, 0x67, 0x72, 0x65, 0x53, 0x51, 0x4C, 0x20, 0x74, 0x6F,
0x20, 0x70, 0x65, 0x72, 0x66, 0x6F, 0x72, 0x6D, 0x20, 0x72, 0x65, 0x63, 0x6F, 0x76, 0x65, 0x72, 0x79, 0x2E, 0x20, 0x41,
0x66, 0x74, 0x65, 0x72, 0x20, 0x72, 0x65, 0x63, 0x6F, 0x76, 0x65, 0x72, 0x79, 0x20, 0x74, 0x68, 0x65, 0x20, 0x64, 0x61,
0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x73, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x77, 0x65, 0x72, 0x65, 0x20, 0x6E, 0x6F,
0x74, 0x20, 0x69, 0x6E, 0x63, 0x6C, 0x75, 0x64, 0x65, 0x64, 0x20, 0x77, 0x69, 0x6C, 0x6C, 0x20, 0x6E, 0x6F, 0x74, 0x20,
0x62, 0x65, 0x20, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x69, 0x62, 0x6C, 0x65, 0x20, 0x62, 0x75, 0x74, 0x20, 0x63, 0x61,
0x6E, 0x20, 0x62, 0x65, 0x20, 0x72, 0x65, 0x6D, 0x6F, 0x76, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, 0x68,
0x65, 0x20, 0x64, 0x72, 0x6F, 0x70, 0x20, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x20, 0x63, 0x6F, 0x6D, 0x6D,
0x61, 0x6E, 0x64, 0x2E, 0x20, 0x0A,
0x66, 0x74, 0x65, 0x72, 0x20, 0x72, 0x65, 0x63, 0x6F, 0x76, 0x65, 0x72, 0x79, 0x2C, 0x20, 0x74, 0x68, 0x65, 0x20, 0x64,
0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x73, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x77, 0x65, 0x72, 0x65, 0x20, 0x6E,
0x6F, 0x74, 0x20, 0x69, 0x6E, 0x63, 0x6C, 0x75, 0x64, 0x65, 0x64, 0x20, 0x77, 0x69, 0x6C, 0x6C, 0x20, 0x6E, 0x6F, 0x74,
0x20, 0x62, 0x65, 0x20, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x69, 0x62, 0x6C, 0x65, 0x20, 0x62, 0x75, 0x74, 0x20, 0x63,
0x61, 0x6E, 0x20, 0x62, 0x65, 0x20, 0x72, 0x65, 0x6D, 0x6F, 0x76, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74,
0x68, 0x65, 0x20, 0x64, 0x72, 0x6F, 0x70, 0x20, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x20, 0x63, 0x6F, 0x6D,
0x6D, 0x61, 0x6E, 0x64, 0x2E, 0x20, 0x0A,
0x4E, 0x4F, 0x54, 0x45, 0x3A, 0x20, 0x62, 0x75, 0x69, 0x6C, 0x74, 0x2D, 0x69, 0x6E, 0x20, 0x64, 0x61, 0x74, 0x61, 0x62,
0x61, 0x73, 0x65, 0x73, 0x20, 0x28, 0x74, 0x65, 0x6D, 0x70, 0x6C, 0x61, 0x74, 0x65, 0x30, 0x2C, 0x20, 0x74, 0x65, 0x6D,
0x70, 0x6C, 0x61, 0x74, 0x65, 0x31, 0x2C, 0x20, 0x61, 0x6E, 0x64, 0x20, 0x70, 0x6F, 0x73, 0x74, 0x67, 0x72, 0x65, 0x73,
0x29, 0x20, 0x61, 0x72, 0x65, 0x20, 0x61, 0x6C, 0x77, 0x61, 0x79, 0x73, 0x20, 0x72, 0x65, 0x73, 0x74, 0x6F, 0x72, 0x65,
0x64, 0x2E, 0x0A, 0x0A,
0x64, 0x20, 0x75, 0x6E, 0x6C, 0x65, 0x73, 0x73, 0x20, 0x73, 0x70, 0x65, 0x63, 0x69, 0x66, 0x69, 0x63, 0x61, 0x6C, 0x6C,
0x79, 0x20, 0x65, 0x78, 0x63, 0x6C, 0x75, 0x64, 0x65, 0x64, 0x2E, 0x0A, 0x0A,
0x54, 0x68, 0x65, 0x20, 0x2D, 0x2D, 0x64, 0x62, 0x2D, 0x69, 0x6E, 0x63, 0x6C, 0x75, 0x64, 0x65, 0x20, 0x6F, 0x70, 0x74,
0x69, 0x6F, 0x6E, 0x20, 0x63, 0x61, 0x6E, 0x20, 0x62, 0x65, 0x20, 0x70, 0x61, 0x73, 0x73, 0x65, 0x64, 0x20, 0x6D, 0x75,
0x6C, 0x74, 0x69, 0x70, 0x6C, 0x65, 0x20, 0x74, 0x69, 0x6D, 0x65, 0x73, 0x20, 0x74, 0x6F, 0x20, 0x73, 0x70, 0x65, 0x63,

View File

@ -1279,8 +1279,8 @@ restoreSelectiveExpression(Manifest *manifest)
String *result = NULL;
// Continue if db-include is specified
if (cfgOptionTest(cfgOptDbInclude))
// Continue if databases to include or exclude have been specified
if (cfgOptionTest(cfgOptDbExclude) || cfgOptionTest(cfgOptDbInclude))
{
MEM_CONTEXT_TEMP_BEGIN()
{
@ -1345,6 +1345,30 @@ restoreSelectiveExpression(Manifest *manifest)
// Log databases found
LOG_DETAIL_FMT("databases found for selective restore (%s)", strZ(strLstJoin(dbList, ", ")));
// Generate list with ids of databases to exclude
StringList *excludeDbIdList = strLstNew();
const StringList *excludeList = strLstNewVarLst(cfgOptionLst(cfgOptDbExclude));
for (unsigned int excludeIdx = 0; excludeIdx < strLstSize(excludeList); excludeIdx++)
{
const String *excludeDb = strLstGet(excludeList, excludeIdx);
// If the db to exclude is not in the list as an id then search by name
if (!strLstExists(dbList, excludeDb))
{
const ManifestDb *db = manifestDbFindDefault(manifest, excludeDb, NULL);
if (db == NULL || !strLstExists(dbList, varStrForce(VARUINT(db->id))))
THROW_FMT(DbMissingError, "database to exclude '%s' does not exist", strZ(excludeDb));
// Set the exclude db to the id if the name mapping was successful
excludeDb = varStrForce(VARUINT(db->id));
}
// Add to exclude list
strLstAdd(excludeDbIdList, excludeDb);
}
// Remove included databases from the list
const StringList *includeList = strLstNewVarLst(cfgOptionLst(cfgOptDbInclude));
@ -1368,13 +1392,27 @@ restoreSelectiveExpression(Manifest *manifest)
if (strLstExists(systemDbIdList, includeDb))
THROW(DbInvalidError, "system databases (template0, postgres, etc.) are included by default");
// Error if the db id is in the exclude list
if (strLstExists(excludeDbIdList, includeDb))
THROW_FMT(DbInvalidError, "database to include '%s' is in the exclude list", strZ(includeDb));
// Remove from list of DBs to zero
strLstRemove(dbList, includeDb);
}
// Exclude the system databases from the list
strLstSort(systemDbIdList, sortOrderAsc);
dbList = strLstMergeAnti(dbList, systemDbIdList);
// Only exclude specified db in case no db to include has been provided
if (strLstEmpty(includeList))
{
dbList = strLstDup(excludeDbIdList);
}
// Else, remove the system databases from list of DBs to zero unless they are excluded explicitly
else
{
strLstSort(systemDbIdList, sortOrderAsc);
strLstSort(excludeDbIdList, sortOrderAsc);
systemDbIdList = strLstMergeAnti(systemDbIdList, excludeDbIdList);
dbList = strLstMergeAnti(dbList, systemDbIdList);
}
// Build regular expression to identify files that will be zeroed
String *expression = NULL;

View File

@ -278,6 +278,7 @@ STRING_EXTERN(CFGOPT_COMPRESS_TYPE_STR, CFGOPT_COMPR
STRING_EXTERN(CFGOPT_CONFIG_STR, CFGOPT_CONFIG);
STRING_EXTERN(CFGOPT_CONFIG_INCLUDE_PATH_STR, CFGOPT_CONFIG_INCLUDE_PATH);
STRING_EXTERN(CFGOPT_CONFIG_PATH_STR, CFGOPT_CONFIG_PATH);
STRING_EXTERN(CFGOPT_DB_EXCLUDE_STR, CFGOPT_DB_EXCLUDE);
STRING_EXTERN(CFGOPT_DB_INCLUDE_STR, CFGOPT_DB_INCLUDE);
STRING_EXTERN(CFGOPT_DB_TIMEOUT_STR, CFGOPT_DB_TIMEOUT);
STRING_EXTERN(CFGOPT_DELTA_STR, CFGOPT_DELTA);

View File

@ -102,6 +102,8 @@ Option constants
STRING_DECLARE(CFGOPT_CONFIG_INCLUDE_PATH_STR);
#define CFGOPT_CONFIG_PATH "config-path"
STRING_DECLARE(CFGOPT_CONFIG_PATH_STR);
#define CFGOPT_DB_EXCLUDE "db-exclude"
STRING_DECLARE(CFGOPT_DB_EXCLUDE_STR);
#define CFGOPT_DB_INCLUDE "db-include"
STRING_DECLARE(CFGOPT_DB_INCLUDE_STR);
#define CFGOPT_DB_TIMEOUT "db-timeout"
@ -211,7 +213,7 @@ Option constants
#define CFGOPT_TYPE "type"
STRING_DECLARE(CFGOPT_TYPE_STR);
#define CFG_OPTION_TOTAL 129
#define CFG_OPTION_TOTAL 130
/***********************************************************************************************************************************
Command enum
@ -276,6 +278,7 @@ typedef enum
cfgOptConfig,
cfgOptConfigIncludePath,
cfgOptConfigPath,
cfgOptDbExclude,
cfgOptDbInclude,
cfgOptDbTimeout,
cfgOptDelta,

View File

@ -1046,6 +1046,21 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
),
),
// -----------------------------------------------------------------------------------------------------------------------------
PARSE_RULE_OPTION
(
PARSE_RULE_OPTION_NAME("db-exclude"),
PARSE_RULE_OPTION_TYPE(cfgOptTypeList),
PARSE_RULE_OPTION_REQUIRED(false),
PARSE_RULE_OPTION_SECTION(cfgSectionGlobal),
PARSE_RULE_OPTION_MULTI(true),
PARSE_RULE_OPTION_COMMAND_ROLE_DEFAULT_VALID_LIST
(
PARSE_RULE_OPTION_COMMAND(cfgCmdRestore)
),
),
// -----------------------------------------------------------------------------------------------------------------------------
PARSE_RULE_OPTION
(
@ -6768,6 +6783,18 @@ static const struct option optionList[] =
.val = PARSE_OPTION_FLAG | cfgOptConfigPath,
},
// db-exclude option
// -----------------------------------------------------------------------------------------------------------------------------
{
.name = "db-exclude",
.has_arg = required_argument,
.val = PARSE_OPTION_FLAG | cfgOptDbExclude,
},
{
.name = "reset-db-exclude",
.val = PARSE_OPTION_FLAG | PARSE_RESET_FLAG | cfgOptDbExclude,
},
// db-include option
// -----------------------------------------------------------------------------------------------------------------------------
{
@ -10610,6 +10637,7 @@ static const ConfigOption optionResolveOrder[] =
cfgOptConfig,
cfgOptConfigIncludePath,
cfgOptConfigPath,
cfgOptDbExclude,
cfgOptDbInclude,
cfgOptDbTimeout,
cfgOptDelta,

View File

@ -158,6 +158,7 @@ testRun(void)
"\n"
" --archive-mode preserve or disable archiving on restored\n"
" cluster [default=preserve]\n"
" --db-exclude restore excluding the specified databases\n"
" --db-include restore only specified databases\n"
" [current=db1, db2]\n"
" --force force a restore [default=n]\n"

View File

@ -1304,6 +1304,17 @@ testRun(void)
TEST_RESULT_LOG("P00 DETAIL: databases found for selective restore (1, 12168, 16380, 16381, 16385)");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("database id to exclude is missing on disk");
argList = strLstDup(argListClean);
strLstAddZ(argList, "--db-exclude=" UTF8_DB_NAME);
harnessCfgLoad(cfgCmdRestore, argList);
TEST_ERROR(restoreSelectiveExpression(manifest), DbMissingError, "database to exclude '" UTF8_DB_NAME "' does not exist");
TEST_RESULT_LOG("P00 DETAIL: databases found for selective restore (1, 12168, 16380, 16381, 16385)");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("all databases selected");
@ -1314,6 +1325,10 @@ testRun(void)
}
MEM_CONTEXT_END();
argList = strLstDup(argListClean);
strLstAddZ(argList, "--db-include=" UTF8_DB_NAME);
harnessCfgLoad(cfgCmdRestore, argList);
TEST_RESULT_STR(restoreSelectiveExpression(manifest), NULL, "all databases selected");
TEST_RESULT_LOG(
@ -1358,7 +1373,7 @@ testRun(void)
"system databases (template0, postgres, etc.) are included by default");
TEST_RESULT_LOG("P00 DETAIL: databases found for selective restore (1, 12168, 16380, 16381, 16384, 16385)");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("error on missing database selected");
@ -1436,6 +1451,99 @@ testRun(void)
TEST_RESULT_LOG(
"P00 DETAIL: databases found for selective restore (1, 12168, 16380, 16381, 16384, 16385, 32768, 65536)\n"
"P00 DETAIL: databases excluded (zeroed) from selective restore (32768, 65536)");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("exclude database by id");
argList = strLstDup(argListClean);
strLstAddZ(argList, "--db-exclude=16384");
harnessCfgLoad(cfgCmdRestore, argList);
TEST_RESULT_STR_Z(
restoreSelectiveExpression(manifest),
"(^pg_data/base/16384/)|(^pg_tblspc/16387/PG_9.4_201409291/16384/)",
"check expression");
TEST_RESULT_LOG(
"P00 DETAIL: databases found for selective restore (1, 12168, 16380, 16381, 16384, 16385, 32768, 65536)\n"
"P00 DETAIL: databases excluded (zeroed) from selective restore (16384)");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("exclude database by name");
argList = strLstDup(argListClean);
strLstAddZ(argList, "--db-exclude=" UTF8_DB_NAME);
harnessCfgLoad(cfgCmdRestore, argList);
TEST_RESULT_STR_Z(
restoreSelectiveExpression(manifest),
"(^pg_data/base/16384/)|(^pg_tblspc/16387/PG_9.4_201409291/16384/)",
"check expression");
TEST_RESULT_LOG(
"P00 DETAIL: databases found for selective restore (1, 12168, 16380, 16381, 16384, 16385, 32768, 65536)\n"
"P00 DETAIL: databases excluded (zeroed) from selective restore (16384)");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("exclude system database");
argList = strLstDup(argListClean);
strLstAddZ(argList, "--db-exclude=16385");
harnessCfgLoad(cfgCmdRestore, argList);
TEST_RESULT_STR_Z(
restoreSelectiveExpression(manifest),
"(^pg_data/base/16385/)|(^pg_tblspc/16387/PG_9.4_201409291/16385/)",
"check expression");
TEST_RESULT_LOG(
"P00 DETAIL: databases found for selective restore (1, 12168, 16380, 16381, 16384, 16385, 32768, 65536)\n"
"P00 DETAIL: databases excluded (zeroed) from selective restore (16385)");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("error on missing database to exclude selected");
argList = strLstDup(argListClean);
strLstAddZ(argList, "--db-exclude=7777777");
harnessCfgLoad(cfgCmdRestore, argList);
TEST_ERROR(restoreSelectiveExpression(manifest), DbMissingError, "database to exclude '7777777' does not exist");
TEST_RESULT_LOG("P00 DETAIL: databases found for selective restore (1, 12168, 16380, 16381, 16384, 16385, 32768, 65536)");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("error on combining include and exclude options");
argList = strLstDup(argListClean);
strLstAddZ(argList, "--db-include=test2");
strLstAddZ(argList, "--db-exclude=test2");
harnessCfgLoad(cfgCmdRestore, argList);
TEST_ERROR(restoreSelectiveExpression(manifest), DbInvalidError, "database to include '32768' is in the exclude list");
TEST_RESULT_LOG("P00 DETAIL: databases found for selective restore (1, 12168, 16380, 16381, 16384, 16385, 32768, 65536)");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("combine include and exclude options");
argList = strLstDup(argListClean);
strLstAddZ(argList, "--db-include=16384");
strLstAddZ(argList, "--db-exclude=1");
strLstAddZ(argList, "--db-exclude=16385");
strLstAddZ(argList, "--db-exclude=32768"); // user databases excluded will be silently ignored
harnessCfgLoad(cfgCmdRestore, argList);
TEST_RESULT_STR_Z(
restoreSelectiveExpression(manifest),
"(^pg_data/base/1/)|(^pg_tblspc/16387/PG_9.4_201409291/1/)|"
"(^pg_data/base/16385/)|(^pg_tblspc/16387/PG_9.4_201409291/16385/)|"
"(^pg_data/base/32768/)|(^pg_tblspc/16387/PG_9.4_201409291/32768/)|"
"(^pg_data/base/65536/)|(^pg_tblspc/16387/PG_9.4_201409291/65536/)",
"check expression");
TEST_RESULT_LOG(
"P00 DETAIL: databases found for selective restore (1, 12168, 16380, 16381, 16384, 16385, 32768, 65536)\n"
"P00 DETAIL: databases excluded (zeroed) from selective restore (1, 16385, 32768, 65536)");
}
// *****************************************************************************************************************************