Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions nixos/home/openclaw-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,10 @@ tar -cf - -C "$OC" \
. | tar -xf - -C "$STAGE" || fail "staging copy of $OC failed"

# --- transaction-consistent snapshot of the agent state DB on top ---
if [ -f "$OC/state/openclaw.sqlite" ]; then
mkdir -p "$STAGE/state"
sqlite3 "$OC/state/openclaw.sqlite" ".backup '$STAGE/state/openclaw.sqlite'" ||
fail "sqlite .backup of state/openclaw.sqlite failed"
fi
[ -f "$OC/state/openclaw.sqlite" ] || fail "required state/openclaw.sqlite is missing"
mkdir -p "$STAGE/state"
sqlite3 "$OC/state/openclaw.sqlite" ".backup '$STAGE/state/openclaw.sqlite'" ||
fail "sqlite .backup of state/openclaw.sqlite failed"

# --- journal: window start = min(last successful run, 24h ago) ---
NOW_EPOCH="$(date +%s)"
Expand Down Expand Up @@ -192,6 +191,9 @@ if ! (
import hashlib, json, os, sys
m = json.load(open("manifest.json"))
bad = 0
required = "state/openclaw.sqlite"
if required not in {f["path"] for f in m["files"]} or not os.path.isfile(required):
print("MISSING REQUIRED", required); bad += 1
for f in m["files"]:
p = f["path"]
if not os.path.isfile(p):
Expand Down
34 changes: 34 additions & 0 deletions nixos/home/openclaw-backup.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,40 @@ no_upload() { # $1 scenario name — true when no copyto was attempted
|| ! grep -q '^copyto' "$TMP_ROOT/$1/rclone-calls.log"
}

# Missing source DB must fail without uploading or advancing the marker.
setup_home missing-db
rm "$RUN_HOME/.openclaw/state/openclaw.sqlite"
run_backup missing-db
if [[ "$RC" -ne 0 ]] && grep -q 'required state/openclaw.sqlite is missing' "$TMP_ROOT/missing-db.log" \
&& no_upload missing-db && [[ "$MARKER_AFTER" == "$PRESET" ]]; then
ok "missing-db: failed before upload with marker unchanged"
else
fail "missing-db: expected missing DB failure, no upload and unchanged marker; log: $(cat "$TMP_ROOT/missing-db.log")"
fi

# A successful but broken sqlite snapshot can omit the DB from the manifest;
# archive verification must independently require it.
SNAPBIN="$TMP_ROOT/snapshot-stub-bin"
mkdir -p "$SNAPBIN"
{ printf '#!%s\n' "$BASH"; cat <<'STUB'
dest="${2#.backup }"
dest="${dest#\'}"
dest="${dest%\'}"
rm -f "$dest"
STUB
} >"$SNAPBIN/sqlite3"
chmod +x "$SNAPBIN/sqlite3"
setup_home missing-snapshot
TAR_OVERLAY="$SNAPBIN"
run_backup missing-snapshot
TAR_OVERLAY=""
if [[ "$RC" -ne 0 ]] && grep -q 'MISSING REQUIRED state/openclaw.sqlite' "$TMP_ROOT/missing-snapshot.log" \
&& no_upload missing-snapshot && [[ "$MARKER_AFTER" == "$PRESET" ]]; then
ok "missing-snapshot: verify failed before upload with marker unchanged"
else
fail "missing-snapshot: expected required member failure, no upload and unchanged marker; log: $(cat "$TMP_ROOT/missing-snapshot.log")"
fi

# --- staging source-tar failure fails the run (#1034) ---------------------
setup_home staging-fail
TAR_OVERLAY="$TARBIN"
Expand Down