Backup and Restore Redis-Server Database


The server can be installed using:

apt-get update
apt-get install redis-server

Next, verify in /etc/redis/redis.conf for these two lines:

dbfilename dump.rdb
dir /var/lib/redis

The first one is the name of the backup dump file that will be generated and the second line describes the folder where it will be located.

This command will launch the actual backup:

redis-cli bgsave

You can pickup the backup file /var/lib/redis/dump.rdb and copy it for example to a backup drive.

Restoring the backup is as easy as stopping redis, copying the dump back to /var/lib/redis/dump.rdb, making sure it has the right permissions and restarting redis.

service redis-server stop
...
chown redis:redis /var/lib/redis/dump.rdb
service redis-server start

This will do a simple backup & restore of the whole database. There are more complex scenarios such as appending data which for a simple backup & restore of the whole DB is not needed.

To get the timestamp of the last executed backup, you can use:

redis-cli LASTSAVE