Skip to content

Backup_strategies

Chapter 42: Backup Strategies and Concepts

Section titled “Chapter 42: Backup Strategies and Concepts”

Comprehensive Backup Planning for Linux Systems

Section titled “Comprehensive Backup Planning for Linux Systems”

Data is one of the most valuable assets in any organization. Data loss can occur due to various reasons:

DATA LOSS SCENARIOS
+------------------------------------------------------------------+
| |
| ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ |
| │ HARDWARE │ │ HUMAN │ │ SOFTWARE │ |
| │ FAILURE │ │ ERROR │ │ CORRUPTION │ |
| ├─────────────────┤ ├─────────────────┤ ├─────────────────┤ |
| │ - Disk failure │ │ - Accidental │ │ - Malware │ |
| │ - RAID failure │ │ deletion │ │ - Ransomware │ |
| │ - Power surge │ │ - Wrong file │ │ - Buggy code │ |
| │ - Controller │ │ overwrite │ │ - Database │ |
| │ issues │ │ - Misconfigured│ │ corruption │ |
| └─────────────────┘ │ script │ └─────────────────┘ |
| └─────────────────┘ |
| |
| ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ |
| │ NATURAL │ │ SECURITY │ │ ENVIRONMENTAL│ |
| │ DISASTERS │ │ THREATS │ │ FACTORS │ |
| ├─────────────────┤ ├─────────────────┤ ├─────────────────┤ |
| │ - Fire │ │ - Insider │ │ - Temperature │ |
| │ - Flood │ │ threats │ │ - Humidity │ |
| │ - Earthquake │ │ - Phishing │ │ - Power outage│ |
| │ - Lightning │ │ - Social │ │ - Fire │ |
| │ │ │ engineering │ │ suppression │ |
| └─────────────────┘ └─────────────────┘ └─────────────────┘ |
| |
+------------------------------------------------------------------+

The industry-standard backup strategy that ensures data safety:

THE 3-2-1 BACKUP STRATEGY
+------------------------------------------------------------------+
| |
| ┌────────────────────────────────────────────────────────────┐ │
| │ 3 COPIES OF DATA │ │
| │ │ │
| │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
| │ │ Original │ │ Copy 1 │ │ Copy 2 │ │ │
| │ │ Data │ │ (Local) │ │(Remote) │ │ │
| │ └──────────┘ └──────────┘ └──────────┘ │ │
| │ │ │ │ │ │
| │ └───────────────┴───────────────┘ │ │
| │ │ │ │
| └───────────────────────┼─────────────────────────────────┘ │
| ▼ │
| ┌────────────────────────────────────────────────────────────┐ │
| │ 2 DIFFERENT MEDIA │ │
| │ │ │
| │ ┌──────────────────┐ ┌──────────────────┐ │ │
| │ │ Primary Disk │ │ Secondary │ │ │
| │ │ (SSD/NVMe) │ │ (Tape/Cloud) │ │ │
| │ └──────────────────┘ └──────────────────┘ │ │
| │ │ │
| │ Prevents single point of failure │ │
| └────────────────────────────────────────────────────────────┘ │
| │ │
| ▼ │
| ┌────────────────────────────────────────────────────────────┐ │
| │ 1 OFFSITE COPY │ │
| │ │ │
| │ ┌──────────────────────────────────────────────────┐ │ │
| │ │ Geographicall Separated Location │ │ │
| │ │ │ │ │
| │ │ ┌────────┐ ┌────────┐ ┌────────┐ │ │ │
| │ │ │ Site │ │ Site │ │ Cloud │ │ │ │
| │ │ │ A │ │ B │ │ │ │ │ │
| │ │ │ (Local)│ │(Remote)│ │ Storage│ │ │ │
| │ │ └────────┘ └────────┘ └────────┘ │ │ │
| │ │ │ │ │
| │ └──────────────────────────────────────────────────┘ │ │
| │ │ │
| │ Protects against site-wide disasters │ │
| └────────────────────────────────────────────────────────────┘ │
| |
+------------------------------------------------------------------+
BACKUP TYPES COMPARISON
+------------------------------------------------------------------+
| |
| ┌──────────────────────────────────────────────────────────────┐ │
| │ FULL BACKUP │ │
| │ ┌──────────────────────────────────────────────────────┐ │ │
| │ │ Day 1: [████████████] 100% │ │ │
| │ │ Day 2: [████████████] 100% (new full) │ │ │
| │ │ Day 3: [████████████] 100% (new full) │ │ │
| │ │ │ │ │
| │ │ Pros: Simple restore, complete data │ │ │
| │ │ Cons: Large storage, slow backup time │ │ │
| │ └──────────────────────────────────────────────────────┘ │ │
| └──────────────────────────────────────────────────────────────┘ │
| |
| ┌──────────────────────────────────────────────────────────────┐ │
| │ INCREMENTAL BACKUP │ │
| │ ┌──────────────────────────────────────────────────────┐ │ │
| │ │ Day 1: [████████████] 100% (Full) │ │ │
| │ │ Day 2: [███..........] 25% (changes only) │ │ │
| │ │ Day 3: [█............] 10% (changes only) │ │ │
| │ │ Day 4: [██............] 15% (changes only) │ │ │
| │ │ │ │ │
| │ │ Pros: Fast backup, minimal storage │ │ │
| │ │ Cons: Slow restore (need all increments) │ │ │
| │ └──────────────────────────────────────────────────────┘ │ │
| └──────────────────────────────────────────────────────────────┘ │
| |
| ┌──────────────────────────────────────────────────────────────┐ │
| │ DIFFERENTIAL BACKUP │ │
| │ ┌──────────────────────────────────────────────────────┐ │ │
| │ │ Day 1: [████████████] 100% (Full) │ │ │
| │ │ Day 2: [███..........] 25% (changes from Day1) │ │ │
| │ │ Day 3: [█████.........] 40% (changes from Day1) │ │ │
| │ │ Day 4: [██████........] 60% (changes from Day1) │ │ │
| │ │ │ │ │
| │ │ Pros: Faster restore than incremental │ │ │
| │ │ Cons: Larger than incremental │ │ │
| │ └──────────────────────────────────────────────────────┘ │ │
| └──────────────────────────────────────────────────────────────┘ │
| |
+------------------------------------------------------------------+

