Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bareos-fd-postgres: properly close database connection #1326

Merged
merged 5 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https:
- ndmp_tape.cc: do not log current rctx->rec in joblog [PR #1324]
- dird: stored: set statistics collection as deprecated [PR #1320]
- webui: switch from mod_php to php-fpm [PR #1287]
- bareos-fd-postgres: properly close database connection [PR #1326]

### Deprecated
- make_catalog_backup.pl is now a shell wrapper script which will be removed in version 23.
Expand Down Expand Up @@ -365,6 +366,7 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https:
[PR #1270]: https://github.com/bareos/bareos/pull/1270
[PR #1271]: https://github.com/bareos/bareos/pull/1271
[PR #1272]: https://github.com/bareos/bareos/pull/1272
[PR #1273]: https://github.com/bareos/bareos/pull/1273
[PR #1275]: https://github.com/bareos/bareos/pull/1275
[PR #1277]: https://github.com/bareos/bareos/pull/1277
[PR #1278]: https://github.com/bareos/bareos/pull/1278
Expand All @@ -374,6 +376,7 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https:
[PR #1283]: https://github.com/bareos/bareos/pull/1283
[PR #1284]: https://github.com/bareos/bareos/pull/1284
[PR #1285]: https://github.com/bareos/bareos/pull/1285
[PR #1287]: https://github.com/bareos/bareos/pull/1287
[PR #1288]: https://github.com/bareos/bareos/pull/1288
[PR #1295]: https://github.com/bareos/bareos/pull/1295
[PR #1296]: https://github.com/bareos/bareos/pull/1296
Expand All @@ -388,5 +391,7 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https:
[PR #1315]: https://github.com/bareos/bareos/pull/1315
[PR #1317]: https://github.com/bareos/bareos/pull/1317
[PR #1318]: https://github.com/bareos/bareos/pull/1318
[PR #1320]: https://github.com/bareos/bareos/pull/1320
[PR #1324]: https://github.com/bareos/bareos/pull/1324
[PR #1326]: https://github.com/bareos/bareos/pull/1326
[unreleased]: https://github.com/bareos/bareos/tree/master
22 changes: 19 additions & 3 deletions core/src/plugins/filed/python/postgres/BareosFdPluginPostgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,19 @@ def restore_object_data(self, ROP):
)
return bareosfd.bRC_OK

def closeDbConnection(self):
def close_db_connection(self):
"""
Make sure the DB connection is closed properly. Will not throw if the connection was already closed.
"""
try:
self.dbCon.close()
except pg8000.exceptions.InterfaceError as e:
pass

def complete_backup_job_and_close_db(self):
"""
Call pg_stop_backup() on PostgreSQL DB to mark the backup job as completed.
"""
# TODO Error Handling
# Get Backup Start Date
self.parseBackupLabelFile()
Expand All @@ -469,6 +481,7 @@ def closeDbConnection(self):
+ "CHECKPOINT LOCATION: %s, " % self.labelItems["CHECKPOINT LOCATION"]
+ "START WAL LOCATION: %s\n" % self.labelItems["START WAL LOCATION"],
)
self.close_db_connection()
self.PostgressFullBackupRunning = False
except Exception as e:
bareosfd.JobMessage(
Expand Down Expand Up @@ -518,11 +531,12 @@ def end_backup_file(self):
return bareosfd.bRC_More
else:
if self.PostgressFullBackupRunning:
self.closeDbConnection()
self.complete_backup_job_and_close_db()
# Now we can also create the Restore object with the right timestamp
self.files_to_backup.append("ROP")
return self.checkForWalFiles()
else:
self.close_db_connection()
return bareosfd.bRC_OK

def end_backup_job(self):
Expand All @@ -532,8 +546,10 @@ def end_backup_job(self):
especially when job was cancelled
"""
if self.PostgressFullBackupRunning:
self.closeDbConnection()
self.complete_backup_job_and_close_db()
self.PostgressFullBackupRunning = False
else:
self.close_db_connection()
return bareosfd.bRC_OK

def wait_for_wal_archiving(self, LSN):
Expand Down