MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

How to backup / dump & Restore redis database?

To back up Redis, write a fresh RDB snapshot (dump.rdb) and copy it somewhere safe. To restore it, stop Redis, put the snapshot in the data directory and start Redis again. This guide covers the steps above plus the parts they leave out: non-blocking backups, remote backups with redis-cli --rdb, the full restore procedure, servers with AOF enabled, Docker, and automation.


$ redis-cli
127.0.0.1:6379> auth mypassword
127.0.0.1:6379> CONFIG GET dir
127.0.0.1:6379> SAVE
127.0.0.1:6379> quit

This ensures dump.rdb is completely up-to-date, and shows us where it is stored (/var/lib/redis/dump.rdb in this case). dump.rdb is also periodically written to disk automatically.

$ cd /var/lib/redis
$ cat dump.rdb
Code language: JavaScript (javascript)

dump.rdb is your redis backup file


How Redis persistence works

Redis keeps its data in memory and can persist it to disk in two ways. RDB writes a point-in-time snapshot of the whole dataset to a single compact binary file, dump.rdb by default. AOF (append-only file) logs every write operation. For backups, the RDB file is what you want: it is one file, it is portable between servers, and Redis loads it at startup.

SettingWhat it controlsHow to check
dirDirectory where the RDB (and AOF) files liveCONFIG GET dir
dbfilenameName of the RDB file (default dump.rdb)CONFIG GET dbfilename
saveAutomatic snapshot rules, e.g. 3600 1 300 100 60 10000CONFIG GET save
appendonlyWhether AOF is on. If it is, Redis loads the AOF instead of the RDB at startupCONFIG GET appendonly

Note: Always check dbfilename as well as dir. If someone has renamed the RDB file, backing up dump.rdb copies a stale or missing file.

Take a backup without blocking Redis

The example above uses SAVE, which runs the snapshot in the main Redis thread. No client gets served until it finishes, and on a large dataset that can take seconds or minutes. On a live server, use BGSAVE instead. It forks a child process that writes the snapshot while Redis carries on serving requests.

# Avoid typing the password on the command line (keeps it out of shell history and ps)
export REDISCLI_AUTH='mypassword'

redis-cli CONFIG GET dir
redis-cli CONFIG GET dbfilename

redis-cli LASTSAVE          # Unix timestamp of the last successful save
redis-cli BGSAVE            # -> Background saving started

# Wait until the save has finished and succeeded
redis-cli INFO persistence | grep -E 'rdb_bgsave_in_progress|rdb_last_bgsave_status'
# rdb_bgsave_in_progress:0
# rdb_last_bgsave_status:okCode language: PHP (php)

When LASTSAVE returns a newer timestamp and the status is ok, copy the file somewhere else. Do not use cat as the example above does. The RDB file is binary, so printing it to a terminal gives you garbage and does not back anything up.

sudo cp /var/lib/redis/dump.rdb /backup/redis/dump-$(date +%F-%H%M).rdb
redis-check-rdb /backup/redis/dump-*.rdb   # verifies the file can be parsedCode language: PHP (php)

Note: With Redis 6+ ACLs, authenticate as AUTH username password (or set --user). A plain AUTH password logs in as the default user only.

Back up a remote Redis with redis-cli –rdb

redis-cli can pull a fresh RDB snapshot over the network and save it locally. You do not need shell access to the Redis host or to know its data directory. This is often the easiest way to back up a remote or containerised instance.

export REDISCLI_AUTH='mypassword'
redis-cli -h redis.example.internal -p 6379 --rdb /backup/redis/dump-$(date +%F).rdb
# ... Transfer finished with success.Code language: PHP (php)

Under the hood this uses the replication protocol, so the user needs permission for SYNC/PSYNC when ACLs are enabled. Many managed services, such as ElastiCache or Azure Cache for Redis, block this and also restrict CONFIG, SAVE and BGSAVE. On those platforms, use the provider's own snapshot or export feature.

Restore a Redis database from dump.rdb

