Build Your First AI Homelab

Reproducible Homelab Recovery: Declarative Config and Fast Rebuilds

An emergency disaster recovery and business continuity engineering runbook for AI homelabs: enforce strict tripartite separation of code, state, and neural weights; version declarative infrastructure in Git; automate encrypted NAS backups with rsync; verify GGUF SHA256 checksums; and execute a sub-15-minute cold-start rebuild from bare metal to serving queries.

Quick Answer & Decision Summary

An emergency disaster recovery and business continuity engineering runbook for AI homelabs: enforce strict tripartite separation of code, state, and neural weights; version declarative infrastructure in Git; automate encrypted NAS backups with rsync; verify GGUF SHA256 checksums; and execute a sub-15-minute cold-start rebuild from bare metal to serving queries.

Scope & Audience: DevOps engineers, systems architects, homelab operators, and privacy engineers building resilient local infrastructure. ·

Who this is for

DevOps engineers, systems architects, homelab operators, and privacy engineers building resilient local infrastructure.

Learning objectives

  • Implement the zero-panic tripartite architecture separating code (Git), state (encrypted keys/DBs), and cache (model weights).
  • Structure an immutable, version-controlled Infrastructure-as-Code (IaC) repository for multi-container AI deployments.
  • Deploy an automated, cron-driven rsync backup pipeline synchronizing configurations to network-attached storage (NAS).
  • Establish a deterministic sub-15-minute cold-start disaster recovery runbook restoring the host from bare metal.
  • Verify neural tensor data integrity using SHA256 checksum manifests to prevent silent corruption and segmentation faults.
  • Conduct regular chaos recovery drills that validate backup restorability and benchmark Recovery Time Objective (RTO).

The Zero-Panic Architecture: Tripartite Separation of Code, State and Weights

The ultimate test of any infrastructure is not how elegantly it runs during peaceful steady-state operation, but how quickly and predictably it can be rebuilt from absolute ruins following a catastrophic hardware failure. In a home laboratory, failure modes are frequent and unavoidable: a power surge destroys a motherboard, an NVMe SSD exhausts its write cycles and drops into read-only mode, or an administrative error corrupts the root filesystem.

When disaster strikes, unprepared administrators experience paralyzing panic. They struggle to remember manual kernel modifications, search through browser histories for forgotten Docker run commands, and realize too late that private SSL certificates and customized system prompts were stored only inside an ephemeral container overlay that is now unrecoverable.

To achieve true resilience, you must engineer your AI homelab according to the Zero-Panic Tripartite Separation Architecture. This model divides all server assets into three strictly isolated, mutually independent categories:

Category 1: Code and Declarative Configuration (Stateless & Version-Controlled). This includes your Docker Compose manifests, Caddyfiles, Prometheus scraping configurations, alert definitions, custom Modelfiles, and host setup scripts (setup-host.sh). This entire layer contains zero private secrets or dynamic state. It resides exclusively inside a private Git repository and is mirrored across local and remote remotes. If the host burns, re-cloning this repository instantly reconstructs the complete architectural blueprint.

Category 2: State and Cryptographic Identity (Volatile, Stateful & Encrypted). This category encompasses your Caddy internal TLS private keys, Tailscale machine identity tokens, Open WebUI SQLite databases, API authorization hashes, and environment variables (.env). While small in size (typically under 250 megabytes), losing this data breaks client access tokens, erases user conversation histories, and revokes SSL trust. This layer must be automatically encrypted and backed up daily to off-host storage.

Category 3: Model Weights and Execution Cache (Bulk, Reconstructible & Ephemeral). Large language model GGUF weights, Hugging Face cache directories, and temporary token buffers consume tens to hundreds of gigabytes of disk space. Backing up 200 gigabytes of static model weights over home Wi-Fi or residential broadband is an operational anti-pattern. Because model weights are immutable and re-downloadable from upstream registries, they must be stored on dedicated mount points, backed up selectively to local Network-Attached Storage (NAS), and strictly excluded from cloud backups.