rsync is a powerful tool for efficient file synchronization and backups:

RSYNC WORKFLOW
+------------------------------------------------------------------+
| |
| SOURCE RSYNC DESTINATION |
| DIRECTORY PROCESS DIRECTORY |
| |
| ┌──────────┐ ┌─────────────┐ ┌──────────┐ │
| │ /data/ │──────────│ │─────────→│ /backup/ │ │
| │ │ │ Compare │ │ │ │
| │ file1 ───│──┐ │ Files │ │ file1 │ │
| │ file2 ───│──┼──→ │ │ │ file2 │ │
| │ file3 ───│──┤ │ Copy Only │ │ file3 │ │
| │ file4 │ │ │ Changed │ │ │ │
| └──────────┘ │ │ │ └──────────┘ │
| │ │ Delta │ │
| │ │ Transfer │ │
│ │ │ │ │
│ ┌──────────┐ │ └─────────────┘ │
│ │ Previous │ │ │ │
│ │ Backup │←─┘ │ │
│ │ │ ▼ │
| │ file1 │ ┌─────────────┐ │
│ │ file2 │◄─────────│ Only Send │ │
│ │ file3 │ │ Delta │ │
│ │ │ │ (Diff) │ │
| └──────────┘ └─────────────┘ │
| |
+------------------------------------------------------------------+
Terminal window
# =============================================================================
# BASIC RSYNC OPERATIONS
# =============================================================================
# Basic sync (mirror)
rsync -av /home/ /backup/home/
# Verbose with progress
rsync -avz --progress /data/ /backup/data/
# Archive mode with compression
rsync -avz --compress /data/ /backup/
# =============================================================================
# EXCLUDING FILES
# =============================================================================
# Exclude specific patterns
rsync -avz --exclude='*.log' --exclude='*.tmp' --exclude='.cache' /src/ /dst/
# Exclude directories
rsync -avz --exclude='/node_modules/' --exclude='/dist/' /src/ /dst/
# Exclude file list
rsync -avz --exclude-from='/root/exclude.txt' /src/ /dst/
# =============================================================================
# SAFETY OPTIONS
# =============================================================================
# Delete files not on source (mirror)
rsync -avz --delete /data/ /backup/
# Dry run (preview what would happen)
rsync -avzn /data/ /backup/
# Checksum comparison (slower but more accurate)
rsync -avzc /data/ /backup/
# =============================================================================
# REMOTE BACKUP VIA SSH
# =============================================================================
# Push to remote
rsync -avz -e ssh /data/ user@remote:/backup/
# Pull from remote
rsync -avz -e ssh user@remote:/data/ /local/
# With SSH key
rsync -avz -e 'ssh -i ~/.ssh/backup_key' /data/ user@remote:/backup/
# =============================================================================
# BANDWIDTH AND PERFORMANCE
# =============================================================================
# Limit bandwidth (KB/s)
rsync -avz --bwlimit=1000 /data/ /backup/
# Partial file (resume interrupted)
rsync -avz --partial /data/ /backup/
# Skip based on size
rsync -avz --max-size=100M /data/ /backup/
TAR BACKUP PROCESS
+------------------------------------------------------------------+
| |
| ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌────────┐│
| │ Source │ │ tar │ │ Compress│ │ Archive││
| │ Files │─────→│ Create │─────→│ (gzip/ │─────→│ File ││
| │ │ │ Archive│ │ bzip2) │ │ ││
| └─────────┘ └─────────┘ └─────────┘ └────────┘│
| |
| RECOVERY FLOW: |
| │
| ┌────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐│
| │ Archive│ │Extract │ │Decompress│ │ Restored││
| │ File │─────→│ tar │─────→│ (gunzip) │─────→│ Files ││
│ │ │ │ │ │ │ │ ││
| └────────┘ └─────────┘ └─────────┘ └─────────┘│
| |
+------------------------------------------------------------------+
Terminal window
# =============================================================================
# BASIC TAR OPERATIONS
# =============================================================================
# Create uncompressed archive
tar -cvpf backup.tar /home/
# Create gzip compressed archive
tar -cvzf backup-$(date +%Y%m%d).tar.gz /home/
# Create bzip2 compressed archive
tar -cvjf backup.tar.bz2 /home/
# Create xz compressed archive (best compression)
tar -cvJf backup.tar.xz /home/
# =============================================================================
# EXCLUDE PATTERNS
# =============================================================================
# Exclude specific patterns
tar -cvzf backup.tar.gz \
--exclude='*.log' \
--exclude='*.tmp' \
--exclude='.cache' \
--exclude='node_modules' \
/home/
# Exclude using file
tar -cvzf backup.tar.gz -X exclude.txt /home/
# =============================================================================
# INCREMENTAL BACKUP
# =============================================================================
# Create snapshot file for incremental backup
SNAPSHOT="/backup/snapshot.file"
BACKUP_DIR="/backup"
SOURCE="/data"
tar --listed-incremental=$SNAPSHOT \
-cvzf $BACKUP_DIR/backup-$(date +%Y%m%d).tar.gz $SOURCE
# =============================================================================
# RESTORE OPERATIONS
# =============================================================================
# List contents
tar -tvf backup.tar.gz
# Extract all files
tar -xvzf backup.tar.gz
# Extract to specific directory
tar -xvzf backup.tar.gz -C /restore/
# Extract specific file
tar -xvzf backup.tar.gz path/to/file
# Extract with full path
tar -xvzf backup.tar.gz -C /
# =============================================================================
# SPLIT ARCHIVE INTO PARTS
# =============================================================================
# Split into 100MB parts
tar -cvzf - /data/ | split -b 100M - backup.tar.gz.
# Restore from parts
cat backup.tar.gz.* | tar -xvzf -
LVM SNAPSHOT ARCHITECTURE
+------------------------------------------------------------------+
| |
| BEFORE SNAPSHOT |
| |
| ┌─────────────────────────────────────────────────────────────┐ │
| │ LVM Volume Group │ │
| │ ┌────────────────────────────────────────────────────┐ │ │
| │ │ Logical Volume (LV) │ │ │
| │ │ │ │ │
| │ │ ┌─────────────────────────────────────────────┐ │ │ │
| │ │ │ Original Data │ │ │ │
| │ │ │ [Data1][Data2][Data3][Data4][Data5] │ │ │ │
| │ │ │ │ │ │ │
| │ │ └─────────────────────────────────────────────┘ │ │ │
| │ │ │ │ │
| │ └────────────────────────────────────────────────────┘ │ │
| └─────────────────────────────────────────────────────────────┘ │
| |
| AFTER SNAPSHOT |
| |
| ┌─────────────────────────────────────────────────────────────┐ │
| │ LVM Volume Group │ │
| │ ┌──────────────────┐ ┌───────────────────────────────┐ │ │
| │ │ Original LV │ │ Snapshot LV │ │ │
| │ │ │ │ │ │ │
| │ │ [Data1][Data2] │ │ [Copy1][Copy2][COW][COW] │ │ │
| │ │ [Data3][Data4] │ │ [Data3][Data4][Data5] │ │ │
| │ │ [Data5][Data6] │ │ │ │ │
| │ │ │ │ (Copy on Write) │ │ │
| │ └──────────────────┘ └───────────────────────────────┘ │ │
| │ │ │ │ │
| │ │ Changes written │ Snapshots track │ │
| │ │ to original │ original blocks │ │
| │ └──────────────────────┘ │ │
| └─────────────────────────────────────────────────────────────┘ │
| |
+------------------------------------------------------------------+
Terminal window
# =============================================================================
# CREATE SNAPSHOT
# =============================================================================
# Create 10GB snapshot
lvcreate -L 10G -s -n backup_snap /dev/vg00/lv_data
# Create thin snapshot (if using thin pool)
lvcreate -V 10G -T vg00/thin_pool -n backup_snap
# =============================================================================
# MOUNT AND BACKUP
# =============================================================================
# Mount snapshot read-only
mount -o ro /dev/vg00/backup_snap /mnt/snapshot
# Backup from snapshot
rsync -av /mnt/snapshot/ /backup/
# Or use tar
tar -cvzf /backup/snapshot-$(date +%Y%m%d).tar.gz -C /mnt/snapshot .
# =============================================================================
# CLEANUP
# =============================================================================
# Unmount snapshot
umount /mnt/snapshot
# Remove snapshot
lvremove /dev/vg00/backup_snap
# =============================================================================
# MONITOR SNAPSHOT SPACE
# =============================================================================
# Check snapshot size
lvs -a vg00
# Check snapshot usage
lvdisplay vg00/backup_snap

