Redis is empty after startup, altough there is an .rdb file

℡╲_俬逩灬. 提交于 2020-12-31 05:37:37

问题


After I ran "shutdown save" in my redis-cli, waited for the "save" command to finish (followed the redis log) and backed up my redis .rdb file, I tried starting the redis server from the begining and it was started with an empty DB (dbsize =0!!!).

What can I do ? How can I restore my redis from the .rdb file?


回答1:


I'd recommend checking the following things:

  1. In your configuration file, check to see that the dir and dbfilename properties reflect the disk location and filename at which you would expect to find the .rdb file (and of course verify that the correct .rdb file is at the expected path).

  2. In your server logs, when starting up the Redis service, see if you see a log message similar to DB loaded from disk: x.xxx seconds appearing. If the message doesn't appear, or if the message appears with something very close to 0.000 seconds (which is probably not a reasonable expectation runtime for loading an 11 GB .rdb file from disk), then that may be another hint that your configuration isn't looking for the .rdb file in the right place.




回答2:


The problem was indeed in my configuration file. I saved my .rdb file called tal.rdb as old-tal.rdb so it won't be effected. Then, I've started my Redis server again, saw it has 0 keys, inserted 10000 keys and ran the save"command and, as a result, I saw it has created a file dump.rdb (the default dbfilename for Redis .rdb files) in the correct directory path, although in the configuration file the dbfilename was tal.rdb, so I understand my configuration file was bad. To fix this, I replaced the configuration file with a backed up file and restarted my Redis with a copy of tal.rdb and then it was started correctly (10M keys). Thanks everyone!




回答3:


I got the same problem. "Db loaded in 0.000 second " .and Key * shows empty list.

For resolving this issue

  1. Created a backup of dump.rdb file.
  2. Stop the server.
  3. Removed the dump.rdb file from redis/dump.rdb .
  4. Copy the backup to the redis folder

    sudo cp dump.rdb /etc/redis/dump.rdb

  5. Restart the server

    127.0.0.1:6379>KEYS *

It Works.




回答4:


I had the same problem in server migration. I checked dir and dbfilename directives in redis.conf too many times but it didn't load the keys. To my experience, in server migration this steps should be passed in order:

  1. Dump keys in source server (use save command)
  2. Dump keys in destination server
  3. Exchange *.rdb file in destination server with the one exported in source server.
  4. Reset redis service in destination.

Don't forget step 2.

CAUTION: Step 3 will remove your keys in destination server, these steps are just for server migration.

Don't forget to check dbfilename and dir directives in redis.conf.



来源:https://stackoverflow.com/questions/28048545/redis-is-empty-after-startup-altough-there-is-an-rdb-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!