Back to Blog

Homelab Disaster Recovery: Complete Backup and Restore Guide

Prepare for the worst with a solid disaster recovery plan. Learn backup strategies, testing procedures, and quick restore methods for your self-hosted homelab.

Posted by

Homelab disaster recovery

When Disaster Strikes

Hard drives fail. Power surges happen. Ransomware exists. Without a disaster recovery plan, you could lose years of photos, documents, and configurations in an instant.

The 3-2-1 Rule

  • 3 copies of your data
  • 2 different storage media
  • 1 copy offsite

Automated Docker Backups

#!/bin/bash
# backup-docker.sh

BACKUP_DIR="/backup/docker"
DATE=$(date +%Y%m%d_%H%M%S)

# Stop containers for consistent backup
docker compose stop

# Backup volumes
for volume in $(docker volume ls -q); do
  docker run --rm -v $volume:/data -v $BACKUP_DIR:/backup \
    alpine tar czf /backup/${volume}_$DATE.tar.gz /data
done

# Backup compose files
tar czf $BACKUP_DIR/compose_$DATE.tar.gz ~/homelab/

# Restart containers
docker compose start

# Remove old backups (keep 7 days)
find $BACKUP_DIR -type f -mtime +7 -delete

Offsite Backup with Restic

# Install restic
sudo apt install restic

# Initialize repository (Backblaze B2 example)
export B2_ACCOUNT_ID="your_account_id"
export B2_ACCOUNT_KEY="your_account_key"
restic -r b2:bucket-name:homelab init

# Backup
restic -r b2:bucket-name:homelab backup /backup/docker

# Restore
restic -r b2:bucket-name:homelab restore latest --target /restore

Test Your Backups!

A backup that hasn't been tested is not a backup. Schedule quarterly restore tests to ensure your disaster recovery actually works.

Continue Reading