我使用scp
命令将我的redis快照(dump.rdb
文件)传输到远程服务器。 我需要在该远程服务器上运行redis服务器,并从dump.rdb
文件中恢复数据。 如何操作?
如果设置了appendonly
标志为no
的数据库,您可以执行以下操作:
dir
选项)。同时,请确保您的备份文件名与配置选项dbfilename
匹配。另一方面,如果您需要将rdb文件还原到追加文件数据库中,则应该执行以下类似操作:
dir
选项)。同时,请确保您的备份文件名与配置选项dbfilename
匹配。appendonly
标志为no
(否则Redis在启动时将忽略您的rdb文件)。redis-cli BGREWRITEAOF
以创建新的追加文件。appendonly
标志恢复为yes
。具体而言,这是Redis配置文件注释中相关的部分内容:
# Note that you can have both the async dumps and the append only file if you
# like (you have to comment the "save" statements above to disable the dumps).
# >> Still if appendonly mode is enabled Redis will load the data from the
# >> log file at startup ignoring the dump.rdb file.
没有具体的操作步骤。只需在新机器上安装redis服务器并编辑配置文件。您只需要更改以下参数,以指向您刚刚复制的转储文件的位置。
# The filename where to dump the DB
dbfilename mydump.rdb
# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# Also the Append Only File will be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir /data/mydirectory/
最后,可以以正常方式启动redis服务器。
redis.conf
文件中的appendonly
设置。每当您想要恢复Redis dump.rdb
文件时,您必须确保在redis.conf
内将appendonly
设置为no
。否则,它会完全清空您的dump.rdb
文件,并从零开始重新开始,就好像什么都没有发生过一样。小心谨慎! - Paul D.dump.rdb
,并且存在于目录 /home/user/dbs
中,那么以下命令可以完成该操作:redis-server --dbfilename dump.rdb --dir /home/user/dbs
官方文档的相关部分:通过命令行传递参数
service redis6379 stop
cp /path/to/dump-6379.rdb /var/lib/redis/dump-6379.rdb
。给它正确的权限(用户:组应该是 redis:redis,并且模式为 644)service redis6379 start
pip install rdbtools python-lzf
执行此操作
rdb -c protocol /path/to/dump.rdb | redis-cli -h host -p port --pipe
如果这是一个集群,端口应该是主节点的端口。
redis-server
时,如果同时指定了mydump.rdb和appendonly.aof文件,则以appendonly.aof
文件为准,因此将加载来自appendonly.aof的数据。例如:redis-server --dbfilename mydump001.rdb --dir /data --appendonly yes
/dir
位置来查找mydump001.rdb
或appendonly.aof
文件的存在。在这种情况下,redis-server
将从appendonly.aof
中加载内容。如果appendonly.aof
不存在,则会创建一个空的/data/appendonly.aof
,redis-server将为空。redis-server --dbfilename mydump001.rdb --dir /data
我添加了这个答案,因为哪一个是哪一个并不明显。如果存在两个备份文件,这通常没有被提及。
在你的第二台服务器上启动Redis,如下所示:
$ > redis-server /path/to/my/redis/configuration/file/redis.conf
# The filename where to dump the DB
dbfilename dump.rdb
# The working directory
dir ./
如您所见,这两个设置都有默认值。
只需更改第一个设置 (第127行) 来标识您的 RDB 文件, 在第二个设置中 (第137行),将默认值“./”替换为快照 RDB 文件的实际文件路径; 保存带有更改的 redis.conf 文件,并启动 Redis 传递这个新的配置文件。
安装 https://github.com/leonchen83/redis-rdb-cli
rmt -s ./your-dump.rdb -m redis://host:port -r
请尝试设置appendonly为no。在我的案例中,*.aof文件为空(0字节),必须将appendonly设置为no,然后使其加载dump.rdb。
chown redis:redis dump.rdb
和chmod 644 dump.rdb
命令。 - RickyAappendonly
标志设置为yes
导致RDB文件被忽略并重写。 - rubik