#!/bin/bash
#===============================================================================
# Automated Backup Script for Arch Linux
# Version: 1.0
# Author: SysAdmin
# Description: Comprehensive backup solution with local and remote backup
#===============================================================================
set -euo pipefail
#===============================================================================
# CONFIGURATION
#===============================================================================
# Backup directories
SOURCE_DIRS=(
"/home"
"/etc"
"/var/www"
"/root"
"/opt"
)
# Exclude patterns
EXCLUDE_PATTERNS=(
"*.tmp"
"*.log"
".cache"
"node_modules"
".git"
".svn"
"__pycache__"
"*.pyc"
)
# Backup locations
LOCAL_BACKUP_DIR="/backup/local"
REMOTE_BACKUP_DIR="/backup/remote"
REMOTE_HOST="backup.example.com"
REMOTE_USER="backup"
# Retention policy
DAILY_RETENTION=7
WEEKLY_RETENTION=4
MONTHLY_RETENTION=12
# Logging
LOG_FILE="/var/log/backup.log"
EMAIL_ALERT="admin@example.com"
#===============================================================================
# FUNCTIONS
#===============================================================================
log() {
local level="$1"
local message="$2"
echo "[$(date '+%Y-%m-%d %H:%M:%S')] [$level] $message" | tee -a "$LOG_FILE"
}
send_alert() {
local subject="$1"
local body="$2"
echo "$body" | mail -s "$subject" "$EMAIL_ALERT"
}
check_prerequisites() {
log "INFO" "Checking prerequisites..."
# Check backup directory exists
if [ ! -d "$LOCAL_BACKUP_DIR" ]; then
mkdir -p "$LOCAL_BACKUP_DIR"
fi
# Check required commands
for cmd in rsync tar gzip mail; do
if ! command -v "$cmd" &> /dev/null; then
log "ERROR" "Required command '$cmd' not found"
exit 1
fi
done
log "INFO" "Prerequisites check passed"
}
create_exclude_file() {
local exclude_file="/tmp/backup_exclude_$$.txt"
for pattern in "${EXCLUDE_PATTERNS[@]}"; do
echo "$pattern" >> "$exclude_file"
done
echo "$exclude_file"
}
backup_directory() {
local source_dir="$1"
local backup_name
backup_name=$(basename "$source_dir")
log "INFO" "Backing up $source_dir..."
# Create timestamped backup
local timestamp
timestamp=$(date +%Y%m%d_%H%M%S)
local backup_file="${LOCAL_BACKUP_DIR}/${backup_name}_${timestamp}.tar.gz"
# Create tar archive with exclusions
tar -czf "$backup_file" \
-g "${LOCAL_BACKUP_DIR}/${backup_name}.snapshot" \
-X "$(create_exclude_file)" \
"$source_dir" 2>> "$LOG_FILE"
# Verify backup
if [ -f "$backup_file" ]; then
local size
size=$(du -h "$backup_file" | cut -f1)
log "INFO" "Backup completed: $backup_file ($size)"
# Create symlink to latest
ln -sf "$backup_file" "${LOCAL_BACKUP_DIR}/${backup_name}_latest.tar.gz"
else
log "ERROR" "Backup failed for $source_dir"
return 1
fi
}
sync_to_remote() {
log "INFO" "Syncing to remote backup server..."
# Check SSH connectivity
if ! ssh -o ConnectTimeout=5 "$REMOTE_USER@$REMOTE_HOST" "echo ok" &>/dev/null; then
log "ERROR" "Cannot connect to remote server"
return 1
fi
# Sync backup directory
rsync -avz --delete \
-e "ssh -o StrictHostKeyChecking=no" \
"$LOCAL_BACKUP_DIR/" \
"$REMOTE_USER@$REMOTE_HOST:$REMOTE_BACKUP_DIR/" 2>> "$LOG_FILE"
log "INFO" "Remote sync completed"
}
cleanup_old_backups() {
log "INFO" "Cleaning up old backups..."
# Daily backups - keep 7 days
find "$LOCAL_BACKUP_DIR" -name "*.tar.gz" -mtime +$DAILY_RETENTION -delete
# Clean up temporary exclude files
rm -f /tmp/backup_exclude_*.txt
log "INFO" "Cleanup completed"
}
verify_backup() {
local backup_file="$1"
log "INFO" "Verifying backup: $backup_file"
# Test archive integrity
if tar -tzf "$backup_file" &>/dev/null; then
log "INFO" "Backup verification passed"
return 0
else
log "ERROR" "Backup verification failed"
return 1
fi
}
#===============================================================================
# MAIN EXECUTION
#===============================================================================
main() {
local start_time
start_time=$(date +%s)
log "INFO" "========================================="
log "INFO" "Starting backup process"
log "INFO" "========================================="
check_prerequisites
# Backup each directory
local failed=0
for dir in "${SOURCE_DIRS[@]}"; do
if [ -d "$dir" ]; then
backup_directory "$dir" || failed=1
else
log "WARN" "Directory not found: $dir"
fi
done
# Sync to remote if configured
if [ -n "$REMOTE_HOST" ]; then
sync_to_remote || failed=1
fi
# Cleanup
cleanup_old_backups
# Calculate duration
local end_time
end_time=$(date +%s)
local duration=$((end_time - start_time))
log "INFO" "========================================="
log "INFO" "Backup completed in ${duration} seconds"
log "INFO" "========================================="
# Send notification
if [ $failed -eq 0 ]; then
log "INFO" "All backups completed successfully"
else
log "ERROR" "Some backups failed"
send_alert "Backup Failed" "One or more backups failed. Check logs at $LOG_FILE"
exit 1
fi
}
# Run main function
main "$@"
Terminal window
# Add to crontab
crontab -e
# Daily backup at 2:00 AM
0 2 * * * /usr/local/bin/backup.sh >> /var/log/backup_cron.log 2>&1
# Weekly full backup Sunday at 3:00 AM
0 3 * * 0 /usr/local/bin/backup-full.sh >> /var/log/backup_full.log 2>&1

