← All articlesCloud Infrastructure

Backup Strategies: The 3-2-1 Rule with Restic and Rclone

Implement bulletproof backups using the 3-2-1 rule. Covers restic for incremental encrypted backups, rclone for cloud sync, verification testing, and...

Y
Yash Pritwani
14 min read

The 3-2-1 Backup Rule

Every backup strategy should follow the 3-2-1 rule:

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

<div style="margin:2.5rem auto;max-width:600px;width:100%;text-align:center;"><svg viewBox="0 0 600 200" xmlns="http://www.w3.org/2000/svg" style="width:100%;height:auto;"><rect width="600" height="200" rx="12" fill="#1a1a2e"/><rect x="60" y="30" width="140" height="140" rx="6" fill="none" stroke="#e2e8f0" stroke-width="1.5"/><text x="130" y="24" text-anchor="middle" fill="#94a3b8" font-size="10" font-family="system-ui">Production</text><rect x="70" y="40" width="120" height="22" rx="3" fill="#6366f1" opacity="0.8"/><circle cx="82" cy="51" r="3" fill="#2dd4bf"/><text x="130" y="55" text-anchor="middle" fill="#ffffff" font-size="9" font-family="system-ui">Web Server</text><rect x="70" y="68" width="120" height="22" rx="3" fill="#6366f1" opacity="0.8"/><circle cx="82" cy="79" r="3" fill="#2dd4bf"/><text x="130" y="83" text-anchor="middle" fill="#ffffff" font-size="9" font-family="system-ui">App Server</text><rect x="70" y="96" width="120" height="22" rx="3" fill="#a855f7" opacity="0.8"/><circle cx="82" cy="107" r="3" fill="#2dd4bf"/><text x="130" y="111" text-anchor="middle" fill="#ffffff" font-size="9" font-family="system-ui">Database</text><rect x="70" y="124" width="120" height="22" rx="3" fill="#f59e0b" opacity="0.6"/><circle cx="82" cy="135" r="3" fill="#2dd4bf"/><text x="130" y="139" text-anchor="middle" fill="#1a1a2e" font-size="9" font-family="system-ui">Monitoring</text><rect x="290" y="30" width="140" height="140" rx="6" fill="none" stroke="#e2e8f0" stroke-width="1.5"/><text x="360" y="24" text-anchor="middle" fill="#94a3b8" font-size="10" font-family="system-ui">Staging</text><rect x="300" y="40" width="120" height="22" rx="3" fill="#3b82f6" opacity="0.6"/><circle cx="312" cy="51" r="3" fill="#2dd4bf"/><text x="360" y="55" text-anchor="middle" fill="#ffffff" font-size="9" font-family="system-ui">Web Server</text><rect x="300" y="68" width="120" height="22" rx="3" fill="#3b82f6" opacity="0.6"/><circle cx="312" cy="79" r="3" fill="#2dd4bf"/><text x="360" y="83" text-anchor="middle" fill="#ffffff" font-size="9" font-family="system-ui">App Server</text><rect x="300" y="96" width="120" height="22" rx="3" fill="#a855f7" opacity="0.5"/><circle cx="312" cy="107" r="3" fill="#f59e0b"/><text x="360" y="111" text-anchor="middle" fill="#ffffff" font-size="9" font-family="system-ui">Database</text><line x1="200" y1="100" x2="290" y2="100" stroke="#2dd4bf" stroke-width="1.5" stroke-dasharray="5,3"/><text x="245" y="95" text-anchor="middle" fill="#2dd4bf" font-size="8" font-family="system-ui">VLAN</text><rect x="480" y="60" width="90" height="70" rx="6" fill="none" stroke="#f59e0b" stroke-width="1" stroke-dasharray="4,3"/><text x="525" y="85" text-anchor="middle" fill="#f59e0b" font-size="9" font-family="system-ui">Backup</text><text x="525" y="100" text-anchor="middle" fill="#f59e0b" font-size="9" font-family="system-ui">Storage</text><text x="525" y="115" text-anchor="middle" fill="#94a3b8" font-size="8" font-family="system-ui">3-2-1 Rule</text><line x1="430" y1="100" x2="478" y2="95" stroke="#f59e0b" stroke-width="1" stroke-dasharray="4,3"/></svg><p style="margin-top:0.75rem;font-size:0.85rem;color:#94a3b8;font-style:italic;line-height:1.4;">Server infrastructure: production and staging environments connected via VLAN with offsite backups.</p></div>

This protects against hardware failure (redundant copies), media failure (different types), and disasters like fire or theft (offsite).

Restic: Encrypted Incremental Backups

Restic is a modern backup tool that creates encrypted, deduplicated, incremental backups. Think of it as what rsync would be if redesigned today.

Installation

# Ubuntu/Debian
sudo apt install restic

# Or download the latest binary
wget https://github.com/restic/restic/releases/download/v0.17.3/restic_0.17.3_linux_amd64.bz2
bunzip2 restic_0.17.3_linux_amd64.bz2
chmod +x restic_0.17.3_linux_amd64
sudo mv restic_0.17.3_linux_amd64 /usr/local/bin/restic

