Redis Cluster backups and restoration

09 / Sep / 2025 by Ashish Soni 0 comments

Redis Cluster backups to Amazon S3 using a single bash script and cron. It’s safe, slot-aware (backs up every node you run it on), and waits for BGSAVE to finish before uploading.

What this setup does

  • Runs on each Redis node, including masters and replicas, so you get a full cluster backup.
  • It triggers BGSAVE, waits for the snapshot to finish, and then uploads your persistence files to S3:
    • dump.rdb
    • appendonly.aof (if AOF or RDB+AOF is enabled)
  • It encrypts the data at rest in S3 using SSE-S3 or SSE-KMS. It also adds retention by using an S3 lifecycle rule and performs basic integrity checks.

Prerequisites (once per node)

  1. Install tools
    apt-get update && apt-get install -y awscli jq
    # or: yum install -y awscli jq
  2. AWS credentials on the node
    Prefer an EC2 instance profile role; otherwise configure aws configure.
  3. IAM policy for the instance role
    Grant Put/Get/List to your chosen bucket, plus (optional) KMS encrypt:
  4. Decide where Redis stores data
    Policy

    Policy

    Check redis.conf:
    1. dir /var/lib/redis
    2. dbfilename dump.rdb
    3. appendonly yes|no and appendfilename appendonly.aof

  5. S3 bucket & (optional) lifecycle
    Create the bucket s3://your-redis-backups/ and add a lifecycle rule. For example, keep the data for 30 days, then move it to Glacier or delete it.

2) Drop-in backup script

Save as /usr/local/bin/redis-cluster-backup.sh and make it executable.

 

Script

Script page -1

Script

Script page – 2

Script

Script page – 3

Optional: a small env file for easy overrides:-

Create /etc/redis-backup.env (owned & readable by root only):

env file

env file

Then call the script with:

Cmd

Cmd

3) Scheduling with Cron

Run daily at 02:15 local time or at any specific time as per your need:

Cron

Cron

5) Restore (node or cluster)

Standalone or single node (lab/staging)

  1. Stop Redis.
  2. Replace files in dir with your backup:
    1. If restoring RDB(Redis Database File): put the dump.rdb(point-in-time snapshot).
    2. If AOF(Append Only File) or mixed: put appendonly.aof (and ensure appendonly yes).
  3. Start Redis — it loads whichever persistence you’ve enabled.

Cluster restore (same topology)

  • Restore each node from its own backup (masters & replicas).
  • Start nodes; verify with:

    Redis

    Redis

  • Ensure slot ownership and replication match your desired layout.(If you are re-creating a cluster from scratch, use cluster create with the master/replica mapping and then restore files before opening to traffic.)
FOUND THIS USEFUL? SHARE IT

Leave a Reply

Your email address will not be published. Required fields are marked *