Redis Data Backup and Recovery

Redis SAVEThe command is used to create a backup of the current database.

Syntax

The basic syntax of the Redis SAVE command is as follows:

redis 127.0.0.1:6379> SAVE 

Example

redis 127.0.0.1:6379> SAVE 
OK

This command will create a dump.rdb file in the Redis installation directory.


Restore Data

To restore data, simply move the backup file (dump.rdb) to the Redis installation directory and start the service. To get the Redis directory, you can use theCONFIGcommand, as shown below:
 
redis 127.0.0.1:6379> CONFIG GET dir
1) "dir"
2) "/usr/local/redis/bin"

The above commandCONFIG GET dirThe output shows the Redis installation directory is /usr/local/redis/bin.


Bgsave

You can also use the command to create a Redis backup fileBGSAVE, which runs in the background.

Example

127.0.0.1:6379> BGSAVE

Background saving started
Other Extensions