To formalize this tripartite separation within your homelab operational runbooks, maintain the following Asset Classification Matrix:

  1. Code & Manifests (Tier 1): Dockerfiles, Compose files, Caddyfiles, Prometheus configs. Stored in Git. Recovery time: under 60 seconds via git clone. Zero confidential data.
  1. State & Cryptographic Material (Tier 2): .env, SQLite DBs, Caddy TLS private keys, Tailscale machine keys. Stored on local NVMe, encrypted via AES-256 GPG, and synced daily to NAS. Recovery time: under 2 minutes via SCP.
  1. Neural Tensor Weights (Tier 3): GGUF binary files (llama-3-8b.Q4_K_M.gguf). Stored in /opt/ai-homelab/models. Mirrored locally on 2.5GbE NAS share or re-pulled from Hugging Face / Ollama. Recovery time: 2 to 5 minutes over LAN.

Infrastructure-as-Code: The Production Homelab Repository Layout

To operationalize tripartite separation, consolidate all configurations into a single, version-controlled Infrastructure-as-Code (IaC) Git repository named ai-homelab. Never leave configuration files scattered randomly across /etc, /var, or user home directories.

Structure your repository according to the standardized RIGLYX directory specification:

TEXT
/opt/ai-homelab/
├── .git/
├── .gitignore
├── .env.example
├── docker-compose.yml
├── docker-compose.monitoring.yml
├── configs/
│   ├── caddy/
│   │   └── Caddyfile
│   ├── monitoring/
│   │   ├── prometheus.yml
│   │   └── alerts.yml
│   └── modelfiles/
│       └── Llama3-Homelab.Modelfile
├── scripts/
│   ├── setup-host.sh
│   ├── benchmark.py
│   ├── backup-nas.sh
│   └── restore-homelab.sh
└── checksums/
    └── models.sha256

Notice .env.example. This file documents every required environment variable (OLLAMA_KEEP_ALIVE, GRAFANA_PASSWORD, BASIC_AUTH_HASH) without committing plaintext secrets to Git history. The production .env file is excluded via .gitignore:

GITIGNORE
# /opt/ai-homelab/.gitignore
.env
*.log
data/
models/
webui-data/

Commit and push this repository to your self-hosted Git server (such as Gitea) or a private GitHub repository: git init && git add . && git commit -m "feat: initial declarative AI homelab configuration". Your entire server architecture is now an immutable, software-defined entity.

Automated Backup Pipeline: Encrypted rsync and NAS Synchronization

Backups that rely on human memory fail 100% of the time. You must automate daily configuration and state synchronization using a hardened shell script executed via systemd timers or standard cron.

rsync provides the ideal tool for homelab synchronization: it transfers only changed file blocks, preserves filesystem permissions, operates securely over SSH, and supports granular exclusion filters. Create the automated backup script at /opt/ai-homelab/scripts/backup-nas.sh:

BASH
#!/usr/bin/env bash
# /opt/ai-homelab/scripts/backup-nas.sh
# RIGLYX Automated NAS Backup & State Synchronization
set -euo pipefail

BACKUP_DATE=$(date +%Y%m%d_%H%M%S)
NAS_TARGET="backup-operator@192.168.1.100:/volume1/homelab-backups/ai-host"
LOCAL_ROOT="/opt/ai-homelab"

echo "==> [1/3] Dumping Application Databases..."
# Gracefully export SQLite databases without locking tables
if [ -f "$LOCAL_ROOT/data/webui/webui.db" ]; then
  sqlite3 "$LOCAL_ROOT/data/webui/webui.db" ".backup '$LOCAL_ROOT/data/webui_backup.db'"
fi

echo "==> [2/3] Synchronizing Declarative Configs and Secrets to NAS..."
rsync -avz --delete \
  --exclude="models/" \
  --exclude="data/prometheus/" \
  --exclude="*.log" \
  --exclude=".git/" \
  -e "ssh -i /root/.ssh/id_ed25519_nas" \
  "$LOCAL_ROOT/" "$NAS_TARGET/configs-current/"

