From 66165196e8eff9d1b9ca9c885f3df256393d0315 Mon Sep 17 00:00:00 2001 From: Paul Water Date: Thu, 13 Jun 2019 10:18:53 +0200 Subject: [PATCH] Log info about number of backups and cloned backups. --- backuppc_clone/DataLayer.py | 36 +++++++++++++++++++++++++++ backuppc_clone/command/AutoCommand.py | 27 ++++++++++++++++++-- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/backuppc_clone/DataLayer.py b/backuppc_clone/DataLayer.py index b29bb28..4883ac4 100644 --- a/backuppc_clone/DataLayer.py +++ b/backuppc_clone/DataLayer.py @@ -631,6 +631,42 @@ def original_backup_truncate(self): """ self.execute_none('delete from BKC_ORIGINAL_BACKUP') + # ------------------------------------------------------------------------------------------------------------------ + def overview_get_stats(self): + """ + Select statistics of the original backups and cloned backups. + + :rtype: dict + """ + sql = """ +select sum(case when cnt1=1 then 1 else 0 end) n_backups +, sum(case when cnt1=1 and cnt2=1 then 1 else 0 end) n_cloned_backups +, sum(case when cnt1=1 and cnt2=0 then 1 else 0 end) n_not_cloned_backups +, sum(case when cnt1=0 and cnt2=1 then 1 else 0 end) n_obsolete_cloned_backups +from +( + select sum(case when src=1 then 1 else 0 end) cnt1 + , sum(case when src=2 then 1 else 0 end) cnt2 + from ( + select bob_host + , bob_number + , 1 src + from BKC_ORIGINAL_BACKUP + + union all + + select hst.hst_name + , bck.bck_number + , 2 src + from BKC_BACKUP bck + join BKC_HOST hst on hst.hst_id = bck.hst_id + ) t + group by bob_host + , bob_number +)""" + + return self.execute_row1(sql) + # ------------------------------------------------------------------------------------------------------------------ def parameter_get_value(self, prm_code): """ diff --git a/backuppc_clone/command/AutoCommand.py b/backuppc_clone/command/AutoCommand.py index 458b168..69f5296 100644 --- a/backuppc_clone/command/AutoCommand.py +++ b/backuppc_clone/command/AutoCommand.py @@ -35,6 +35,29 @@ def __scan_original_backups(self): helper.scan() DataLayer.instance.commit() + # ------------------------------------------------------------------------------------------------------------------ + def __sync_auxiliary_files(self): + """ + Synchronises auxiliary files (i.e. files directly under a host directory but not part of a backup). + """ + self._io.title('Synchronizing Auxiliary Files') + + helper = AuxiliaryFiles(self._io) + helper.synchronize() + + # ------------------------------------------------------------------------------------------------------------------ + def __show_overview_stats(self): + """ + Shows the number of backups, cloned backups, backups to clone, and number of obsolete cloned backups. + """ + stats = DataLayer.instance.overview_get_stats() + + self._io.writeln(' # backups : {}'.format(stats['n_backups'])) + self._io.writeln(' # cloned backups : {}'.format(stats['n_cloned_backups'])) + self._io.writeln(' # backups still to clone : {}'.format(stats['n_not_cloned_backups'])) + self._io.writeln(' # obsolete cloned backups: {}'.format(stats['n_obsolete_cloned_backups'])) + self._io.writeln('') + # ------------------------------------------------------------------------------------------------------------------ def __remove_obsolete_hosts(self): """ @@ -172,6 +195,7 @@ def _handle_command(self): self.__remove_partially_cloned_backups() self.__scan_original_backups() + self.__show_overview_stats() self.__remove_obsolete_hosts() self.__remove_obsolete_backups() @@ -191,7 +215,6 @@ def _handle_command(self): if status != 0: break - helper = AuxiliaryFiles(self._io) - helper.synchronize() + self.__sync_auxiliary_files() # ----------------------------------------------------------------------------------------------------------------------