The original post stops at the backup. Order matters when you restore. If you copy the file in while Redis is running, Redis may write its in-memory dataset over your file at the next automatic save or at shutdown. Stop Redis first.

  1. Check that appendonly is no (redis-cli CONFIG GET appendonly). If it is yes, follow the AOF procedure in the next section instead.
  2. Stop Redis: sudo systemctl stop redis-server (Debian/Ubuntu) or sudo systemctl stop redis (RHEL family).
  3. Move the current file aside: sudo mv /var/lib/redis/dump.rdb /var/lib/redis/dump.rdb.old.
  4. Copy the backup in under the configured dbfilename: sudo cp /backup/redis/dump-2026-12-01.rdb /var/lib/redis/dump.rdb.
  5. Fix ownership and permissions so the Redis user can read it: sudo chown redis:redis /var/lib/redis/dump.rdb && sudo chmod 660 /var/lib/redis/dump.rdb.
  6. Start Redis: sudo systemctl start redis-server.
  7. Verify the data: run redis-cli DBSIZE and redis-cli INFO keyspace, and look for DB loaded from disk in the Redis log (journalctl -u redis-server or /var/log/redis/redis-server.log).

Note: Redis loads the RDB file only at startup. Copying a file into the data directory while Redis is running does nothing until a restart.

Restoring when AOF is enabled

When appendonly yes is set, Redis rebuilds its dataset from the AOF at startup and ignores dump.rdb. Restoring only the RDB file therefore seems to do nothing, or brings back an empty database. Load the RDB with AOF off, then switch AOF back on so Redis builds a new AOF from the restored data.

  1. Stop Redis.
  2. In redis.conf, set appendonly no.
  3. Move the old AOF out of the way. Redis 7+ uses an appendonlydir directory; older versions use a single appendonly.aof file.
  4. Copy in dump.rdb, fix ownership, and start Redis. Check DBSIZE.
  5. Turn AOF back on at runtime: redis-cli CONFIG SET appendonly yes. Redis writes a new AOF from the current dataset in the background.
  6. Wait until redis-cli INFO persistence shows aof_rewrite_in_progress:0, then set appendonly yes in redis.conf again (or run CONFIG REWRITE) so the setting survives a restart.

Backup and restore in Docker

In the official redis image the data directory is /data. Mount it as a volume so snapshots survive when the container is replaced.

# Backup
docker exec redis redis-cli BGSAVE
docker exec redis redis-cli INFO persistence | grep rdb_bgsave_in_progress
docker cp redis:/data/dump.rdb ./dump-$(date +%F).rdb

# Restore (container stopped so nothing overwrites the file)
docker stop redis
docker cp ./dump-2026-12-01.rdb redis:/data/dump.rdb
docker start redis
docker exec redis redis-cli DBSIZECode language: PHP (php)

docker cp works on stopped containers. If the file ends up owned by root, run docker run --rm -v <volume>:/data redis chown redis:redis /data/dump.rdb before you start the container again.

Automate daily backups

The script below takes a snapshot with --rdb, checks the file, compresses it and deletes backups older than seven days. Store the password in a root-only environment file, not in the script.

#!/usr/bin/env bash
# /usr/local/bin/redis-backup.sh
set -euo pipefail

BACKUP_DIR=/backup/redis
RETENTION_DAYS=7
FILE="$BACKUP_DIR/dump-$(date +%F-%H%M).rdb"

: "${REDISCLI_AUTH:?REDISCLI_AUTH must be set}"
export REDISCLI_AUTH
mkdir -p "$BACKUP_DIR"

redis-cli -h 127.0.0.1 -p 6379 --rdb "$FILE"
redis-check-rdb "$FILE" > /dev/null
gzip "$FILE"