echo "==> [3/3] Creating Timestamped State Snapshot Archive..."
tar -czf "/tmp/ai-state-$BACKUP_DATE.tar.gz" \
  -C "$LOCAL_ROOT" \
  configs/ .env data/webui_backup.db

scp -i /root/.ssh/id_ed25519_nas \
  "/tmp/ai-state-$BACKUP_DATE.tar.gz" "$NAS_TARGET/snapshots/"
rm -f "/tmp/ai-state-$BACKUP_DATE.tar.gz"

echo "==> Backup completed successfully at $(date)!"

Notice how large data directories are handled: --exclude="models/" and --exclude="data/prometheus/" skip multi-gigabyte neural weights and ephemeral time-series data, allowing the backup to complete in under 5 seconds over the local network.

Schedule this script to execute automatically every morning at 03:00 AM using crontab: (crontab -l 2>/dev/null; echo "0 3 * /opt/ai-homelab/scripts/backup-nas.sh >> /var/log/ai-backup.log 2>&1") | crontab -.

For offsite or cloud-mirrored backups, plain rsync is insufficient because backup targets must be protected with client-side zero-knowledge encryption and content-defined chunk deduplication. BorgBackup (borg) or Restic provide enterprise-grade cryptographic encapsulation for homelab state.

Initialize and execute a BorgBackup repository targeting encrypted remote storage:

BASH
# 1. Initialize an authenticated, encrypted Borg repository
export BORG_REPO="ssh://backup-operator@offsite-storage.local:2222/volume1/borg-repo"
export BORG_PASSPHRASE="YourUltraSecureBorgPassphrase2026"
borg init --encryption=repokey-blake2

# 2. Execute deduplicated, encrypted backup archive
borg create --compression zstd,6 --stats --progress \
  ::"ai-homelab-{now:%Y-%m-%d_%H%M%S}" \
  /opt/ai-homelab/configs \
  /opt/ai-homelab/.env \
  /opt/ai-homelab/data/webui_backup.db

# 3. Apply automated retention pruning policy
borg prune --keep-daily=7 --keep-weekly=4 --keep-monthly=6

Notice the cryptographic architecture: the backup archive is compressed with zstd, encrypted client-side using authenticated BLAKE2 and ChaCha20-Poly1305, and deduplicated across consecutive snapshots. Even if an attacker gains physical control over your remote NAS or cloud bucket, your API tokens and system prompts remain computationally impossible to decrypt.

To add an additional layer of defensive isolation for standalone secret files, encrypt your .env file with GPG using symmetric AES-256 before distributing backups offsite:

BASH
# Encrypt .env configuration using symmetric AES-256
gpg --symmetric --cipher-algo AES256 --batch --yes \
  --passphrase "$BACKUP_SECRET_PASSPHRASE" \
  -o /opt/ai-homelab/.env.gpg /opt/ai-homelab/.env

Furthermore, to prevent automated backup execution logs from consuming disk space, configure log rotation by creating /etc/logrotate.d/ai-backup:

TEXT
/var/log/ai-backup.log {
    weekly
    rotate 4
    compress
    missingok
    notifempty
}

The 15-Minute Cold-Start Disaster Recovery Runbook: Bare-Metal to Serving

Assume the worst-case scenario: your server’s primary drive has suffered catastrophic NAND flash failure. You have unboxed a brand-new replacement NVMe SSD (or an entirely new Mini PC). The following step-by-step disaster recovery runbook restores your complete AI homelab from bare metal to serving verified inference queries in under 15 minutes.

Minute 00:00 to 04:00 — Minimal OS Bootstrap and Network Join. Boot the host from a prepared Ubuntu Server 24.04 LTS USB drive. Install minimal headless server with standard partition schemes. Configure hostname and static IP. Connect administrative SSH.

Minute 04:00 to 07:00 — Execute Host Hardware Hardening. Clone or download your initialization script and execute: curl -fsSL https://raw.githubusercontent.com/your-org/ai-homelab/main/scripts/setup-host.sh | sudo bash. In three minutes, Docker CE is installed, sysctl virtual memory parameters are tuned, systemd cgroup slices are established, and CPU performance governors are locked.

Minute 07:00 to 09:00 — Restore IaC Repository and Secrets. Clone your Git repository and restore state files from your NAS:

BASH
# Clone base repository
sudo git clone https://github.com/your-org/ai-homelab.git /opt/ai-homelab
cd /opt/ai-homelab

# Restore latest encrypted state snapshot from NAS
scp backup-operator@192.168.1.100:/volume1/homelab-backups/ai-host/configs-current/.env ./
scp backup-operator@192.168.1.100:/volume1/homelab-backups/ai-host/configs-current/data/webui_backup.db data/webui/webui.db

Minute 09:00 to 12:00 — Launch Containers and Download Model Weights. Launch the Docker Compose services: docker compose up -d && docker compose -f docker-compose.monitoring.yml up -d. Pull your pinned base model directly or restore cached GGUFs from your NAS:

BASH
# Restore pre-quantized model weights from local high-speed NAS (1-2 minutes over 2.5GbE)
rsync -avh --progress backup-operator@192.168.1.100:/volume1/model-cache/ /opt/ai-homelab/models/

# Re-compile custom Modelfile
docker exec -i homelab-ollama ollama create riglyx-llama3:8b -f /dev/stdin < configs/modelfiles/Llama3-Homelab.Modelfile

Minute 12:00 to 15:00 — Acceptance Verification. Verify service availability via Caddy: curl -k -u riglyx_operator:YourSecurePassword https://127.0.0.1:8443/api/tags. Execute the automated benchmark: python3 scripts/benchmark.py. At minute 14:30, your AI homelab is fully operational, verified, and serving queries identical to its pre-crash state.

To compress this entire recovery sequence into a single automated execution, save the production restore-homelab.sh shell script to your NAS backup share alongside your archives:

BASH
#!/usr/bin/env bash
# restore-homelab.sh - RIGLYX Automated Cold-Start Bare-Metal Recovery
set -euo pipefail

NAS_IP="192.168.1.100"
NAS_SHARE="/volume1/homelab-backups/ai-host"
INSTALL_DIR="/opt/ai-homelab"

echo "==> [1/5] Bootstrapping Base Directory..."
sudo mkdir -p "$INSTALL_DIR"
sudo chown "$USER:$USER" "$INSTALL_DIR"

echo "==> [2/5] Restoring IaC Repository from Git..."
git clone https://github.com/your-org/ai-homelab.git "$INSTALL_DIR"
cd "$INSTALL_DIR"

echo "==> [3/5] Restoring Secrets and State from NAS..."
scp "backup-operator@$NAS_IP:$NAS_SHARE/configs-current/.env" ./
scp "backup-operator@$NAS_IP:$NAS_SHARE/configs-current/data/webui_backup.db" data/webui/webui.db

echo "==> [4/5] Launching Containerized Services..."
docker compose up -d
docker compose -f docker-compose.monitoring.yml up -d

echo "==> [5/5] Rebuilding Local Modelfiles..."
sleep 10
docker exec -i homelab-ollama ollama create riglyx-llama3:8b -f /dev/stdin < configs/modelfiles/Llama3-Homelab.Modelfile

echo "==> RECOVERY COMPLETE! Running Verification Benchmark..."
python3 scripts/benchmark.py

Executing curl -fsSL http://192.168.1.100/restore-homelab.sh | bash transforms a brand-new, freshly booted Linux machine into a fully functional local AI homelab with zero manual intervention required.

If restoring over a slower 1GbE network link or Wi-Fi, you can prioritize starting the inference engine with an ultra-compact model (such as a 1.5B or 3B model occupying under 1.2 GB) so that local API services resume functioning in under 3 minutes, while heavier 8B or 14B weights continue downloading asynchronously in the background.

Data Integrity Verification: Checksum Manifests and Model Weight Validation

In computing, silent data corruption (bit rot) is a pernicious failure mode. A flipped bit in an executable binary causes an immediate segmentation fault or crash. In a large language model, however, a flipped bit inside a 5-gigabyte floating-point tensor can cause silent, undetectable cognitive decay: the model continues generating grammatically valid text, but its logical reasoning, code syntax, and factual accuracy silently degrade.

