You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2026-05-22 10:15:16 +02:00
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.
This commit is contained in:
committed by
David Steele
parent
5c1d4bcd0d
commit
18d4cb5741
@@ -25,6 +25,15 @@
|
|||||||
</release-bug-list>
|
</release-bug-list>
|
||||||
|
|
||||||
<release-improvement-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>
|
<release-item>
|
||||||
<p>Improve performance of non-blocking reads by using maximum buffer size.</p>
|
<p>Improve performance of non-blocking reads by using maximum buffer size.</p>
|
||||||
</release-item>
|
</release-item>
|
||||||
@@ -7022,6 +7031,11 @@
|
|||||||
<contributor-id type="github">guruguruguru</contributor-id>
|
<contributor-id type="github">guruguruguru</contributor-id>
|
||||||
</contributor>
|
</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 id="hans.jurgen.schonig">
|
||||||
<contributor-name-display>Hans-J&uuml;rgen Sch&ouml;nig</contributor-name-display>
|
<contributor-name-display>Hans-J&uuml;rgen Sch&ouml;nig</contributor-name-display>
|
||||||
</contributor>
|
</contributor>
|
||||||
|
|||||||
+15
-11
@@ -307,18 +307,22 @@ sub stanzaDelete
|
|||||||
"\nHINT: has the pgbackrest stop command been run on this server?", ERROR_FILE_MISSING);
|
"\nHINT: has the pgbackrest stop command been run on this server?", ERROR_FILE_MISSING);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get the master database object and index
|
# If a force has not been issued, then check the database
|
||||||
my ($oDbMaster, $iMasterRemoteIdx) = dbObjectGet({bMasterOnly => true});
|
if (!cfgOption(CFGOPT_FORCE))
|
||||||
|
|
||||||
# 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. " .
|
# Get the master database object and index
|
||||||
"To delete stanza '${strStanza}', shutdown the postmaster for stanza '${strStanza}' and try again, " .
|
my ($oDbMaster, $iMasterRemoteIdx) = dbObjectGet({bMasterOnly => true});
|
||||||
"or use --force.", ERROR_POSTMASTER_RUNNING);
|
|
||||||
|
# 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))
|
||||||
|
{
|
||||||
|
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
|
# Delete the archive info files
|
||||||
|
|||||||
@@ -15514,16 +15514,20 @@ static const EmbeddedModule embeddedModule[] =
|
|||||||
"\"\\nHINT: has the pgbackrest stop command been run on this server?\", ERROR_FILE_MISSING);\n"
|
"\"\\nHINT: has the pgbackrest stop command been run on this server?\", ERROR_FILE_MISSING);\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"\n\n"
|
"\n\n"
|
||||||
|
"if (!cfgOption(CFGOPT_FORCE))\n"
|
||||||
|
"{\n"
|
||||||
|
"\n"
|
||||||
"my ($oDbMaster, $iMasterRemoteIdx) = dbObjectGet({bMasterOnly => true});\n"
|
"my ($oDbMaster, $iMasterRemoteIdx) = dbObjectGet({bMasterOnly => true});\n"
|
||||||
"\n\n"
|
"\n\n"
|
||||||
"my $oStorageDbMaster = storageDb({iRemoteIdx => $iMasterRemoteIdx});\n"
|
"my $oStorageDbMaster = storageDb({iRemoteIdx => $iMasterRemoteIdx});\n"
|
||||||
"\n\n"
|
"\n\n"
|
||||||
"if ($oStorageDbMaster->exists(DB_FILE_POSTMASTERPID) && !cfgOption(CFGOPT_FORCE))\n"
|
"if ($oStorageDbMaster->exists(DB_FILE_POSTMASTERPID))\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
"confess &log(ERROR, DB_FILE_POSTMASTERPID . \" exists - looks like the postmaster is running. \" .\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"
|
"\"To delete stanza '${strStanza}', shutdown the postmaster for stanza '${strStanza}' and try again, \" .\n"
|
||||||
"\"or use --force.\", ERROR_POSTMASTER_RUNNING);\n"
|
"\"or use --force.\", ERROR_POSTMASTER_RUNNING);\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
|
"}\n"
|
||||||
"\n\n"
|
"\n\n"
|
||||||
"$oStorageRepo->remove(STORAGE_REPO_ARCHIVE . '/' . ARCHIVE_INFO_FILE, {bIgnoreMissing => true});\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"
|
"$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]
|
[global:backup]
|
||||||
archive-copy=y
|
archive-copy=y
|
||||||
start-fast=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),
|
'succeed on --no-' . cfgOptionName(CFGOPT_ONLINE) . ' with --' . cfgOptionName(CFGOPT_FORCE),
|
||||||
{strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE) . ' --' . 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user