bzo
bzo

Reputation: 1624

redis database restore shows no records

Hope this is a simple question:

I'm trying to copy a redis database from one machine (M1) to another (M2). Both machines running the same version of redis. Here's what I do :-

  1. On M1, issue a "save". As far as I understand, this creates a point in time disk file of my dataset. Based on my config file (redis.conf), this writes to a file called "dump.rdb".

  2. On M2 I shutdown redis and remove the dump.rdb file on that machine. I then copy the dump.rdb from M1-->M2 (to the expected location as specified in M2's redis.conf) and restart the redis instance on M2.

On issuing some "hgetall" queries on the M2 redis instance, no records are there. Repeating the same on M1 gives the expected and correct result.

What am I doing wrong ?

Upvotes: 4

Views: 1189

Answers (4)

Tw Bert
Tw Bert

Reputation: 3809

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

MIGRATE

I thought I'd mention this feature, because sometimes you may want to copy only part of the data.

I wouldn't use it for a complete database dump and load, the methods already mentioned are better for that scenario.

Upvotes: 0

Joshua Flanagan
Joshua Flanagan

Reputation: 8557

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

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

Upvotes: 2

antirez
antirez

Reputation: 18514

You aren't doing anything wrong at the higher level. Probably you are making some mistake unintentionally... make sure that the files have the same MD5 sum after they are copied. Make sure that the second Redis is configured to use dump.rdb as persistence method and not the AOF. Read the Redis log to check if it reads the database file. As you also using the same database number? Maybe your data is stored on DB5 but you are querying DB0?

Upvotes: 3

Anshu
Anshu

Reputation: 7853

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

Following is the usage:

    $ 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

Upvotes: 1

Related Questions