Redis database recovery does not display records

Hope this is a simple question:

I am trying to copy a redis database from one machine (M1) to another (M2). Both machines work with the same version of redis. That's what I'm doing: -

  • In M1 print "save". As far as I understand, this creates a temporary disk file of my data set. Based on my configuration file (redis.conf), this is written to a file called "dump.rdb".

  • In M2, I end the redis command and delete the dump.rdb file on this computer. Then I copy dump.rdb from M1 -> M2 (to the expected location specified in M2 redis.conf) and restart the redis instance on M2.

When issuing some hgetall requests, there are no entries on the M2 redis instance. Repeating the same result on M1 gives the expected and correct result.

What am I doing wrong?

+4
source share
4 answers

You are not doing anything wrong at a higher level. You are probably mistaken inadvertently ... make sure the files have the same amount of MD5 after copying them. Make sure the second Redis is configured to use dump.rdb as its save method, not AOF. Read the Redis log to see if it reads the database file. How do you use the same database number? Your data may be stored in DB5, but are you querying DB0?

+3
source

I had the same problem. In the end, I realized that the redis instance with which I copied dump.rdb was running on 2.4.x, but the destination redis instance was running 2.2.x. When the 2.2.x instance was started, there were no warnings that the rdb file could not be read. But DBSIZE , INFO , KEYS * etc. All indicated an empty database.

As soon as I upgraded the second instance to 2.4.x, I was able to open the database as expected. I know that you have already stated that your machines work with the same version, but I wanted to add this here to make sure that others know that they will see the same symptoms if they have inappropriate versions.

+2
source

I would recommend you use redis-dump to backup and restore redis

The following is the use:

  $ redis-dump $ redis-dump -u 127.0.0.1:6371 > db_full.json $ redis-dump -u 127.0.0.1:6371 -d 15 > db_db15.json $ < db_full.json redis-load $ < db_db15.json redis-load -d 15 

To install redis-dump:

  $ gem install redis-dump 
+1
source

Since redis 2.6, there is also a MIGRATE statement, which you can run with the COPY option:

MIGRATE

I thought I mention this function because sometimes you may need to copy only part of the data.

I would not use it for a complete database dump and loading, the methods already mentioned are better suited for this scenario.

0
source

Source: https://habr.com/ru/post/1439976/


All Articles