Skip to content

Role Backup

Osotechie edited this page Jun 22, 2026 · 1 revision

Role: Backup

Configures the automated backup system that creates LVM snapshots of Docker persistent data.

What It Does

  1. Installs wakeonlan
  2. Creates backup directory structure (/mnt/backup, /mnt/backup/snapshot, /mnt/backup/remote)
  3. Deploys backup.sh and restore.sh scripts to /config

⚠️ The backup directory structure needs cleaning up after recent changes — see the Roadmap.

  1. Creates a daily cron job at 04:00 UTC

Backup Strategy

The goal is to back up all Docker container persistent data with minimal downtime. The approach uses LVM snapshots:

flowchart LR
    A[04:00 UTC] --> B[Stop containers<br/>~seconds]
    B --> C[Create LVM snapshot]
    C --> D[Restart containers<br/>back online]
    D --> E[Compress snapshot<br/>runs in background]
    E --> F[Cleanup]
Loading

Container downtime is only the few seconds it takes to create the LVM snapshot. The actual tar/compress operation runs against the snapshot mount, not the live filesystem.

How backup.sh Works

Step Action
1 Stop all Docker containers
2 Create LVM snapshot of ubuntu-vg/ubuntu-lv (100G snapshot size)
3 Restart all containers
4 Mount the snapshot to /mnt/backup/snapshot
5 Tar and gzip /docker from the snapshot → /mnt/storage/backups/nas/NAS-Backup.tar.gz
6 Unmount and remove the snapshot

Key Variables in the Script

Variable Value Purpose
LVM Volume Group ubuntu-vg The VG containing the root LV
LVM Logical Volume ubuntu-lv The LV to snapshot
Snapshot Size 100G Space allocated for snapshot COW data
Backup Destination /mnt/storage/backups/nas Where the tar.gz lands
Backup Source /docker What gets backed up (from within the snapshot)

Restore

The restore.sh script handles extracting the backup. See the script at playbooks/roles/owendemooy.nas-backup/files/restore.sh for the current implementation.

What's Backed Up vs What's Rebuilt

Data Method
Docker volumes / persistent data (/docker) LVM snapshot backup (this role) + Crashplan offsite
Important storage content (/mnt/storage) Crashplan offsite
OS configuration, packages, users Rebuilt from code (Ansible)
Docker container definitions Rebuilt from code (nas-containers-as-code)
Secrets Azure KeyVault (never backed up locally)

💡 The philosophy is: code rebuilds the structure, backups restore the state. If the NAS dies, you provision a new one from the repos, then restore the backup to get your data back.

Offsite Backup (Crashplan)

In addition to the local LVM snapshot backup, I run a Crashplan container (managed in nas-containers-as-code) to provide offsite cloud backup of content I care about. This covers:

  • /mnt/storage — important files from the MergerFS pool (media, documents, photos)
  • /mnt/storage/backups/nas — Compressed copy of LVM Snapshot Docker persistent data (container configs, databases, etc.)

This protects against catastrophic failure scenarios (fire, theft, multiple disk failure) where local backups wouldn't survive. The LVM snapshot handles quick day-to-day recovery; SnapRAID handles disk failures, and Crashplan handles the "house burned down" scenario.

Cron Schedule

0 4 * * *  /config/backup.sh |& tee /tmp/backup.log

Runs daily at 04:00 UTC. Output is captured to /tmp/backup.log for debugging.

🔗 LVM snapshots | MergerFS + snapshots considerations | Crashplan

Clone this wiki locally