TIMESHIFT SNAPSHOT ARCHITECTURE
+------------------------------------------------------------------+
| |
| ┌─────────────────────────────────────────────────────────────┐ │
| │ SYSTEM FILES (Protected) │ │
| │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
| │ │ /etc │ │ /boot │ │ /usr │ │ /var │ │ │
| │ │ │ │ │ │ (partial)│ │ (partial)│ │ │
| │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │
| └─────────────────────────────────────────────────────────────┘ │
| │ │
│ ▼ │
| ┌─────────────────────────────────────────────────────────────┐ │
| │ TIMESHIFT SNAPSHOTS │ │
| │ │ │
| │ ┌───────────┐ ┌───────────┐ ┌───────────┐ │ │
| │ │ Snapshot │ │ Snapshot │ │ Snapshot │ │ │
| │ │ 2024-01 │ │ 2024-02 │ │ 2024-03 │ │ │
| │ │ │ │ │ │ │ │ │
| │ │ BTRFS/RSYNC│ │ BTRFS/RSYNC│ │ BTRFS/RSYNC│ │ │
| │ └───────────┘ └───────────┘ └───────────┘ │ │
| │ │ │
| └─────────────────────────────────────────────────────────────┘ │
| |
| ┌─────────────────────────────────────────────────────────────┐ │
│ │ RESTORE OPTIONS │ │
| │ │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
| │ │ RESTORE │ │ RESTORE │ │ RESTORE │ │ │
| │ │ FILES │ │ BTRFS │ │ RSYNC │ │ │
| │ │ (Select) │ │ (Snapshot)│ │ (Full) │ │ │
| │ └──────────┘ └──────────┘ └──────────┘ │ │
| │ │ │
| └─────────────────────────────────────────────────────────────┘ │
| |
+------------------------------------------------------------------+
Terminal window
# =============================================================================
# INSTALLATION
# =============================================================================
# Arch Linux
sudo pacman -S timeshift
# Ubuntu/Debian
sudo apt install timeshift
# Fedora
sudo dnf install timeshift
# =============================================================================
# CONFIGURATION
# =============================================================================
# Create snapshot with comments
sudo timeshift --create --comments "Before system update"
# Create BTRFS snapshot
sudo timeshift --create --btrfs --comments "BTRFS snapshot"
# Create RSYNC snapshot
sudo timeshift --create --rsync --comments "RSYNC snapshot"
# =============================================================================
# SNAPSHOT MANAGEMENT
# =============================================================================
# List all snapshots
sudo timeshift --list
# List with details
sudo timeshift --list --details
# Delete snapshot
sudo timeshift --delete --snapshot '2024-01-15_10-00-00'
# Delete all snapshots
sudo timeshift --delete --all
# =============================================================================
# RESTORE OPERATIONS
# =============================================================================
# Restore latest snapshot
sudo timeshift --restore
# Restore specific snapshot
sudo timeshift --restore --snapshot '2024-01-15_10-00-00'
# Restore without bootloader
sudo timeshift --restore --no-grub
# Estimate restore size (no actual restore)
sudo timeshift --restore --estimate
# =============================================================================
# SCHEDULED SNAPSHOTS (via systemd)
# =============================================================================
# Enable scheduled snapshots
sudo timeshift --schedule --daily
# Weekly snapshots
sudo timeshift --schedule --weekly
# Monthly snapshots
sudo timeshift --schedule --monthly
# Custom number of snapshots
sudo timeshift --schedule --keep 5

