From 45551a805166bb8fa33a237d491ed1841e4bb672 Mon Sep 17 00:00:00 2001 From: Gardel Date: Fri, 20 Mar 2026 01:28:25 +0800 Subject: [PATCH] fix restic unlock success detection --- scripts/opt/backup-loop.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/scripts/opt/backup-loop.sh b/scripts/opt/backup-loop.sh index a808922..1bb8572 100644 --- a/scripts/opt/backup-loop.sh +++ b/scripts/opt/backup-loop.sh @@ -431,15 +431,21 @@ restic() { } _unlock() { - if ! [ -z "${output=$(command restic list locks 2>&1)}" ];then - log WARN "Confirmed stale lock on repo, unlocking..." - if [[ unlock=$(command restic unlock 2>&1) == *"success"* ]]; then + if output="$(command restic list locks 2>&1)" && [ -n "${output}" ]; then + log WARN "Confirmed stale lock on repo, unlocking..." + if unlock_output="$(command restic unlock 2>&1)"; then + if [ -n "${unlock_output}" ]; then + <<<"${unlock_output}" log INFO + fi log INFO "Successfully unlocked the repo" - else + else + if [ -n "${unlock_output}" ]; then + <<<"${unlock_output}" log ERROR + fi log ERROR "Unable to unlock the repo. Is there another process running?" return 1 - fi - fi + fi + fi } _check() {