Redis Tutorial 0/42 lessons ~6 min read Lesson 30

    Backup & Recovery

    Untested backups are Schrödinger's disaster recovery — RDB snapshots, AOF files, and managed cloud snapshots each need quarterly restore drills verifying key counts and applicat…

    Course progress0%
    Focus
    10 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    Introduction

    Untested backups are Schrödinger's disaster recovery — RDB snapshots, AOF files, and managed cloud snapshots each need quarterly restore drills verifying key counts and application smoke tests.

    Best practice: BGSAVE on replica, encrypt, upload to object storage with versioning, document RTO/RPO. Point-in-time for Redis alone is approximate — combine with application-level audit if needed.

    Restore to isolated instance first — never overwrite prod without validation.

    Understanding the topic

    Key concepts

    • RDB — point-in-time binary snapshot.
    • AOF — replay write log on restore.
    • Managed automatic snapshots (ElastiCache).
    • Off-site immutable copy (S3 Object Lock).
    • redis-check-rdb / redis-check-aof validation.
    • RTO/RPO documented per service tier.

    Step-by-step explanation

    1. Schedule BGSAVE or rely on cloud snapshot.
    2. Copy artifact to durable storage.
    3. Validate with check tools.
    4. Restore to temp Redis instance.
    5. Compare DBSIZE, spot keys, run app tests.
    6. Cutover or discard.

    Syntax reference

    Common commands

    • Test restore ≠ listing backup exists.
    • Encrypt at rest in S3.
    • Scrub PII when cloning prod to staging.
    bash
    redis-cli BGSAVE
    redis-check-rdb dump.rdb
    # Restore test
    redis-server --dbfilename dump.rdb --dir /tmp/restore-test
    redis-cli -p 6379 DBSIZE

    Informative example

    Automated backup script outline:

    bash
    #!/bin/bash
    redis-cli -h replica.internal BGSAVE
    sleep 30
    scp replica:/var/lib/redis/dump.rdb ./backup-$(date +%F).rdb
    redis-check-rdb backup-$(date +%F).rdb
    aws s3 cp backup-$(date +%F).rdb s3://dr/redis/ --sse AES256

    Run from replica. Alert if redis-check-rdb fails. Keep 30-day retention minimum for compliance tiers.

    Real-world use

    Real-world use cases

    • Disaster recovery regional outage.
    • Accidental FLUSHDB recovery from last RDB.
    • Staging refresh from sanitized prod.
    • Compliance audit trail of backups.
    • Pre-upgrade snapshot rollback point.

    Best practices

    • Quarterly restore drill with checklist.
    • Backup from replica not master.
    • Encrypt and version off-site copies.
    • Separate AWS account for backup bucket.
    • Document who approves prod restore.
    • Monitor backup job success alerts.

    Common mistakes

    • Backups never restored in test.
    • Only on-primary BGSAVE under load.
    • No encryption on backup bucket.
    • Restoring FLUSHALL over prod without isolation.

    Advanced interview questions

    Q1BeginnerRDB backup command?
    BGSAVE background; SAVE blocks — avoid.
    Q2BeginnerValidate RDB file?
    redis-check-rdb before restore.
    Q3IntermediateRPO with daily RDB?
    Up to 24 hours lost writes unless AOF everysec too.
    Q4IntermediateBackup without master impact?
    Run BGSAVE on replica node.
    Q5AdvancedDR runbook for Redis?
    Replica snapshot → S3 → restore isolated → DBSIZE/key sample → app smoke → promote or redirect.

    Summary

    Automate RDB/snapshot to off-site storage.

    Ready to mark this lesson complete?Track your journey across the entire course.