redis-rdb-tools icon indicating copy to clipboard operation
redis-rdb-tools copied to clipboard

Provide a way to restore a subset of keys into a running redis server from a RDB File

Open sripathikrishnan opened this issue 6 years ago • 3 comments

Very often, due to application bugs, teams lose or corrupt a subset of data within redis. For example, someone may have accidentally deleted some keys or would have run the wrong command.

There are a few ways to recover data in such cases - a) replaying AOF file after removing the offending command, or b) Restore an older RDB. Replaying the AOF is not always possible, because many cloud providers do not expose the AOF file, and not everyone has AOF enabled. Restoring an older RDB requires developers to spin up a new redis instance and then selectively copy data from the new instance to the existing instance with corrupted data.

This issue proposes another alternative - generating a stream of RESTORE commands. Developers can apply any of the existing filters to select a subset of keys from the RDB file, and then rdbtools will generate appropriate RESTORE commands. We should avoid connecting to redis servers directly. Instead, we should generate a stream of commands, and let the user pipe it to redis server using redis-cli.

Proposed syntax - rdb --c restore /var/redis/6379/dump.rdb

To restore specific key pattern to a redis server running on localhost rdb --c restore --key "users:.*" dump.rdb | redis-cli --pipe

By default, we will fail if the key already exists. We can pass the --force flag to replace existing keys. This will pass the REPLACE flag when invoking the restore command.

sripathikrishnan avatar Jun 21 '18 13:06 sripathikrishnan

@oranagra FYI - I'm working on this feature request, should have a pull request in a couple of days

sripathikrishnan avatar Jun 21 '18 13:06 sripathikrishnan

great.. i was waiting for a chance we'll add that feature to rdbtools. p.s. you may want to take a look at these: https://github.com/happybits/redisimp https://github.com/antirez/redis/pull/5045

oranagra avatar Jun 21 '18 14:06 oranagra

Thanks for such a great tool. Just sharing that if one is in needs of an immediate way to restore a subset of keys from an rdb file it can be achieved with this approach

rdb --command protocol --key "happybits:*" some_dump.rdb | redis-cli --pipe

pfcarrier avatar Oct 17 '19 23:10 pfcarrier