Redis data backup and recovery
Redis SAVE 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 the dump.rdb file in the redis installation directory.
Restore data
If you need to restore data, just move the backup file (dump.rdb) to the redis installation directory and start the service. To obtain the redis directory, you can use the CONFIG command, as shown below:redis 127.0.0.1:6379> CONFIG GET dir 1) "dir" 2) "/usr/local/redis/bin"
The above command CONFIG GET dir outputs the redis installation directory as /usr/local/redis/bin.
Bgsave
To create a redis backup file, you can also use the command BGSAVE, which is executed in the background.
Example
127.0.0.1:6379> BGSAVE Background saving started