Skip to content

Commit

Permalink
Merge pull request #1535 from LKuemmel/fix
Browse files Browse the repository at this point in the history
Error message for cloud backup
  • Loading branch information
LKuemmel authored Apr 10, 2024
2 parents 8e74009 + 04d17f3 commit 0faedaa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
19 changes: 11 additions & 8 deletions packages/helpermodules/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,27 @@ 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":
log.debug("Don't start multiple instances of cloud backup thread.")
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:
Expand Down
2 changes: 1 addition & 1 deletion packages/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions packages/modules/backup_clouds/nextcloud/backup_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)


Expand Down

0 comments on commit 0faedaa

Please sign in to comment.