How to Configure Redis Persistence with Rdb Snapshots and Aof Logging for Data Durability and Backup on Ubuntu Server

Learning how to configure Redis persistence with RDB snapshots and AOF logging for data durability and backup on Ubuntu Server is essential for any production environment. Redis is an in-memory data store, which means data can disappear on restart or crash. Without persistence, you risk losing everything. This tutorial shows you how to enable both RDB (Redis Database) snapshots and AOF (Append-Only File) logging. Together, these two methods give you strong data protection. You’ll walk away knowing how to configure each method, combine them, and verify your setup is working correctly. Whether you’re running Redis for caching, session storage, or as a primary data store, this guide applies directly to your Ubuntu server setup.

Prerequisites for Configuring Redis Persistence on Ubuntu Server

Before you start, make sure you have the following in place.

Required software and access:

  • Ubuntu Server 20.04 or 22.04 (LTS recommended)
  • Redis installed and running (version 6.x or 7.x)
  • Root or sudo access to the server
  • A text editor such as nano or vim

Assumed knowledge:

  • Basic Linux command-line experience
  • Familiarity with editing configuration files
  • Understanding of what Redis does at a high level

Estimated time: 30–45 minutes

If Redis isn’t installed yet, run the following commands first:

sudo apt update
sudo apt install redis-server -y
sudo systemctl enable redis-server
sudo systemctl start redis-server

Check that Redis is running before moving on:

sudo systemctl status redis-server

You should see active (running) in the output. Once confirmed, you’re ready to begin.

How to Configure Redis RDB Snapshots and AOF Logging for Data Durability

You might also find this useful: Host File Edit: Viewing Websites Without DNS

This section walks you through configuring both persistence methods. RDB creates point-in-time snapshots. AOF logs every write operation. Using both gives you the best balance of speed and safety.

Step 1: Open the Redis configuration file

The main config file lives at /etc/redis/redis.conf. Open it with nano:

sudo nano /etc/redis/redis.conf

Step 2: Configure RDB snapshots

Find the save directives in the file. They control when Redis writes a snapshot. By default, you’ll see something like this:

save 900 1
save 300 10
save 60 10000

These rules mean: save after 900 seconds if at least 1 key changed, after 300 seconds if 10 keys changed, and after 60 seconds if 10,000 keys changed. Adjust these based on your needs. For a busy server, shorter intervals make sense. For a low-traffic app, the defaults work fine.

Set the RDB filename and directory:

dbfilename dump.rdb
dir /var/lib/redis

Enable RDB compression to save disk space:

rdbcompression yes
rdbchecksum yes

Step 3: Enable AOF logging

Find the appendonly setting. Change it from no to yes:

appendonly yes

Set the AOF filename:

appendfilename "appendonly.aof"

Step 4: Set the AOF sync policy

The appendfsync option controls how often Redis flushes the AOF file to disk. You have three choices:

# always  - safest, slowest
# everysec - good balance (recommended)
# no       - fastest, least safe

appendfsync everysec

The everysec option is the best choice for most servers. It syncs once per second. You may lose one second of data in a crash. That’s an acceptable trade-off for most workloads.

Step 5: Enable AOF rewrite to manage file size

AOF files grow over time. Redis can rewrite them automatically. Set these options:

auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb

This triggers a rewrite when the AOF file doubles in size and is at least 64MB.

Step 6: Set the persistence mode to use both RDB and AOF

Redis 7.x introduced a combined persistence mode. If you’re on Redis 7, add this line:

aof-use-rdb-preamble yes

This makes AOF files start with an RDB snapshot. It speeds up restart times significantly.

Step 7: Save and restart Redis

Save the file with CTRL+O, then exit with CTRL+X. Restart Redis to apply changes:

sudo systemctl restart redis-server

Step 8: Verify persistence is active

Connect to the Redis CLI and check the configuration:

redis-cli
127.0.0.1:6379> CONFIG GET save
127.0.0.1:6379> CONFIG GET appendonly

You should see your save intervals returned and appendonly set to yes. Run a manual save to test RDB:

127.0.0.1:6379> BGSAVE

Check that the dump file exists:

ls -lh /var/lib/redis/dump.rdb

For more detail on all available options, check the official Redis persistence documentation.

Troubleshooting Redis Persistence Issues on Ubuntu

Even with a clean setup, things can go wrong. Here are the most common problems and how to fix them.

Problem: Redis won’t start after editing the config

Check the logs for syntax errors:

sudo journalctl -u redis-server -n 50

A typo in redis.conf is usually the cause. Double-check your edits.

Problem: RDB file isn’t being created

Make sure Redis has write permission to the data directory:

sudo chown -R redis:redis /var/lib/redis
sudo chmod 750 /var/lib/redis

Problem: AOF file is growing too large

Trigger a manual AOF rewrite from the CLI:

redis-cli BGREWRITEAOF

Problem: Data still lost after restart

Confirm that both appendonly yes and valid save directives are set. Also check that the dir path points to a persistent volume. If you’re running Redis in a container or cloud instance, the data directory might be on a temporary filesystem.

Warning: Never set appendfsync no in production. The OS controls flushing, and you can lose significant data in a crash.

For Ubuntu-specific service management tips, the Ubuntu Server documentation is a reliable reference.

Conclusion: Keeping Your Redis Data Safe with RDB and AOF

You now know how to configure Redis persistence with RDB snapshots and AOF logging for data durability and backup on Ubuntu Server. You’ve enabled both persistence methods, tuned the sync policy, and verified your setup is working. Your Redis instance will now survive restarts and unexpected crashes without losing critical data.

From here, consider setting up automated backups of your dump.rdb and appendonly.aof files to a remote location. Tools like rsync or cloud storage solutions work well for this. You might also explore Redis Sentinel or Redis Cluster for high-availability setups. Both build on the persistence foundation you’ve set up today. Good persistence configuration is the first step toward a production-ready Redis deployment.

Similar Posts