DBAtlas · Database operations atlas

Redis backup and restore (RDB, AOF, replica and cluster)

RedisLevel: IntermediateDuration: 30–60 min

Sets up a backup routine for an installed Redis or Valkey (single instance, master/replica with Sentinel, or Redis Cluster) and describes how to restore from backup. Step by step: RDB backups (save rule, BGSAVE, LASTSAVE, copy of dump.rdb) and AOF backups (BGREWRITEAOF, multi-part appendonlydir in 7.x), backup from a replica, backup of all masters in a Cluster, a test restore on a temporary instance, an in-place restore that avoids the AOF precedence trap, and a scheduled backup with retention and a remote copy via systemd timer / cron; the result is a backup that runs regularly and has been proven restorable. Replication (Sentinel, Cluster) is no substitute for a backup: accidentally deleted data propagates to every replica. Installation and day-to-day operations are covered in separate Redis guides.

Topology: Single instance, replica or Redis Cluster server (Redis 7.2 / 8.x, Valkey)

Before you start

  • … is running and requirepass is set in the configuration file … (the password is read from this file). The installation must have used the paths from the DBAtlas …Redis Cluster…Redis Sentinel… guide; if they differ, adapt the paths.
  • … is on a disk separate from the data disk or on a network share; free space at least the in-memory data size (used_memory) times the retention period. The data directory also needs enough free space for BGSAVE to write the new RDB.
  • BGSAVE/BGREWRITEAOF work with a fork: depending on the write rate, extra memory is needed (copy-on-write). vm.overcommit_memory = 1 must be set; otherwise the fork fails with "Can't save in background: fork: Cannot allocate memory".
  • The commands used for the backup (CONFIG, BGSAVE, LASTSAVE, BGREWRITEAOF…, CLUSTER, SYNC…) are not disabled with rename-command, and the user owning the password (default) can run them.
  • You have root or sudo rights. If an in-place restore is planned, a maintenance window has been agreed and the application team informed.

Phases of the guide

  • Current persistence settings — Review persistence and role information · Set the RDB save rule · Enable AOF at runtime · Prepare the backup directory
  • RDB backup — Verify that the replica is up to date · Take a fresh RDB with BGSAVE · Copy dump.rdb to the backup directory and verify it · List the Cluster masters · Take an RDB from each master (--rdb)
  • AOF backup — Compact the AOF (BGREWRITEAOF) · Back up appendonlydir · Verify the AOF files
  • Test restore (temporary instance) — Open the RDB on a temporary instance · Compare with the source and shut down the temporary instance · Open the AOF backup on a temporary instance
  • In-place restore — Stop the service and move the current files aside · Put the RDB backup in place · Disable AOF temporarily · Put the AOF backup in place · Start the service and verify the data · Re-enable AOF at runtime …
  • Scheduled backup and retention — Write the backup script · Make the script executable · Prepare SSH access to the remote server · Create the systemd service and timer · Trigger the scheduled backup manually and verify it · Write the cron job …
  • Monitoring — Monitor persistence and backup age · Regular restore drill
Open the step-by-step plan for your environment →