Files
dropshell-templates/tailscale-relay/restore.sh
j 1a61eec6ac
All checks were successful
Test and Publish Templates / test-and-publish (push) Successful in 14s
Add 24 files
2026-02-26 15:04:20 +13:00

27 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# shellcheck disable=SC1091
source "${AGENT_PATH}/common.sh"
_check_required_env_vars "CONTAINER_NAME" "BACKUP_FILE" "TEMP_DIR"
if ! lxc info "${CONTAINER_NAME}" 2>/dev/null | grep -q "Status: RUNNING"; then
_die "Container ${CONTAINER_NAME} must be running for restore. Run install.sh first."
fi
mkdir -p "${TEMP_DIR}/restore"
tar -xzf "${BACKUP_FILE}" -C "${TEMP_DIR}/restore"
echo "Restoring Tailscale state..."
# Stop tailscale before restoring state
lxc exec "${CONTAINER_NAME}" -- systemctl stop tailscaled 2>/dev/null || true
# Push state archive into container and extract
lxc file push "${TEMP_DIR}/restore/tailscale-state.tgz" "${CONTAINER_NAME}/tmp/tailscale-state.tgz" || _die "Failed to push backup to container"
lxc exec "${CONTAINER_NAME}" -- bash -c "rm -rf /var/lib/tailscale/* && tar -xzf /tmp/tailscale-state.tgz -C /var/lib/tailscale" || _die "Failed to extract state"
lxc exec "${CONTAINER_NAME}" -- rm -f /tmp/tailscale-state.tgz
# Restart tailscale
lxc exec "${CONTAINER_NAME}" -- systemctl start tailscaled
echo "Restore completed successfully"