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.
| Setting | What it controls | How to check |
|---|---|---|
dir | Directory where the RDB (and AOF) files live | CONFIG GET dir |
dbfilename | Name of the RDB file (default dump.rdb) | CONFIG GET dbfilename |
save | Automatic snapshot rules, e.g. 3600 1 300 100 60 10000 | CONFIG GET save |
appendonly | Whether AOF is on. If it is, Redis loads the AOF instead of the RDB at startup | CONFIG 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.
- Check that
appendonlyisno(redis-cli CONFIG GET appendonly). If it isyes, follow the AOF procedure in the next section instead. - Stop Redis:
sudo systemctl stop redis-server(Debian/Ubuntu) orsudo systemctl stop redis(RHEL family). - Move the current file aside:
sudo mv /var/lib/redis/dump.rdb /var/lib/redis/dump.rdb.old. - Copy the backup in under the configured
dbfilename:sudo cp /backup/redis/dump-2026-12-01.rdb /var/lib/redis/dump.rdb. - 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. - Start Redis:
sudo systemctl start redis-server. - Verify the data: run
redis-cli DBSIZEandredis-cli INFO keyspace, and look forDB loaded from diskin the Redis log (journalctl -u redis-serveror/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.
- Stop Redis.
- In
redis.conf, setappendonly no. - Move the old AOF out of the way. Redis 7+ uses an
appendonlydirdirectory; older versions use a singleappendonly.aoffile. - Copy in
dump.rdb, fix ownership, and start Redis. CheckDBSIZE. - Turn AOF back on at runtime:
redis-cli CONFIG SET appendonly yes. Redis writes a new AOF from the current dataset in the background. - Wait until
redis-cli INFO persistenceshowsaof_rewrite_in_progress:0, then setappendonly yesinredis.confagain (or runCONFIG 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
| Symptom | Likely cause | Fix |
|---|---|---|
| Database is empty after restore | AOF is enabled and was loaded instead of the RDB, or the file name does not match dbfilename | Follow the AOF procedure; check CONFIG GET dbfilename |
| Restored data replaced by old data | Redis was running while the file was copied and saved over it at shutdown | Stop Redis before copying the file |
Background save already in progress | A save (automatic or manual) is already running | Wait 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 disk | Disk full, wrong permissions on dir, or the fork failed | Free disk space, chown redis:redis the data directory, check memory and vm.overcommit_memory |
Can't handle RDB format version | Backup was made on a newer Redis than the one restoring it | Restore on the same or a newer Redis version |
NOAUTH Authentication required | No password supplied | Set 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
- More Databases tutorials
- Database Platform Engineer: Role Blueprint, Responsibilities, Skills, KPIs, and Career Path
- Senior Database Administrator: Role Blueprint, Responsibilities, Skills, KPIs, and Career Path
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals