style: format deployment helpers
Build web service image / build (push) Successful in 40s

This commit is contained in:
2026-09-12 12:05:24 +08:00
parent 0d29b828bb
commit 97cfba7f01
4 changed files with 121 additions and 47 deletions
+36 -27
View File
@@ -12,31 +12,40 @@ source=$2
target=$3
case "$command" in
backup)
[ -f "$source" ] || { echo "data file does not exist: $source" >&2; exit 1; }
mkdir -p "$target"
name="$(basename "$source").$(date -u +%Y%m%dT%H%M%SZ).manual.json"
temporary="$target/.wxagent-backup-$$.tmp"
trap 'rm -f "$temporary"' EXIT
install -m 600 "$source" "$temporary"
mv -f "$temporary" "$target/$name"
sha256sum "$target/$name"
;;
restore)
[ -f "$source" ] || { echo "backup file does not exist: $source" >&2; exit 1; }
directory=$(dirname "$target")
mkdir -p "$directory"
lock="$target.lock"
exec 9>"$lock"
flock -n 9 || { echo "data file is in use; stop the active control plane first" >&2; exit 1; }
temporary="$directory/.wxagent-restore-$$.tmp"
trap 'rm -f "$temporary"' EXIT
install -m 600 "$source" "$temporary"
python3 -m json.tool "$temporary" >/dev/null
mv -f "$temporary" "$target"
sha256sum "$target"
;;
*)
usage
;;
backup)
[ -f "$source" ] || {
echo "data file does not exist: $source" >&2
exit 1
}
mkdir -p "$target"
name="$(basename "$source").$(date -u +%Y%m%dT%H%M%SZ).manual.json"
temporary="$target/.wxagent-backup-$$.tmp"
trap 'rm -f "$temporary"' EXIT
install -m 600 "$source" "$temporary"
mv -f "$temporary" "$target/$name"
sha256sum "$target/$name"
;;
restore)
[ -f "$source" ] || {
echo "backup file does not exist: $source" >&2
exit 1
}
directory=$(dirname "$target")
mkdir -p "$directory"
lock="$target.lock"
exec 9>"$lock"
flock -n 9 || {
echo "data file is in use; stop the active control plane first" >&2
exit 1
}
temporary="$directory/.wxagent-restore-$$.tmp"
trap 'rm -f "$temporary"' EXIT
install -m 600 "$source" "$temporary"
python3 -m json.tool "$temporary" >/dev/null
mv -f "$temporary" "$target"
sha256sum "$target"
;;
*)
usage
;;
esac