From 98e436c9e6b1227d848f8740c454b7ab4baef6b3 Mon Sep 17 00:00:00 2001 From: lluuaapp <266615+lluuaapp@users.noreply.github.com> Date: Thu, 1 Dec 2022 18:06:21 +0100 Subject: [PATCH] bareos-fd-postgres: renamed some methods to something more reasonable --- .../python/postgres/BareosFdPluginPostgres.py | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/core/src/plugins/filed/python/postgres/BareosFdPluginPostgres.py b/core/src/plugins/filed/python/postgres/BareosFdPluginPostgres.py index 06f188e2872..c3cc744595c 100644 --- a/core/src/plugins/filed/python/postgres/BareosFdPluginPostgres.py +++ b/core/src/plugins/filed/python/postgres/BareosFdPluginPostgres.py @@ -452,13 +452,19 @@ def restore_object_data(self, ROP): ) return bareosfd.bRC_OK - def __dbConClose(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 closeDbConnection(self): + 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() @@ -475,7 +481,7 @@ def closeDbConnection(self): + "CHECKPOINT LOCATION: %s, " % self.labelItems["CHECKPOINT LOCATION"] + "START WAL LOCATION: %s\n" % self.labelItems["START WAL LOCATION"], ) - self.__dbConClose() + self.close_db_connection() self.PostgressFullBackupRunning = False except Exception as e: bareosfd.JobMessage( @@ -525,12 +531,12 @@ def end_backup_file(self): return bareosfd.bRC_More else: if self.PostgressFullBackupRunning: - self.closeDbConnection() + self.completed_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.__dbConClose() + self.close_db_connection() return bareosfd.bRC_OK def end_backup_job(self): @@ -540,10 +546,10 @@ def end_backup_job(self): especially when job was cancelled """ if self.PostgressFullBackupRunning: - self.closeDbConnection() + self.completed_backup_job_and_close_db() self.PostgressFullBackupRunning = False else: - self.__dbConClose() + self.close_db_connection() return bareosfd.bRC_OK def wait_for_wal_archiving(self, LSN):