Skip to content
Permalink
Browse files

Bypass database checks when stanza-delete issued with force.

Previously it was not possible to delete a stanza if the PostgreSQL server could not be contacted.

Contributed by Cynthia Shang.
Suggested by Roman.
  • Loading branch information...
cmwshang authored and dwsteele committed May 15, 2019
1 parent 5c1d4bc commit 18d4cb574180d279dbbdabd8b87b9dab43115659
@@ -25,6 +25,15 @@
</release-bug-list>

<release-improvement-list>
<release-item>
<release-item-contributor-list>
<release-item-ideator id="hatifnatt"/>
<release-item-contributor id="cynthia.shang"/>
</release-item-contributor-list>

<p>Bypass database checks when <cmd>stanza-delete</cmd> issued with <br-option>force</br-option>.</p>
</release-item>

<release-item>
<p>Improve performance of non-blocking reads by using maximum buffer size.</p>
</release-item>
@@ -7022,6 +7031,11 @@
<contributor-id type="github">guruguruguru</contributor-id>
</contributor>

<contributor id="hatifnatt">
<contributor-name-display>Roman</contributor-name-display>
<contributor-id type="github">hatifnatt</contributor-id>
</contributor>

<contributor id="hans.jurgen.schonig">
<contributor-name-display>Hans-J&amp;uuml;rgen Sch&amp;ouml;nig</contributor-name-display>
</contributor>
@@ -307,18 +307,22 @@ sub stanzaDelete
"\nHINT: has the pgbackrest stop command been run on this server?", ERROR_FILE_MISSING);
}

# Get the master database object and index
my ($oDbMaster, $iMasterRemoteIdx) = dbObjectGet({bMasterOnly => true});
# If a force has not been issued, then check the database
if (!cfgOption(CFGOPT_FORCE))
{
# Get the master database object and index
my ($oDbMaster, $iMasterRemoteIdx) = dbObjectGet({bMasterOnly => true});

# Initialize the master file object and path
my $oStorageDbMaster = storageDb({iRemoteIdx => $iMasterRemoteIdx});
# Initialize the master file object and path
my $oStorageDbMaster = storageDb({iRemoteIdx => $iMasterRemoteIdx});

# Check if Postgres is running and if so only continue when forced
if ($oStorageDbMaster->exists(DB_FILE_POSTMASTERPID) && !cfgOption(CFGOPT_FORCE))
{
confess &log(ERROR, DB_FILE_POSTMASTERPID . " exists - looks like the postmaster is running. " .
"To delete stanza '${strStanza}', shutdown the postmaster for stanza '${strStanza}' and try again, " .
"or use --force.", ERROR_POSTMASTER_RUNNING);
# Check if Postgres is running and if so only continue when forced
if ($oStorageDbMaster->exists(DB_FILE_POSTMASTERPID))
{
confess &log(ERROR, DB_FILE_POSTMASTERPID . " exists - looks like the postmaster is running. " .
"To delete stanza '${strStanza}', shutdown the postmaster for stanza '${strStanza}' and try again, " .
"or use --force.", ERROR_POSTMASTER_RUNNING);
}
}

# Delete the archive info files
"\"\\nHINT: has the pgbackrest stop command been run on this server?\", ERROR_FILE_MISSING);\n"
"}\n"
"\n\n"
"if (!cfgOption(CFGOPT_FORCE))\n"
"{\n"
"\n"
"my ($oDbMaster, $iMasterRemoteIdx) = dbObjectGet({bMasterOnly => true});\n"
"\n\n"
"my $oStorageDbMaster = storageDb({iRemoteIdx => $iMasterRemoteIdx});\n"
"\n\n"
"if ($oStorageDbMaster->exists(DB_FILE_POSTMASTERPID) && !cfgOption(CFGOPT_FORCE))\n"
"if ($oStorageDbMaster->exists(DB_FILE_POSTMASTERPID))\n"
"{\n"
"confess &log(ERROR, DB_FILE_POSTMASTERPID . \" exists - looks like the postmaster is running. \" .\n"
"\"To delete stanza '${strStanza}', shutdown the postmaster for stanza '${strStanza}' and try again, \" .\n"
"\"or use --force.\", ERROR_POSTMASTER_RUNNING);\n"
"}\n"
"}\n"
"\n\n"
"$oStorageRepo->remove(STORAGE_REPO_ARCHIVE . '/' . ARCHIVE_INFO_FILE, {bIgnoreMissing => true});\n"
"$oStorageRepo->remove(STORAGE_REPO_ARCHIVE . '/' . ARCHIVE_INFO_FILE . INI_COPY_EXT, {bIgnoreMissing => true});\n"
@@ -312,3 +312,23 @@ repo1-path=[TEST_PATH]/backup/repo
[global:backup]
archive-copy=y
start-fast=y

stop all stanzas (db-master host)
> [CONTAINER-EXEC] db-master [BACKREST-BIN] --config=[TEST_PATH]/db-master/pgbackrest.conf stop
------------------------------------------------------------------------------------------------------------------------------------

stop db stanza (backup host)
> [CONTAINER-EXEC] backup [BACKREST-BIN] --config=[TEST_PATH]/backup/pgbackrest.conf --stanza=db stop
------------------------------------------------------------------------------------------------------------------------------------

stanza-delete db - delete stanza with --force when pgbackrest on pg host not accessible (backup host)
> [CONTAINER-EXEC] backup [BACKREST-BIN] --config=[TEST_PATH]/backup/pgbackrest.conf --stanza=db --log-level-console=detail --force stanza-delete
------------------------------------------------------------------------------------------------------------------------------------

start all stanzas (db-master host)
> [CONTAINER-EXEC] db-master [BACKREST-BIN] --config=[TEST_PATH]/db-master/pgbackrest.conf start
------------------------------------------------------------------------------------------------------------------------------------

start all stanzas (backup host)
> [CONTAINER-EXEC] backup [BACKREST-BIN] --config=[TEST_PATH]/backup/pgbackrest.conf start
------------------------------------------------------------------------------------------------------------------------------------
@@ -988,6 +988,22 @@ sub run
'succeed on --no-' . cfgOptionName(CFGOPT_ONLINE) . ' with --' . cfgOptionName(CFGOPT_FORCE),
{strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE) . ' --' . cfgOptionName(CFGOPT_FORCE)});
}

# Stanza-delete --force without access to pgbackrest on database host
#---------------------------------------------------------------------------------------------------------------------------
if ($bTestExtra && !$bS3 && $bHostBackup)
{
# With stanza-delete --force, allow stanza to be deleted regardless of accessiblility of database host
if ($bHostBackup)
{
$oHostDbMaster->stop();
$oHostBackup->stop({strStanza => $self->stanza});
$oHostBackup->stanzaDelete("delete stanza with --force when pgbackrest on pg host not accessible",
{strOptionalParam => ' --' . cfgOptionName(CFGOPT_FORCE)});
$oHostDbMaster->start();
$oHostBackup->start();
}
}
}
}
}

0 comments on commit 18d4cb5

Please sign in to comment.
You can’t perform that action at this time.