Initialize a Repository

# Local repository
restic init --repo /backups/restic-repo

# S3/MinIO repository
export AWS_ACCESS_KEY_ID=your-key
export AWS_SECRET_ACCESS_KEY=your-secret
restic init --repo s3:https://s3.example.com/backups

# SFTP repository
restic init --repo sftp:user@backup-server:/backups/restic

Backup Operations

# Backup a directory
restic -r /backups/restic-repo backup /var/lib/docker/volumes

# Backup with exclusions
restic -r /backups/restic-repo backup /home \
  --exclude="*.tmp" \
  --exclude=".cache" \
  --exclude="node_modules" \
  --exclude=".git"

# Backup Docker volumes with tags
restic -r /backups/restic-repo backup \
  /var/lib/docker/volumes/postgres_data \
  /var/lib/docker/volumes/gitea_data \
  --tag docker-volumes

<div style="margin:2.5rem auto;max-width:600px;width:100%;text-align:center;"><svg viewBox="0 0 600 180" xmlns="http://www.w3.org/2000/svg" style="width:100%;height:auto;"><rect width="600" height="180" rx="12" fill="#1a1a2e"/><ellipse cx="150" cy="55" rx="60" ry="18" fill="#6366f1" opacity="0.8"/><rect x="90" y="55" width="120" height="50" fill="#6366f1" opacity="0.8"/><ellipse cx="150" cy="105" rx="60" ry="18" fill="#6366f1" opacity="0.9"/><text x="150" y="85" text-anchor="middle" fill="#ffffff" font-size="12" font-family="system-ui" font-weight="bold">Primary</text><text x="150" y="140" text-anchor="middle" fill="#94a3b8" font-size="10" font-family="system-ui">Read + Write</text><ellipse cx="400" cy="30" rx="50" ry="14" fill="#a855f7" opacity="0.7"/><rect x="350" y="30" width="100" height="35" fill="#a855f7" opacity="0.7"/><ellipse cx="400" cy="65" rx="50" ry="14" fill="#a855f7" opacity="0.8"/><text x="400" y="52" text-anchor="middle" fill="#ffffff" font-size="10" font-family="system-ui">Replica 1</text><ellipse cx="400" cy="110" rx="50" ry="14" fill="#a855f7" opacity="0.7"/><rect x="350" y="110" width="100" height="35" fill="#a855f7" opacity="0.7"/><ellipse cx="400" cy="145" rx="50" ry="14" fill="#a855f7" opacity="0.8"/><text x="400" y="132" text-anchor="middle" fill="#ffffff" font-size="10" font-family="system-ui">Replica 2</text><defs><marker id="arrow8" markerWidth="8" markerHeight="6" refX="8" refY="3" orient="auto"><path d="M0,0 L8,3 L0,6" fill="#2dd4bf"/></marker></defs><path d="M212,65 Q280,30 348,48" stroke="#2dd4bf" stroke-width="1.5" fill="none" marker-end="url(#arrow8)"/><path d="M212,90 Q280,130 348,128" stroke="#2dd4bf" stroke-width="1.5" fill="none" marker-end="url(#arrow8)"/><text x="280" y="55" text-anchor="middle" fill="#2dd4bf" font-size="9" font-family="system-ui">WAL stream</text><text x="280" y="130" text-anchor="middle" fill="#2dd4bf" font-size="9" font-family="system-ui">WAL stream</text><text x="500" y="52" text-anchor="start" fill="#94a3b8" font-size="9" font-family="system-ui">Read-only</text><text x="500" y="132" text-anchor="start" fill="#94a3b8" font-size="9" font-family="system-ui">Read-only</text></svg><p style="margin-top:0.75rem;font-size:0.85rem;color:#94a3b8;font-style:italic;line-height:1.4;">Database replication: the primary handles writes while replicas serve read queries via WAL streaming.</p></div>

Snapshot Management

# List snapshots
restic -r /backups/restic-repo snapshots

# Restore the latest snapshot
restic -r /backups/restic-repo restore latest --target /restore/

# Restore specific paths
restic -r /backups/restic-repo restore latest \
  --target /restore/ \
  --include "/var/lib/docker/volumes/postgres_data"

# Mount snapshots as a browseable filesystem
mkdir /mnt/restic
restic -r /backups/restic-repo mount /mnt/restic

Retention Policy

# Keep: 7 daily, 4 weekly, 6 monthly, 2 yearly
restic -r /backups/restic-repo forget \
  --keep-daily 7 \
  --keep-weekly 4 \
  --keep-monthly 6 \
  --keep-yearly 2 \
  --prune

Rclone: Sync to Any Cloud

Rclone is rsync for cloud storage. It supports 70+ providers including S3, Backblaze B2, Google Drive, and SFTP.

Sync Operations

# Sync local restic repo to Backblaze B2
rclone sync /backups/restic-repo backblaze:my-backup-bucket/restic \
  --transfers 4 \
  --checkers 8 \
  --progress

