diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a81f771980..38d5bcdac7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. @@ -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 @@ -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 @@ -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 diff --git a/core/src/plugins/filed/python/postgres/BareosFdPluginPostgres.py b/core/src/plugins/filed/python/postgres/BareosFdPluginPostgres.py index acfb9108429..f2f66867b9f 100644 --- a/core/src/plugins/filed/python/postgres/BareosFdPluginPostgres.py +++ b/core/src/plugins/filed/python/postgres/BareosFdPluginPostgres.py @@ -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() @@ -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( @@ -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): @@ -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):