To guarantee that restored or downloaded model weights are byte-for-byte identical to their published upstream hashes, you must maintain a cryptographic SHA256 checksum manifest inside your repository at /opt/ai-homelab/checksums/models.sha256:

TEXT
# /opt/ai-homelab/checksums/models.sha256
# Cryptographic SHA256 Integrity Verification Manifest
7a9b1c3d4e5f60718293a4b5c6d7e8f90123456789abcdef0123456789abcdef  llama-3.1-8b-instruct.Q4_K_M.gguf
9f8e7d6c5b4a302110fedcba9876543210abcdef0123456789abcdef01234567  mistral-7b-instruct-v0.3.Q5_K_M.gguf

Automate checksum validation using an executable verification script at /opt/ai-homelab/scripts/verify-integrity.sh:

BASH
#!/usr/bin/env bash
# /opt/ai-homelab/scripts/verify-integrity.sh
# RIGLYX Model Tensor Integrity & Bit-Rot Verification
set -euo pipefail

CHECKSUM_FILE="/opt/ai-homelab/checksums/models.sha256"
MODELS_DIR="/opt/ai-homelab/models"

echo "==> Auditing Neural Model Tensor Cryptographic Integrity..."
cd "$MODELS_DIR"

if sha256sum -c "$CHECKSUM_FILE"; then
  echo "==> INTEGRITY VERIFIED: All model weights are byte-exact and bit-rot free!"
else
  echo "CRITICAL FAILURE: Model weight checksum mismatch detected!" >&2
  exit 1
fi

Execute this verification script immediately following any backup restoration, NAS synchronization, or model download. By validating mathematical integrity before loading weights into memory, you eliminate the risk of running corrupted models.

For homelab hosts equipped with enterprise NVMe storage or multi-drive RAID setups, operating filesystems with built-in data scrubbing and cryptographic integrity—such as OpenZFS or Btrfs—provides continuous protection against silent bit rot. ZFS utilizes 256-bit Fletcher4 or SHA256 checksums on every single disk block. When a model file is read into memory, ZFS automatically recalculates the block checksum on-the-fly.

If a hardware bit-flip is detected and redundant storage (such as a ZFS mirror) is present, ZFS repairs the corrupted block silently in real time using the parity data before delivering the clean tensor to the userland inference runtime. Schedule a monthly ZFS filesystem scrub: sudo zpool scrub rpool to actively scan and repair every stored neural weight.

Chaos Recovery Drills: Validating the Backup Lifecycle

Untested backups are merely theoretical wishes. The only way to know with absolute certainty that your backup pipeline works is to periodically execute an unannounced chaos recovery drill.

Schedule a Disaster Recovery Exercise twice annually. During the exercise, follow this strict protocol:

  1. Simulate Host Loss: Power down your primary homelab server completely. Disconnect its storage drives.
  1. Target Secondary Hardware: Boot a secondary laptop, spare Mini PC, or temporary virtual machine.
  1. Execute Cold-Start Runbook: Using only the documentation stored in your Git repository and backups on your NAS, execute the 15-Minute Cold-Start Runbook from start to finish.
  1. Measure Recovery Metrics: Record your Recovery Time Objective (RTO - total elapsed time until the first query succeeds) and Recovery Point Objective (RPO - age of the oldest restored conversation data). Your target RTO is under 15 minutes; your target RPO is under 24 hours.
  1. Continuous Improvement: Document any forgotten dependencies, outdated passwords, or missing environment variables discovered during the drill. Update your setup-host.sh and docker-compose.yml immediately.

To automate your disaster drill directly on your running server without destroying data, execute this safe, non-destructive chaos drill script at /opt/ai-homelab/scripts/chaos-drill.sh:

BASH
#!/usr/bin/env bash
# /opt/ai-homelab/scripts/chaos-drill.sh
# Safe, non-destructive disaster recovery simulation
set -euo pipefail

echo "==> SIMULATING CATASTROPHIC OUTAGE: Tearing down all running services..."
cd /opt/ai-homelab
docker compose down -v
docker compose -f docker-compose.monitoring.yml down -v

