diff --git a/packages/helpermodules/command.py b/packages/helpermodules/command.py index 345d8bc8d0..ce661b0af6 100644 --- a/packages/helpermodules/command.py +++ b/packages/helpermodules/command.py @@ -871,9 +871,15 @@ def systemFetchVersions(self, connection_id: str, payload: dict) -> None: def createBackup(self, connection_id: str, payload: dict) -> None: pub_user_message(payload, connection_id, "Sicherung wird erstellt...", MessageType.INFO) parent_file = Path(__file__).resolve().parents[2] - result = run_command( - [str(parent_file / "runs" / "backup.sh"), - "1" if "use_extended_filename" in payload["data"] and payload["data"]["use_extended_filename"] else "0"]) + try: + result = run_command([ + str(parent_file / "runs" / "backup.sh"), + "1" if "use_extended_filename" in payload["data"] and payload["data"]["use_extended_filename"] else "0" + ], process_exception=False) + except subprocess.CalledProcessError: + pub_user_message(payload, connection_id, + "Fehler beim Erstellen der Sicherung. Bitte Logdatei prüfen.", MessageType.ERROR) + return file_name = result.rstrip('\n') file_link = "/openWB/data/backup/" + file_name pub_user_message(payload, connection_id, diff --git a/packages/helpermodules/system.py b/packages/helpermodules/system.py index 7b1dd3c727..ce9c667002 100644 --- a/packages/helpermodules/system.py +++ b/packages/helpermodules/system.py @@ -97,7 +97,7 @@ def create_backup_and_send_to_cloud(self): def create_backup(self) -> str: try: - result = run_command([str(self._get_parent_file() / "runs" / "backup.sh"), "1"]) + result = run_command([str(self._get_parent_file() / "runs" / "backup.sh"), "1"], process_exception=False) file_name = result.rstrip('\n') return file_name except subprocess.CalledProcessError as e: diff --git a/runs/backup.sh b/runs/backup.sh index 9e28c7319c..72edb6f370 100755 --- a/runs/backup.sh +++ b/runs/backup.sh @@ -178,9 +178,19 @@ force_mosquitto_write() { collect_git_info() { echo "collecting git information" - git branch --no-color --show-current >"$TEMPDIR/GIT_BRANCH" - git log --pretty='format:%H' -n1 >"$TEMPDIR/GIT_HASH" - echo "branch: $(<"$TEMPDIR/GIT_BRANCH") commit-hash: $(<"$TEMPDIR/GIT_HASH")" + if git branch --no-color --show-current >"$TEMPDIR/GIT_BRANCH"; then + echo "current branch: $(<"$TEMPDIR/GIT_BRANCH")" + else + echo "failed to collect git branch info" + return 1 + fi + if git log --pretty='format:%H' -n1 >"$TEMPDIR/GIT_HASH"; then + echo "current commit hash: $(<"$TEMPDIR/GIT_HASH")" + else + echo "failed to collect git commit hash" + return 1 + fi + return 0 } create_archive() { @@ -277,7 +287,12 @@ create_archive() { generate_filename log_environment remove_old_backups - collect_git_info + if collect_git_info; then + echo "git information collected successfully" + else + echo "error: failed to collect git information" + exit 1 + fi force_mosquitto_write create_archive echo "backup finished"