问题
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:
In your configuration file, check to see that the
dir
anddbfilename
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).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 to0.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
- Created a backup of dump.rdb file.
- Stop the server.
- Removed the dump.rdb file from redis/dump.rdb .
Copy the backup to the redis folder
sudo cp dump.rdb /etc/redis/dump.rdb
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:
- Dump keys in source server (use save command)
- Dump keys in destination server
- Exchange *.rdb file in destination server with the one exported in source server.
- 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