CLOUD BACKUP SOLUTIONS
+------------------------------------------------------------------+
| |
| ┌────────────────┐ ┌────────────────┐ ┌────────────────┐ │
| │ AWS S3 │ │ Azure Blob │ │ Google Cloud │ │
| │ Storage │ │ Storage │ │ Storage │ │
| ├────────────────┤ ├────────────────┤ ├────────────────┤ │
| │ - S3 Standard │ │ - Hot/ Cool │ │ - Standard │ │
| │ - Glacier │ │ - Archive │ │ - Nearline │ |
| │ - Lifecycle │ │ - Lifecycle │ │ - Coldline │ │
│ │ - Cross-repl│ │ - Geo-redund │ │ - Multi-reg │ │
| └────────────────┘ └────────────────┘ └────────────────┘ |
| |
| ┌────────────────┐ ┌────────────────┐ ┌────────────────┐ │
| │ Backblaze │ │ Wasabi │ │ MinIO │ │
| │ B2 │ │ │ │ (Self-Host) │ │
| ├────────────────┤ ├────────────────┤ ├────────────────┤ │
| │ - Unlimited │ │ - No egress │ │ - S3-compat │ │
| │ retention │ │ fees │ │ - MinIO │ │
| │ - Low cost │ │ - Fast │ │ Gateway │ │
| └────────────────┘ └────────────────┘ └────────────────┘ │
| |
+------------------------------------------------------------------+
#!/bin/bash
# AWS S3 Backup Script
# Configuration
S3_BUCKET="s3://my-backup-bucket"
AWS_REGION="us-east-1"
BACKUP_DIR="/backup"
LOG_FILE="/var/log/s3_backup.log"
log() {
echo "[$(date)] $1" | tee -a "$LOG_FILE"
}
# Upload to S3
aws s3 sync "$BACKUP_DIR" "$S3_BUCKET" \
--storage-class STANDARD_IA \
--region "$AWS_REGION" \
--delete \
2>&1 | tee -a "$LOG_FILE"
# Lifecycle policy (move to Glacier after 30 days)
aws s3api put-bucket-lifecycle \
--bucket my-backup-bucket \
--lifecycle-configuration '{
"Rules": [{
"ID": "MoveToGlacier",
"Status": "Enabled",
"Prefix": "",
"Transitions": [{
"Days": 30,
"StorageClass": "GLACIER"
}]
}]
}'