find "$BACKUP_DIR" -name 'dump-*.rdb.gz' -mtime +"$RETENTION_DAYS" -deleteCode language: PHP (php)
# /etc/cron.d/redis-backup  (REDISCLI_AUTH defined in /etc/redis-backup.env, chmod 600)
30 2 * * * root . /etc/redis-backup.env && /usr/local/bin/redis-backup.sh >> /var/log/redis-backup.log 2>&1Code language: PHP (php)
  • Copy backups off the host (object storage or another server). A backup on the same disk does not survive losing that disk.
  • Encrypt backups at rest. An RDB file holds all your data in readable form.
  • Test restores on a scratch instance regularly. A backup you have never restored is unverified.
  • Make sure the host has free memory before a BGSAVE. The fork uses copy-on-write, and a busy server can temporarily need much more RAM than the dataset size.
  • Restore to the same or a newer Redis version. Older Redis versions refuse RDB files written in a newer format.

Common errors and fixes

SymptomLikely causeFix
Database is empty after restoreAOF is enabled and was loaded instead of the RDB, or the file name does not match dbfilenameFollow the AOF procedure; check CONFIG GET dbfilename
Restored data replaced by old dataRedis was running while the file was copied and saved over it at shutdownStop Redis before copying the file
Background save already in progressA save (automatic or manual) is already runningWait for rdb_bgsave_in_progress:0 and then copy the file
MISCONF Redis is configured to save RDB snapshots, but it's currently unable to persist to diskDisk full, wrong permissions on dir, or the fork failedFree disk space, chown redis:redis the data directory, check memory and vm.overcommit_memory
Can't handle RDB format versionBackup was made on a newer Redis than the one restoring itRestore on the same or a newer Redis version
NOAUTH Authentication requiredNo password suppliedSet REDISCLI_AUTH or authenticate with AUTH

Frequently asked questions

What is the difference between SAVE and BGSAVE in Redis?

SAVE writes the snapshot in the main thread and blocks every client until it finishes. BGSAVE forks a child process to write it in the background, so Redis keeps serving requests. Use BGSAVE on production servers.

Where is the Redis dump.rdb file stored?

It is stored in the directory returned by CONFIG GET dir, under the name returned by CONFIG GET dbfilename. Debian and Ubuntu packages typically use /var/lib/redis, and the official Docker image uses /data.

Can I restore a Redis backup without restarting the server?

Not from an RDB file. Redis reads it only at startup. To limit downtime, start a separate instance from the backup and switch clients over, or make the running server a replica of it with REPLICAOF.

Are the Redis DUMP and RESTORE commands the same as a database backup?

No. DUMP and RESTORE serialise and recreate a single key. They are useful for moving individual keys, but a full database backup uses an RDB snapshot.

Is it safe to copy dump.rdb while Redis is running?

Yes, for a backup. Redis writes snapshots to a temporary file and renames it into place, so the file you copy is always complete. Just make sure no BGSAVE is still in progress if you need the latest data.

Related tutorials

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals

Related Posts

How to deal with data persistence using Redis while implementing Cache?

Redis is primarily an in-memory data store, meaning it stores data in the system’s memory (RAM) for fast read and write operations. However, Redis also provides options…

Read More

Top 10 Backup & Recovery Tools in 2026: Features, Pros, Cons & Comparison

Introduction In todayโ€™s digital world, data is the backbone of virtually every business operation. As the amount of critical data grows, so does the need for robust…

Read More

Chef Tutorials: Chef Infra Server & Chef Automate Backup and Restore

Chef Infra Server is backed up with chef-server-ctl backup and restored with chef-server-ctl restore. Chef Automate has its own commands, chef-automate backup create and chef-automate backup restore….

Read More

Best Azure DevOps Backup Tools in 2026

Source: Magnific Azure DevOps doesn’t back itself up. Deleted repositories, pipelines, and work items can vanish for good once the recovery window closes, and Microsoft’s own documentation…

Read More

AWS Tutorials: How to Shutdown (Stop / Start) ElastiCache Service in AWS

Amazon ElastiCache has no stop or start button. You keep paying for every node until you shrink or delete it. This guide shows the two ways to…

Read More

Shell Bash Scripting: Assignment & Excercise – 7

This exercise uses Bash, rsync and SSH to copy a local file to a remote backup server, then sends an email when the copy finishes. Below the…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x