Writing Skills
writing-skills
效率与协作技能,来自 obra/superpowers,查看原文获取完整用途和操作说明。
headscale-backup【部署与运维】Manage Headscale backups, restores, or migrations with a verified SQLite snapshot and explicit recovery paths before upgrades, host moves, or disaster recovery; do not use for server deployment, routine node management, or PostgreSQL backups.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Headscale state is stored in SQLite (its database), config.yaml, policy.json, and TLS certificates. Regular backups are critical before upgrades, as database corruption or misconfiguration can result in complete loss of node registration and routing state. This skill provides three scripts covering the full lifecycle: backup, restore, and migration.
Before creating an archive or restoring files, confirm the target, scope, and rollback path.
Read-only discovery and --dry-run previews may proceed without confirmation.
A complete backup tarball includes:
config.yaml — Headscale server configurationpolicy.json — ACL policy file (if present)sqlite3 .backup (recommended) — Safe for live databases; uses SQLite online backup API. This is what hs-backup.sh uses.cp) — Requires stopping headscale first to avoid WAL corruption.hs-backup.sh reads the database path and optional policy, TLS, node-key, DERP key, and DERP map paths
from config.yaml. It supports database.sqlite.path, database.path, and the legacy
database_path setting. PostgreSQL configurations are rejected. TLS certificates and keys
are included only when configured explicitly (or found in the configured standard
/etc/headscale locations); the helper does not scan unrelated Let's Encrypt certificates.
The resulting archive contains a manifest with SHA-256 checksums, file modes, and restore
destinations. Restore verifies every declared asset before it asks to overwrite files. It
preserves the recorded destinations by default. Root overrides that would move any asset
are rejected because the config or service may still point at archived paths. A migration
to different paths requires a separate planned config update and validation before restore.
Before the first restore write, confirm the target host and mapped paths, the set of files to replace, and the rollback archive or recovery route. A dry run is read-only and can be used without confirmation.
hs-restore.sh --backup <archive> --dry-run --jsonhs-restore.sh --backup <archive>headscale nodes listThe wrapper stops and restarts an active systemd or SysV service around a restore. For
isolated tests only, set HEADSCALE_SKIP_SERVICE_CONTROL=1; this is intended for disposable
fixtures and does not make a production restore safe to run while Headscale is active.
Restored files keep the ownership of an existing destination; for a new file, the helper
uses the destination directory's owner and group. On a new host, prepare directories with
the ownership expected by the Headscale service before restoring. If a restore fails after
stopping the service, the helper leaves it stopped to avoid running with mixed state.
rsync or scp the backup tarball to the target hostSource and target headscale versions should match exactly. Restoring a database from a different headscale version may cause schema migration failures or data corruption. Check versions with headscale version before migrating.
Set up a daily cron job:
0 2 * * * /path/to/hs-backup.sh --auto --output-dir /backups/headscale/
sqlite3 .backup is safe; cp of the database file while headscale is running will produce a corrupt copy.headscale apikeys create.HEADSCALE_URL — Headscale server URLHEADSCALE_API_KEY — API key for health checks and validationHEADSCALE_CONFIG, HEADSCALE_DATA_DIR, HEADSCALE_CERTS_DIR,
HEADSCALE_CONFIG_DIR, and HEADSCALE_SERVICE override the corresponding script defaults.
For migration, HEADSCALE_REMOTE_RESTORE_SCRIPT names the verified restore helper path
installed on the destination host; the default uses the same path as the local script.
Do not use this skill for deploying or configuring a Headscale server — load headscale-deploy instead, or headscale-node-lifecycle for node management. It covers backup, restore, and migration of an existing installation only.