Redis 简明教程

Redis - Backup

Redis SAVE 命令用于创建当前 Redis 数据库的备份。

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

Syntax

以下是 redis SAVE 命令的基本语法。

Following is the basic syntax of redis SAVE command.

127.0.0.1:6379> SAVE

Example

以下示例创建当前数据库的备份。

Following example creates a backup of the current database.

127.0.0.1:6379> SAVE
OK

此命令将在您的 Redis 目录中创建一个 dump.rdb 文件。

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

Restore Redis Data

要还原 Redis 数据,请将 Redis 备份文件 (dump.rdb) 移动到您的 Redis 目录并启动服务器。要获取您的 Redis 目录,请使用 Redis 的 CONFIG 命令,如下所示。

To restore Redis data, move Redis backup file (dump.rdb) into your Redis directory and start the server. To get your Redis directory, use CONFIG command of Redis as shown below.

127.0.0.1:6379> CONFIG get dir
1) "dir"
2) "/user/tutorialspoint/redis-2.8.13/src"

在以上命令的输出中, /user/tutorialspoint/redis-2.8.13/src 是 Redis 服务器安装所在的目录。

In the output of the above command /user/tutorialspoint/redis-2.8.13/src is the directory, where Redis server is installed.

Bgsave

为了创建 Redis 备份,还可以使用另一个命令 BGSAVE 。此命令将启动备份进程,并在后台运行此进程。

To create Redis backup, an alternate command BGSAVE is also available. This command will start the backup process and run this in the background.

Example

127.0.0.1:6379> BGSAVE
Background saving started