Files
homelab-docs/scripts/verify-vzdump-level2.sh
Andrey 53769e6832 Update architecture and backup documentation to include Healthchecks integration
Add Healthchecks service details to architecture and backup documentation, including its role as a Dead man's switch for backups. Update backup scripts to utilize systemd timers instead of cron for improved scheduling. Enhance network topology documentation to reflect Healthchecks integration in the VPS Miran setup. This update clarifies backup processes and enhances overall system reliability.
2026-02-28 15:43:39 +03:00

89 lines
3.0 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Тест восстановления уровня 2: автотест vzdump CT 107.
# Восстанавливает последний vzdump-lxc-107 в временный CT 999, проверяет запуск, удаляет.
# Запускать на хосте Proxmox под root. Ежемесячно (systemd timer).
# При успехе/ошибке — уведомление в Telegram.
set -e
DUMP_DIR="/mnt/backup/proxmox/dump/dump"
TEST_VMID=999
TEST_IP="192.168.1.199/24"
TEST_GW="192.168.1.1"
STORAGE="local-lvm"
WAIT_START_SEC=60
NOTIFY_SCRIPT="${NOTIFY_SCRIPT:-/root/scripts/notify-telegram.sh}"
if [ "$(id -u)" -ne 0 ]; then
echo "Запускайте под root."
exit 1
fi
# Очистка при выходе (успех или ошибка)
cleanup() {
if pct status "$TEST_VMID" &>/dev/null; then
echo "[verify-vzdump] Останавливаем и удаляем CT $TEST_VMID..."
pct stop "$TEST_VMID" --skiplock 2>/dev/null || true
sleep 2
pct destroy "$TEST_VMID" --purge 1 --force 2>/dev/null || true
fi
}
trap cleanup EXIT INT TERM
notify_ok() {
[ -x "$NOTIFY_SCRIPT" ] && "$NOTIFY_SCRIPT" "✅ Тест vzdump CT 107" "$1" || true
}
notify_err() {
[ -x "$NOTIFY_SCRIPT" ] && "$NOTIFY_SCRIPT" "⚠️ Тест vzdump CT 107" "Ошибка: $1" || true
}
if [ ! -d "$DUMP_DIR" ]; then
notify_err "Каталог $DUMP_DIR не найден."
exit 1
fi
# Последний vzdump-lxc-107
ARCHIVE=$(ls -t "$DUMP_DIR"/vzdump-lxc-107-*.tar.zst 2>/dev/null | head -1)
if [ -z "$ARCHIVE" ] || [ ! -f "$ARCHIVE" ]; then
notify_err "Не найден vzdump-lxc-107-*.tar.zst в $DUMP_DIR"
exit 1
fi
echo "[verify-vzdump] Архив: $ARCHIVE"
# Убедиться, что CT 999 не существует (остаток от прошлого запуска)
if pct status "$TEST_VMID" &>/dev/null; then
pct destroy "$TEST_VMID" --purge 1 --force 2>/dev/null || true
sleep 2
fi
echo "[verify-vzdump] Создаём CT $TEST_VMID из архива..."
if ! pct create "$TEST_VMID" "$ARCHIVE" --restore 1 --storage "$STORAGE" 2>&1; then
notify_err "pct create не удался."
exit 1
fi
# Другой IP, чтобы не конфликтовать с оригиналом 107
echo "[verify-vzdump] Настраиваем сеть (IP $TEST_IP)..."
pct set "$TEST_VMID" --net0 "name=eth0,bridge=vmbr0,gw=$TEST_GW,ip=$TEST_IP,type=veth"
echo "[verify-vzdump] Запускаем CT $TEST_VMID..."
if ! pct start "$TEST_VMID" 2>&1; then
notify_err "pct start не удался."
exit 1
fi
echo "[verify-vzdump] Ожидание $WAIT_START_SEC сек..."
sleep "$WAIT_START_SEC"
STATUS=$(pct exec "$TEST_VMID" -- systemctl is-system-running 2>/dev/null || echo "unknown")
if [ "$STATUS" != "running" ]; then
notify_err "systemctl is-system-running вернул: $STATUS (ожидалось running)"
exit 1
fi
echo "[verify-vzdump] CT 999 запущен, system running. Тест пройден."
notify_ok "OK"
exit 0