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”42.1 Understanding Backup Fundamentals
Section titled “42.1 Understanding Backup Fundamentals”Why Backup is Critical
Section titled “Why Backup is Critical”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 3-2-1 Backup Rule
Section titled “The 3-2-1 Backup Rule”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
Section titled “Backup Types Comparison” 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 │ │ │| │ └──────────────────────────────────────────────────────┘ │ │| └──────────────────────────────────────────────────────────────┘ │| |+------------------------------------------------------------------+42.2 Backup Solutions for Linux
Section titled “42.2 Backup Solutions for Linux”rsync-based Backups
Section titled “rsync-based Backups”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) │ │| └──────────┘ └─────────────┘ │| |+------------------------------------------------------------------+rsync Command Examples
Section titled “rsync Command Examples”# =============================================================================# BASIC RSYNC OPERATIONS# =============================================================================
# Basic sync (mirror)rsync -av /home/ /backup/home/
# Verbose with progressrsync -avz --progress /data/ /backup/data/
# Archive mode with compressionrsync -avz --compress /data/ /backup/
# =============================================================================# EXCLUDING FILES# =============================================================================
# Exclude specific patternsrsync -avz --exclude='*.log' --exclude='*.tmp' --exclude='.cache' /src/ /dst/
# Exclude directoriesrsync -avz --exclude='/node_modules/' --exclude='/dist/' /src/ /dst/
# Exclude file listrsync -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 remotersync -avz -e ssh /data/ user@remote:/backup/
# Pull from remotersync -avz -e ssh user@remote:/data/ /local/
# With SSH keyrsync -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 sizersync -avz --max-size=100M /data/ /backup/tar-based Backups
Section titled “tar-based Backups” TAR BACKUP PROCESS+------------------------------------------------------------------+| || ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌────────┐│| │ Source │ │ tar │ │ Compress│ │ Archive││| │ Files │─────→│ Create │─────→│ (gzip/ │─────→│ File ││| │ │ │ Archive│ │ bzip2) │ │ ││| └─────────┘ └─────────┘ └─────────┘ └────────┘│| || RECOVERY FLOW: || │| ┌────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐│| │ Archive│ │Extract │ │Decompress│ │ Restored││| │ File │─────→│ tar │─────→│ (gunzip) │─────→│ Files │││ │ │ │ │ │ │ │ ││| └────────┘ └─────────┘ └─────────┘ └─────────┘│| |+------------------------------------------------------------------+tar Command Examples
Section titled “tar Command Examples”# =============================================================================# BASIC TAR OPERATIONS# =============================================================================
# Create uncompressed archivetar -cvpf backup.tar /home/
# Create gzip compressed archivetar -cvzf backup-$(date +%Y%m%d).tar.gz /home/
# Create bzip2 compressed archivetar -cvjf backup.tar.bz2 /home/
# Create xz compressed archive (best compression)tar -cvJf backup.tar.xz /home/
# =============================================================================# EXCLUDE PATTERNS# =============================================================================
# Exclude specific patternstar -cvzf backup.tar.gz \ --exclude='*.log' \ --exclude='*.tmp' \ --exclude='.cache' \ --exclude='node_modules' \ /home/
# Exclude using filetar -cvzf backup.tar.gz -X exclude.txt /home/
# =============================================================================# INCREMENTAL BACKUP# =============================================================================
# Create snapshot file for incremental backupSNAPSHOT="/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 contentstar -tvf backup.tar.gz
# Extract all filestar -xvzf backup.tar.gz
# Extract to specific directorytar -xvzf backup.tar.gz -C /restore/
# Extract specific filetar -xvzf backup.tar.gz path/to/file
# Extract with full pathtar -xvzf backup.tar.gz -C /
# =============================================================================# SPLIT ARCHIVE INTO PARTS# =============================================================================
# Split into 100MB partstar -cvzf - /data/ | split -b 100M - backup.tar.gz.
# Restore from partscat backup.tar.gz.* | tar -xvzf -LVM Snapshots
Section titled “LVM Snapshots” 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 │ │| │ └──────────────────────┘ │ │| └─────────────────────────────────────────────────────────────┘ │| |+------------------------------------------------------------------+LVM Commands
Section titled “LVM Commands”# =============================================================================# CREATE SNAPSHOT# =============================================================================
# Create 10GB snapshotlvcreate -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-onlymount -o ro /dev/vg00/backup_snap /mnt/snapshot
# Backup from snapshotrsync -av /mnt/snapshot/ /backup/
# Or use tartar -cvzf /backup/snapshot-$(date +%Y%m%d).tar.gz -C /mnt/snapshot .
# =============================================================================# CLEANUP# =============================================================================
# Unmount snapshotumount /mnt/snapshot
# Remove snapshotlvremove /dev/vg00/backup_snap
# =============================================================================# MONITOR SNAPSHOT SPACE# =============================================================================
# Check snapshot sizelvs -a vg00
# Check snapshot usagelvdisplay vg00/backup_snap42.3 Automated Backup Scripts
Section titled “42.3 Automated Backup Scripts”Complete Backup Script Example
Section titled “Complete Backup Script Example”#!/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 directoriesSOURCE_DIRS=( "/home" "/etc" "/var/www" "/root" "/opt")
# Exclude patternsEXCLUDE_PATTERNS=( "*.tmp" "*.log" ".cache" "node_modules" ".git" ".svn" "__pycache__" "*.pyc")
# Backup locationsLOCAL_BACKUP_DIR="/backup/local"REMOTE_BACKUP_DIR="/backup/remote"REMOTE_HOST="backup.example.com"REMOTE_USER="backup"
# Retention policyDAILY_RETENTION=7WEEKLY_RETENTION=4MONTHLY_RETENTION=12
# LoggingLOG_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 functionmain "$@"Cron Setup
Section titled “Cron Setup”# Add to crontabcrontab -e
# Daily backup at 2:00 AM0 2 * * * /usr/local/bin/backup.sh >> /var/log/backup_cron.log 2>&1
# Weekly full backup Sunday at 3:00 AM0 3 * * 0 /usr/local/bin/backup-full.sh >> /var/log/backup_full.log 2>&142.4 System Backup with Timeshift
Section titled “42.4 System Backup with Timeshift”Understanding Timeshift
Section titled “Understanding Timeshift” 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) │ │ │| │ └──────────┘ └──────────┘ └──────────┘ │ │| │ │ │| └─────────────────────────────────────────────────────────────┘ │| |+------------------------------------------------------------------+Timeshift Commands
Section titled “Timeshift Commands”# =============================================================================# INSTALLATION# =============================================================================
# Arch Linuxsudo pacman -S timeshift
# Ubuntu/Debiansudo apt install timeshift
# Fedorasudo dnf install timeshift
# =============================================================================# CONFIGURATION# =============================================================================
# Create snapshot with commentssudo timeshift --create --comments "Before system update"
# Create BTRFS snapshotsudo timeshift --create --btrfs --comments "BTRFS snapshot"
# Create RSYNC snapshotsudo timeshift --create --rsync --comments "RSYNC snapshot"
# =============================================================================# SNAPSHOT MANAGEMENT# =============================================================================
# List all snapshotssudo timeshift --list
# List with detailssudo timeshift --list --details
# Delete snapshotsudo timeshift --delete --snapshot '2024-01-15_10-00-00'
# Delete all snapshotssudo timeshift --delete --all
# =============================================================================# RESTORE OPERATIONS# =============================================================================
# Restore latest snapshotsudo timeshift --restore
# Restore specific snapshotsudo timeshift --restore --snapshot '2024-01-15_10-00-00'
# Restore without bootloadersudo timeshift --restore --no-grub
# Estimate restore size (no actual restore)sudo timeshift --restore --estimate
# =============================================================================# SCHEDULED SNAPSHOTS (via systemd)# =============================================================================
# Enable scheduled snapshotssudo timeshift --schedule --daily
# Weekly snapshotssudo timeshift --schedule --weekly
# Monthly snapshotssudo timeshift --schedule --monthly
# Custom number of snapshotssudo timeshift --schedule --keep 542.5 Cloud Backup Solutions
Section titled “42.5 Cloud Backup Solutions”Overview of Cloud Backup Options
Section titled “Overview of Cloud Backup Options” 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 │ │| └────────────────┘ └────────────────┘ └────────────────┘ │| |+------------------------------------------------------------------+AWS S3 Backup Script
Section titled “AWS S3 Backup Script”#!/bin/bash# AWS S3 Backup Script
# ConfigurationS3_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 S3aws 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" }] }] }'42.6 Backup Best Practices
Section titled “42.6 Backup Best Practices”Decision Flowchart
Section titled “Decision Flowchart” 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 │| |+------------------------------------------------------------------+Summary Checklist
Section titled “Summary Checklist” 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