# Sync with bandwidth limit (useful for residential connections)
rclone sync /backups backblaze:my-bucket \
  --bwlimit 10M \
  --progress

Complete Backup Script

#!/bin/bash
# backup-full.sh — Complete 3-2-1 backup implementation
set -euo pipefail

RESTIC_REPO="/backups/restic-repo"
RESTIC_PASSWORD_FILE="/etc/restic-password"
RCLONE_REMOTE="backblaze:my-backup-bucket"

export RESTIC_REPOSITORY="\$RESTIC_REPO"
export RESTIC_PASSWORD_FILE

echo "[\$(date)] Starting backup..."

# Step 1: Database dumps
docker exec postgres pg_dumpall -U postgres > /tmp/all-databases.sql

# Step 2: Restic backup (Copy 1 - local)
restic backup /var/lib/docker/volumes /mnt/projects /tmp/all-databases.sql \
  --tag automated --exclude="node_modules"

# Step 3: Apply retention
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune

# Step 4: Verify integrity
restic check --read-data-subset=5%

# Step 5: Offsite sync (Copy 2 - cloud)
rclone sync "\$RESTIC_REPO" "\$RCLONE_REMOTE/restic" --transfers 4

# Step 6: Cleanup
rm -f /tmp/all-databases.sql
echo "[\$(date)] Backup complete"

<div style="margin:2.5rem auto;max-width:600px;width:100%;text-align:center;"><svg viewBox="0 0 600 170" xmlns="http://www.w3.org/2000/svg" style="width:100%;height:auto;"><rect width="600" height="170" rx="12" fill="#1a1a2e"/><path d="M80,90 Q80,50 120,50 Q130,30 160,35 Q190,25 200,50 Q230,45 230,70 Q240,90 210,95 L100,95 Q70,95 80,90 Z" fill="none" stroke="#3b82f6" stroke-width="1.5"/><text x="155" y="75" text-anchor="middle" fill="#3b82f6" font-size="11" font-family="system-ui">Cloud</text><text x="155" y="120" text-anchor="middle" fill="#94a3b8" font-size="9" font-family="system-ui">$5,000/mo</text><defs><marker id="arrow9" markerWidth="10" markerHeight="7" refX="10" refY="3.5" orient="auto"><path d="M0,0 L10,3.5 L0,7" fill="#2dd4bf"/></marker></defs><line x1="245" y1="70" x2="340" y2="70" stroke="#2dd4bf" stroke-width="2.5" marker-end="url(#arrow9)"/><text x="293" y="60" text-anchor="middle" fill="#2dd4bf" font-size="10" font-family="system-ui" font-weight="bold">Migrate</text><rect x="355" y="35" width="180" height="70" rx="8" fill="none" stroke="#6366f1" stroke-width="2"/><rect x="365" y="45" width="160" height="15" rx="3" fill="#6366f1" opacity="0.7"/><rect x="365" y="65" width="160" height="15" rx="3" fill="#a855f7" opacity="0.7"/><rect x="365" y="85" width="100" height="10" rx="2" fill="#2dd4bf" opacity="0.5"/><text x="445" y="57" text-anchor="middle" fill="#ffffff" font-size="9" font-family="system-ui">Bare Metal</text><text x="445" y="77" text-anchor="middle" fill="#ffffff" font-size="9" font-family="system-ui">Docker + LXC</text><text x="445" y="120" text-anchor="middle" fill="#94a3b8" font-size="9" font-family="system-ui">$200/mo</text><text x="300" y="150" text-anchor="middle" fill="#2dd4bf" font-size="11" font-family="system-ui" font-weight="bold">96% cost reduction</text></svg><p style="margin-top:0.75rem;font-size:0.85rem;color:#94a3b8;font-style:italic;line-height:1.4;">Cloud to self-hosted migration can dramatically reduce infrastructure costs while maintaining full control.</p></div>

Disaster Recovery Testing

A backup you have never tested is not a backup. Schedule monthly restore tests:

#!/bin/bash
# test-restore.sh
RESTORE_DIR="/tmp/restore-test-\$(date +%Y%m%d)"
mkdir -p "\$RESTORE_DIR"
restic restore latest --target "\$RESTORE_DIR"
ACTUAL_FILES=\$(find "\$RESTORE_DIR" -type f | wc -l)
echo "Restored \$ACTUAL_FILES files successfully"
rm -rf "\$RESTORE_DIR"

At TechSaaS, we follow the 3-2-1 rule religiously. Our infrastructure has automated daily backups with restic, offsite sync to cloud storage via rclone, and ZFS snapshots for instant rollback. We run restore tests weekly and have recovered from failures in under 10 minutes.

Need bulletproof backup infrastructure? Contact [email protected].

#backups#restic#rclone#disaster-recovery#3-2-1-rule

Need help with cloud infrastructure?

TechSaaS provides expert consulting and managed services for cloud infrastructure, DevOps, and AI/ML operations.