Print summary of recent backups
This commit is contained in:
		
							parent
							
								
									2943a4844f
								
							
						
					
					
						commit
						86daf3ea7f
					
				|  | @ -1,5 +1,6 @@ | ||||||
| from borgmanager.database.object import Repo, Archive, Cache | from borgmanager.database.object import Repo, Archive, Cache | ||||||
| from math import floor, pow, log | from math import floor, pow, log | ||||||
|  | from datetime import datetime, timedelta | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Summary(object): | class Summary(object): | ||||||
|  | @ -26,9 +27,42 @@ class Summary(object): | ||||||
|                              f" ago\n" |                              f" ago\n" | ||||||
|             return_string += f"\t> Un/Compressed size: {self.bytes_to_string(cache.unique_size)}" \ |             return_string += f"\t> Un/Compressed size: {self.bytes_to_string(cache.unique_size)}" \ | ||||||
|                              f"/{self.bytes_to_string(cache.unique_csize)}\n" |                              f"/{self.bytes_to_string(cache.unique_csize)}\n" | ||||||
|  |             return_string += f"\t> {self.get_backup_line(repo.primary_key)}\n" | ||||||
|             return_string += "\n" |             return_string += "\n" | ||||||
|         return return_string.strip() |         return return_string.strip() | ||||||
| 
 | 
 | ||||||
|  |     def get_backup_line(self, repo_id): | ||||||
|  |         units = [] | ||||||
|  |         units.append(['H' if h else '_' for h in self.get_archive_hours(repo_id, 24)]) | ||||||
|  |         units.append(['D' if d else '_' for d in self.get_archive_days(repo_id, 7)]) | ||||||
|  |         units.append(['W' if w else '_' for w in self.get_archive_units(repo_id, 5, 7)]) | ||||||
|  |         units.append(['M' if m else '_' for m in self.get_archive_units(repo_id, 12, 30)]) | ||||||
|  | 
 | ||||||
|  |         return f"[{']['.join([''.join(u) for u in units])}]" | ||||||
|  | 
 | ||||||
|  |     def get_archive_hours(self, repo_id, n=12): | ||||||
|  |         hours = [] | ||||||
|  |         for hours_ago in range(n): | ||||||
|  |             exists = self.db.archive_conn.archive_on_hour(repo_id, datetime.today() - timedelta(hours=hours_ago)) | ||||||
|  |             hours.append(exists) | ||||||
|  |         return hours | ||||||
|  | 
 | ||||||
|  |     def get_archive_days(self, repo_id, n=7): | ||||||
|  |         days = [] | ||||||
|  |         for days_ago in range(n): | ||||||
|  |             exists = self.db.archive_conn.archive_on_date(repo_id, datetime.today() - timedelta(days=days_ago)) | ||||||
|  |             days.append(exists) | ||||||
|  |         return days | ||||||
|  | 
 | ||||||
|  |     def get_archive_units(self, repo_id, n: int, dmult: int): | ||||||
|  |         weeks = [] | ||||||
|  |         for weeks_ago in range(0, n): | ||||||
|  |             last_day = datetime.today() - timedelta(days=weeks_ago * dmult) | ||||||
|  |             first_day = datetime.today() - timedelta(days=(weeks_ago * dmult) + dmult - 1) | ||||||
|  |             exists = self.db.archive_conn.between_dates(repo_id, first_day, last_day) | ||||||
|  |             weeks.append(exists) | ||||||
|  |         return weeks | ||||||
|  | 
 | ||||||
|     @staticmethod |     @staticmethod | ||||||
|     def seconds_to_string(seconds: int, detail='hour', short=False): |     def seconds_to_string(seconds: int, detail='hour', short=False): | ||||||
|         seconds = int(seconds) |         seconds = int(seconds) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user