Skip to content

Commit

Permalink
Merge pull request #1326
Browse files Browse the repository at this point in the history
bareos-fd-postgres: properly close database connection
  • Loading branch information
arogge committed Dec 7, 2022
2 parents 45a35d0 + 5a91e68 commit 91f55eb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,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 @@ -366,6 +367,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 #1276]: https://github.com/bareos/bareos/pull/1276
[PR #1277]: https://github.com/bareos/bareos/pull/1277
Expand All @@ -376,6 +378,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 @@ -390,5 +393,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

0 comments on commit 91f55eb

Please sign in to comment.