diff --git a/app/classes/shared/helpers.py b/app/classes/shared/helpers.py index 8668213d..adaff61e 100644 --- a/app/classes/shared/helpers.py +++ b/app/classes/shared/helpers.py @@ -426,15 +426,27 @@ class Helpers: @staticmethod def calc_percent(source_path, dest_path): + #calculates percentable of zip from drive. Not with compression. For backups and support logs source_size = 0 + files_count = 0 for path, _dirs, files in os.walk(source_path): for f in files: fp = os.path.join(path, f) source_size += os.stat(fp).st_size + files_count += 1 dest_size = os.path.getsize(str(dest_path)) percent = round((dest_size/source_size) * 100) - print("per", percent) - return percent + if percent >= 0: + results = { + "percent": percent, + "total_files": files_count + } + else: + results = { + "percent": 0, + "total_files": 0 + } + return results @staticmethod def check_file_exists(path: str): diff --git a/app/classes/shared/server.py b/app/classes/shared/server.py index 115a213f..1f47157b 100644 --- a/app/classes/shared/server.py +++ b/app/classes/shared/server.py @@ -594,6 +594,7 @@ class Server: if not self.is_backingup: try: backup_thread.start() + self.is_backingup = True except Exception as ex: logger.error(f"Failed to start backup: {ex}") return False @@ -603,13 +604,24 @@ class Server: logger.info(f"Backup Thread started for server {self.settings['server_name']}.") def a_backup_server(self): + if len(websocket_helper.clients) > 0: + websocket_helper.broadcast_page_params( + '/panel/server_detail', + { + 'id': str(self.server_id) + }, + 'backup_reload', + { + "percent": 0, + "total_files": 0 + } + ) logger.info(f"Starting server {self.name} (ID {self.server_id}) backup") server_users = server_permissions.get_server_user_list(self.server_id) for user in server_users: websocket_helper.broadcast_user(user, 'notification', translation.translate('notify', 'backupStarted', users_helper.get_user_lang_by_id(user)).format(self.name)) time.sleep(3) - self.is_backingup = True conf = management_helper.get_backup_config(self.server_id) try: backup_filename = f"{self.settings['backup_path']}/{datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}" @@ -666,7 +678,26 @@ class Server: return def backup_status(self, source_path, dest_path): - helper.calc_percent(source_path, dest_path) + results = helper.calc_percent(source_path, dest_path) + self.backup_stats = results + if len(websocket_helper.clients) > 0: + websocket_helper.broadcast_page_params( + '/panel/server_detail', + { + 'id': str(self.server_id) + }, + 'backup_status', + results + ) + + def send_backup_status(self): + try: + return self.backup_stats + except: + return { + 'percent': 0, + 'total_files': 0 + } def list_backups(self): if self.settings['backup_path']: diff --git a/app/frontend/templates/panel/server_backup.html b/app/frontend/templates/panel/server_backup.html index b641cb3b..a30fb803 100644 --- a/app/frontend/templates/panel/server_backup.html +++ b/app/frontend/templates/panel/server_backup.html @@ -42,9 +42,20 @@ -
Backing up {{data['backup_stats']['total_files']}} Files
+ {% end %} + +