echo "==> SIMULATING ROOT CORRUPTION: Stashing production configurations..."
mv .env /tmp/.env.stash
mv configs /tmp/configs.stash

T_START=$(date +%s)
echo "==> DISASTER SIMULATION ACTIVE! Initiating Cold-Start Rebuild Protocol..."

# 1. Restore configs from NAS
rsync -avz backup-operator@192.168.1.100:/volume1/homelab-backups/ai-host/configs-current/configs/ ./configs/
cp /tmp/.env.stash ./.env

# 2. Launch production services
docker compose up -d

# 3. Poll for service health
until curl -s http://127.0.0.1:11434/api/tags > /dev/null; do
  echo "Waiting for inference runtime to report healthy..."
  sleep 2
done

T_END=$(date +%s)
ELAPSED=$((T_END - T_START))

echo "==> CHAOS DRILL COMPLETED SUCCESSFULLY in ${ELAPSED} seconds!"
# Cleanup temporary stashes
rm -rf /tmp/.env.stash /tmp/configs.stash

By transforming disaster recovery from an emergency panic into an automated, practiced engineering routine, you achieve total operational independence. Your AI homelab is resilient, deterministic, self-healing, and completely under your sovereign control.

To certify that your AI homelab meets sovereign resilience standards, complete the following 10-Point Disaster Recovery Audit:

  1. UEFI Power-Loss Auto-Start: Verify in BIOS that "Restore on AC Power Loss" is set to "Power On", ensuring that the server automatically reboots following household power restoration.
  1. Headless Boot Integrity: Confirm that the motherboard boots cleanly without an attached physical HDMI/DisplayPort display or dummy plug.
  1. Network Persistence: Confirm that static IP addresses or DHCP reservations are documented inside your IaC repository.
  1. Decoupled Mount Points: Confirm that /opt/ai-homelab/models resides on a dedicated partition or independent drive to prevent model weight exhaustion from crashing the OS root filesystem.
  1. Automated Daily Sync: Verify that the daily rsync backup runs and that snapshot archives appear on the NAS without errors.
  1. Offsite Secret Redundancy: Ensure that the symmetric GPG recovery passphrase is stored in an encrypted password manager (such as Bitwarden or 1Password).
  1. Model Integrity Manifest: Ensure that every production GGUF weight is recorded with a verified SHA256 checksum inside models.sha256.
  1. Zero Hardcoded Secrets in Git: Scan your Git repository history using git log -p to verify that no plaintext passwords, tokens, or private certificates exist in code commits.
  1. Tested RTO Under 15 Minutes: Verify through active chaos drills that complete rebuild duration from bare-metal boots remains strictly beneath the 15-minute SLA.
  1. Documentation Integrity: Ensure that the 15-Minute Recovery Runbook is printed or cached offline on an independent laptop so it remains accessible during an active infrastructure failure.

Technical Glossary

SODIMM
Small Outline Dual In-Line Memory Module — compact modular RAM form factor used in laptops and most socketed Mini PCs.
NPU
Neural Processing Unit — dedicated silicon block optimized for low-power, fixed-precision AI inference.
UCFF
Ultra-Compact Form Factor — roughly 4x4 inch (10x10 cm) Mini PC motherboard and chassis class (typically 0.5–1.5 L).
PCIe lane
A point-to-point serial data link (Tx/Rx pair) connecting the CPU to NVMe SSDs, NICs, or expansion cards.
ECC
Error-Correcting Code memory — detects and corrects single-bit memory errors for unattended server stability.
UEFI
Unified Extensible Firmware Interface — modern system firmware controlling boot, power limits, fan curves, and auto power-on.
NAND
Non-volatile flash memory cells used inside SSDs; endurance and sustained write behavior depend on controller and cache.

Sources

Claim-to-source map

Related technologies

Next Step
Mini PC Buying Checklist
Read next guide →

Continue learning

View Structured Data Asset (JSON) · DA-RIG-ART-014 · Central Intelligence Hub Ready