BACKUP STRATEGY DECISION
+------------------------------------------------------------------+
| |
| START │
| │ │
| ▼ │
| ┌─────────────────────────────┐ │
| │ What is data criticality? │ │
| └─────────────────────────────┘ │
│ │ │
│ ┌───────────────┼───────────────┐ │
│ ▼ ▼ ▼ │
│ ┌─────────┐ ┌───────────┐ ┌──────────┐ │
│ │ Critical │ │ Important │ │ Standard │ │
│ └────┬────┘ └─────┬─────┘ └────┬─────┘ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌─────────────────────────────┐ │
│ │ RTO < 1 hour, RPO < 15 min │ │
│ │ │ │
│ │ - Real-time replication │ │
│ │ - Multiple backup types │ │
│ │ - Offsite + cloud │ │
│ └─────────────────────────────┘ │
| │ │
| ▼ │
| ┌───────────────────────────┐ │
| │ Storage budget? │ │
| └───────────────────────────┘ │
│ │ │ │
│ ┌─────┴─────┐ ┌─────┴──────┐ │
│ ▼ ▼ ▼ ▼ │
│ ┌────────┐ ┌──────────┐ ┌──────────┐ │
│ │ High │ │ Medium │ │ Low │ │
│ │ Budget │ │ Budget │ │ Budget │ │
│ └────┬───┘ └────┬─────┘ └────┬─────┘ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌─────────────────────────────┐ │
│ │ Recommended Strategy │ │
│ │ │ │
│ │ - Daily incremental │ │
│ │ - Weekly full │ │
│ │ - Cloud sync │ │
│ │ - Monthly archive │ │
│ └─────────────────────────────┘ │
| │ │
| ▼ │
│ END │
| |
+------------------------------------------------------------------+
BACKUP BEST PRACTICES CHECKLIST
+------------------------------------------------------------------+
| |
| ┌─────────────────────────────────────────────────────────────┐ │
│ │ DATA BACKUP │ │
│ ├─────────────────────────────────────────────────────────────┤ │
│ │ □ All critical data is backed up │ │
│ │ □ Backup follows 3-2-1 rule │ │
│ │ □ Offsite backup is configured │ │
│ │ □ Backup encryption is enabled │ │
│ │ □ Regular backup testing is scheduled │ │
│ └─────────────────────────────────────────────────────────────┘ │
| |
| ┌─────────────────────────────────────────────────────────────┐ │
│ │ AUTOMATION │ │
│ ├─────────────────────────────────────────────────────────────┤ │
│ │ □ Automated backup schedule is configured │ │
│ │ □ Backup monitoring is in place │ │
│ │ □ Alert notifications are set up │ │
│ │ □ Log rotation is configured │ │
│ └─────────────────────────────────────────────────────────────┘ │
| |
| ┌─────────────────────────────────────────────────────────────┐ │
│ │ RECOVERY │ │
│ ├─────────────────────────────────────────────────────────────┤ │
│ │ □ Documented recovery procedures exist │ │
│ │ □ Recovery time objectives are defined │ │
│ │ □ Regular recovery drills are conducted │ │
│ │ □ Recovery keys/credentials are securely stored │ │
│ └─────────────────────────────────────────────────────────────┘ │
| |
| ┌─────────────────────────────────────────────────────────────┐ │
│ │ SECURITY │ │
│ ├─────────────────────────────────────────────────────────────┤ │
│ │ □ Backup data is encrypted at rest │ │
│ │ □ Backup data is encrypted in transit │ │
│ │ □ Access controls are implemented │ │
│ │ □ Audit logging is enabled │ │
│ └─────────────────────────────────────────────────────────────┘ │
| |
+------------------------------------------------------------------+

End of Chapter 42: Backup Strategies and Concepts