tools.win_pg_dump_controller
1:a22dd63ba19e Browse Files
* Исправление ошибки в логике работы с резервными копиями второго класса . Добавлено больше информации о состоянии резервных копий второго класса . Не пишем в логи лишние строки во время операций чистки старых логов
win_pg_dump_controller/executor.py win_pg_dump_controller/store_controller.py
1.1 --- a/win_pg_dump_controller/executor.py Sun Jan 30 22:17:39 2022 +0300 1.2 +++ b/win_pg_dump_controller/executor.py Fri Feb 11 23:55:12 2022 +0300 1.3 @@ -19,7 +19,6 @@ 1.4 log_t = log.get_timing() 1.5 log(log_t(f'Начинаем копирование {task.name}')) 1.6 1.7 - 1.8 stor = StoreController(task) 1.9 backup_item = stor.new_item() 1.10 1.11 @@ -56,9 +55,14 @@ 1.12 else: 1.13 stor.add_item(backup_item) 1.14 1.15 - log(log_t('Очистка старых копий')) 1.16 + cleaned = stor.clean(config.teir1_days, config.teir2_copies_interval, config.tier2_store_days) 1.17 1.18 - log(log_t('\n'.join(map(lambda x: f'- {x}', stor.clean(config.teir1_days, config.teir2_copies_interval, 1.19 - config.tier2_store_days))))) 1.20 + if cleaned: 1.21 + log(log_t('Очистка старых копий')) 1.22 + log(log_t('\n'.join(map(lambda x: f'- {x}', cleaned)))) 1.23 + 1.24 + if stor.op_adv_status: 1.25 + log(log_t('Расширенное состояние хранимых копий второго класса')) 1.26 + log(log_t('\n'.join(map(lambda x: f'- {x}', stor.op_adv_status)))) 1.27 1.28 stor.save_index()
2.1 --- a/win_pg_dump_controller/store_controller.py Sun Jan 30 22:17:39 2022 +0300 2.2 +++ b/win_pg_dump_controller/store_controller.py Fri Feb 11 23:55:12 2022 +0300 2.3 @@ -32,6 +32,9 @@ 2.4 2.5 return self._my_path 2.6 2.7 + def __str__(self) -> str: 2.8 + return self.filename 2.9 + 2.10 def get_datetime(self): 2.11 return datetime.fromtimestamp(self.time) 2.12 2.13 @@ -66,6 +69,7 @@ 2.14 self.task = task 2.15 self.index_name = self.get_filename(f'{task.name}.index') 2.16 self.idx: Dict[int, IndexItem] = {} 2.17 + self.op_adv_status = [] 2.18 2.19 if exists(self.index_name): 2.20 self.load_index() 2.21 @@ -87,11 +91,13 @@ 2.22 with open(self.index_name, 'w') as OUT: 2.23 json.dump(list(map(lambda x: x.to_dict(), self.idx.values())), OUT) 2.24 2.25 + def add_op_status(self, msg: str) -> None: 2.26 + self.op_adv_status.append(msg) 2.27 + 2.28 def new_item(self) -> IndexItem: 2.29 return IndexItem.new(self, f'{self.task.name}.backup') 2.30 2.31 def add_item(self, item: IndexItem) -> None: 2.32 - item_path = item.get_path() 2.33 if not item.is_exists(): 2.34 raise StoreError(f'Storing to index file not found: {item.get_path()}') 2.35 2.36 @@ -109,7 +115,7 @@ 2.37 file_remove(item.get_path()) 2.38 2.39 def __iter__(self): 2.40 - for i in sorted(self.idx): 2.41 + for i in sorted(self.idx, reverse=True): 2.42 yield self.idx[i] 2.43 2.44 def clean(self, tier1_days: int, tier2_copies_interval: int, tier2_store_days: int) -> List[str]: 2.45 @@ -134,9 +140,12 @@ 2.46 # хотя бы одну копию. В одной эпохе старший файл вытесняет младший. Из вычислений 2.47 # убираем период tier1 2.48 2.49 - storing_days -= tier1_days 2.50 + storing_days_clean = storing_days - tier1_days 2.51 2.52 - _epoch = divmod(storing_days, tier2_copies_interval)[0] 2.53 + _epoch = divmod(storing_days_clean, tier2_copies_interval)[0] 2.54 + self.add_op_status(f'"{item}": epoch={_epoch} storing_days={storing_days}' 2.55 + f' clean_storing_days={storing_days_clean}') 2.56 + 2.57 if _epoch in tier2_idx: 2.58 to_remove.append(tier2_idx[_epoch]) 2.59