Skip to content

Instantly share code, notes, and snippets.

@fernandoaleman
Last active February 27, 2024 07:09
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save fernandoaleman/8e14f433b000e25e79c88933685dce67 to your computer and use it in GitHub Desktop.
Save fernandoaleman/8e14f433b000e25e79c88933685dce67 to your computer and use it in GitHub Desktop.
How to backup and restore Redis

How To Backup and Restore Redis

Backup

Login to Redis

$ redis-cli

Locate Redis database directory

127.0.0.1:6379> config get dir

Output

1) "dir"
2) "/var/lib/redis"

Commit the latest changes to the database

127.0.0.1:6379> save

Exit out of Redis

127.0.0.1:6379> exit

Create backup directory

$ mkdir -p /backup/redis

Copy the Redis database to backup directory

$ cp /var/lib/redis/dump.rdb /backup/redis/dump.rdb

Restore

Stop the Redis server

$ systemctl stop redis.service

Rename current Redis database

$ mv /var/lib/redis/dump.rdb /var/lib/redis/dump.rdb.old

Copy the backup Redis database to the Redis directory

$ cp /backup/redis/dump.rdb /var/lib/redis/dump.rdb

Set ownership on Redis database

$ chown redis.redis /var/lib/redis/dump.rdb

Set permissions on Redis database

$ chmod 660 /var/lib/redis/dump.rdb

Start the Redis server

$ systemctl start redis.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment