Proxmox worker, uptime, backup, tagged deploy
This commit is contained in:
commit
e1c6b46279
10 changed files with 176 additions and 0 deletions
44
scripts/restore.sh
Executable file
44
scripts/restore.sh
Executable file
|
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env bash
|
||||
# Restore a .tgz from backup.sh. Default is --dry-run.
|
||||
set -euo pipefail
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
# shellcheck disable=SC1091
|
||||
. "$ROOT/paths.env"
|
||||
DRY=1
|
||||
ARCHIVE=""
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--apply) DRY=0 ;;
|
||||
--dry-run) DRY=1 ;;
|
||||
--archive) ARCHIVE="${2:-}"; shift ;;
|
||||
*) echo "usage: restore.sh [--dry-run|--apply] [--archive file.tgz]" >&2; exit 1 ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
if [[ -z "$ARCHIVE" ]]; then
|
||||
ARCHIVE="$(ls -1t "$BACKUP_ROOT"/*.tgz 2>/dev/null | head -1 || true)"
|
||||
fi
|
||||
[[ -n "$ARCHIVE" && -f "$ARCHIVE" ]] || { echo "no archive" >&2; exit 1; }
|
||||
echo "archive $ARCHIVE dry=$DRY"
|
||||
TMP="$(mktemp -d)"
|
||||
tar -xzf "$ARCHIVE" -C "$TMP"
|
||||
INNER="$(find "$TMP" -mindepth 1 -maxdepth 1 -type d | head -1)"
|
||||
restore_one() {
|
||||
local from="$1" to="$2"
|
||||
[[ -e "$from" ]] || { echo "skip $from"; return; }
|
||||
echo "would restore $from -> $to"
|
||||
if [[ $DRY -eq 0 ]]; then
|
||||
mkdir -p "$(dirname "$to")"
|
||||
rm -rf "$to"
|
||||
cp -a "$from" "$to"
|
||||
fi
|
||||
}
|
||||
restore_one "$INNER/sqlite/$(basename "$ZAPPIER_DB")" "$ZAPPIER_DB"
|
||||
restore_one "$INNER/iam/$(basename "$IAM_DATA")" "$IAM_DATA"
|
||||
restore_one "$INNER/keep/$(basename "$KEEP_DATA")" "$KEEP_DATA"
|
||||
restore_one "$INNER/fleet-runtime/$(basename "$FLEET_RUNTIME")" "$FLEET_RUNTIME"
|
||||
restore_one "$INNER/nats/$(basename "$NATS_STORE")" "$NATS_STORE"
|
||||
rm -rf "$TMP"
|
||||
if [[ $DRY -eq 1 ]]; then
|
||||
echo "dry-run only. re-run with --apply after stopping keep/fleet/nats consumers."
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue