Skip to content

Commit

Permalink
Log info about number of backups and cloned backups.
Browse files Browse the repository at this point in the history
  • Loading branch information
prwater committed Jun 13, 2019
1 parent 283e732 commit 6616519
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
36 changes: 36 additions & 0 deletions backuppc_clone/DataLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
27 changes: 25 additions & 2 deletions backuppc_clone/command/AutoCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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()

Expand All @@ -191,7 +215,6 @@ def _handle_command(self):
if status != 0:
break

helper = AuxiliaryFiles(self._io)
helper.synchronize()
self.__sync_auxiliary_files()

# ----------------------------------------------------------------------------------------------------------------------

0 comments on commit 6616519

Please sign in to comment.