diff --git a/packages/helpermodules/system.py b/packages/helpermodules/system.py index 24380d6068..340e10aecd 100644 --- a/packages/helpermodules/system.py +++ b/packages/helpermodules/system.py @@ -76,17 +76,12 @@ def update_ip_address(self) -> None: self.data["ip_address"] = new_ip pub.Pub().pub("openWB/set/system/ip_address", new_ip) - def create_backup_and_send_to_cloud(self): + def thread_backup_and_send_to_cloud(self): def create(): try: - if self.backup_cloud is not None: - backup_filename = self.create_backup() - with open(self._get_parent_file()/'data'/'backup'/backup_filename, 'rb') as f: - data = f.read() - self.backup_cloud.update(backup_filename, data) - log.debug('Nächtliche Sicherung erstellt und hochgeladen.') + self.create_backup_and_send_to_cloud() except Exception as e: - raise e + log.exception(f"Error in cloud backup: {e}") for thread in threading.enumerate(): if thread.name == "cloud backup": @@ -94,6 +89,14 @@ def create(): return threading.Thread(target=create, args=(), name="cloud backup").start() + def create_backup_and_send_to_cloud(self): + if self.backup_cloud is not None: + backup_filename = self.create_backup() + with open(self._get_parent_file()/'data'/'backup'/backup_filename, 'rb') as f: + data = f.read() + self.backup_cloud.update(backup_filename, data) + log.debug('Nächtliche Sicherung erstellt und hochgeladen.') + def create_backup(self) -> str: result = subprocess.run([str(self._get_parent_file() / "runs" / "backup.sh"), "1"], stdout=subprocess.PIPE) if result.returncode == 0: diff --git a/packages/main.py b/packages/main.py index c81183ab87..ed9cf2925b 100755 --- a/packages/main.py +++ b/packages/main.py @@ -145,7 +145,7 @@ def handler_midnight(self): @exit_after(10) def handler_random_nightly(self): try: - data.data.system_data["system"].create_backup_and_send_to_cloud() + data.data.system_data["system"].thread_backup_and_send_to_cloud() except KeyboardInterrupt: log.critical("Ausführung durch exit_after gestoppt: "+traceback.format_exc()) except Exception: diff --git a/packages/modules/backup_clouds/nextcloud/backup_cloud.py b/packages/modules/backup_clouds/nextcloud/backup_cloud.py index ecd15389de..5a8491070f 100644 --- a/packages/modules/backup_clouds/nextcloud/backup_cloud.py +++ b/packages/modules/backup_clouds/nextcloud/backup_cloud.py @@ -27,6 +27,7 @@ def upload_backup(config: NextcloudBackupCloudConfiguration, backup_filename: st headers={'X-Requested-With': 'XMLHttpRequest', }, data=backup_file, auth=(user, '' if config.password is None else config.password), + timeout=5 )