tools.win_pg_dump_controller

Yohn Y. 2022-02-11 Parent:be791d354d2a Child:a38a008ce3e8

1:a22dd63ba19e Go to Latest

tools.win_pg_dump_controller/win_pg_dump_controller/store_controller.py

* Исправление ошибки в логике работы с резервными копиями второго класса . Добавлено больше информации о состоянии резервных копий второго класса . Не пишем в логи лишние строки во время операций чистки старых логов

History
     1.1 --- a/win_pg_dump_controller/store_controller.py	Sun Jan 30 22:17:39 2022 +0300
     1.2 +++ b/win_pg_dump_controller/store_controller.py	Fri Feb 11 23:55:12 2022 +0300
     1.3 @@ -32,6 +32,9 @@
     1.4  
     1.5          return self._my_path
     1.6  
     1.7 +    def __str__(self) -> str:
     1.8 +        return self.filename
     1.9 +
    1.10      def get_datetime(self):
    1.11          return datetime.fromtimestamp(self.time)
    1.12  
    1.13 @@ -66,6 +69,7 @@
    1.14          self.task = task
    1.15          self.index_name = self.get_filename(f'{task.name}.index')
    1.16          self.idx: Dict[int, IndexItem] = {}
    1.17 +        self.op_adv_status = []
    1.18  
    1.19          if exists(self.index_name):
    1.20              self.load_index()
    1.21 @@ -87,11 +91,13 @@
    1.22          with open(self.index_name, 'w') as OUT:
    1.23              json.dump(list(map(lambda x: x.to_dict(), self.idx.values())), OUT)
    1.24  
    1.25 +    def add_op_status(self, msg: str) -> None:
    1.26 +        self.op_adv_status.append(msg)
    1.27 +
    1.28      def new_item(self) -> IndexItem:
    1.29          return IndexItem.new(self, f'{self.task.name}.backup')
    1.30  
    1.31      def add_item(self, item: IndexItem) -> None:
    1.32 -        item_path = item.get_path()
    1.33          if not item.is_exists():
    1.34              raise StoreError(f'Storing to index file not found: {item.get_path()}')
    1.35  
    1.36 @@ -109,7 +115,7 @@
    1.37              file_remove(item.get_path())
    1.38  
    1.39      def __iter__(self):
    1.40 -        for i in sorted(self.idx):
    1.41 +        for i in sorted(self.idx, reverse=True):
    1.42              yield self.idx[i]
    1.43  
    1.44      def clean(self, tier1_days: int, tier2_copies_interval: int, tier2_store_days: int) -> List[str]:
    1.45 @@ -134,9 +140,12 @@
    1.46                          #        хотя бы одну копию. В одной эпохе старший файл вытесняет младший. Из вычислений
    1.47                          #        убираем период tier1
    1.48  
    1.49 -                        storing_days -= tier1_days
    1.50 +                        storing_days_clean = storing_days - tier1_days
    1.51  
    1.52 -                        _epoch = divmod(storing_days, tier2_copies_interval)[0]
    1.53 +                        _epoch = divmod(storing_days_clean, tier2_copies_interval)[0]
    1.54 +                        self.add_op_status(f'"{item}": epoch={_epoch} storing_days={storing_days}'
    1.55 +                                           f' clean_storing_days={storing_days_clean}')
    1.56 +
    1.57                          if _epoch in tier2_idx:
    1.58                              to_remove.append(tier2_idx[_epoch])
    1.59