[NoSQL Redis] redis-dump: Backup and restore your Redis data to and from JSON
redis-dump
Backup and restore your Redis data to and from JSON.
Installation
1 | gem install redis-dump |
Or of you want to run it directly:
1 | git clone https://github.com/delano/redis-dump.git |
Usage
There are two executables: redis-dump
and redis-load
.
1 | redis-dump |
Output format
All redis datatypes are output to a simple JSON object. All objects have the following 5 fields:
-
db (Integer)
-
key (String)
-
ttl (Integer): The amount of time in seconds that the key will live. If no expire is set, it’s -1.
-
type (String), one of: string, list, set, zset, hash, none.
-
value (String): A JSON-encoded string. For keys of type list, set, zset, and hash, the data is given a specific structure (see below).
Here are examples of each datatype:
1 | {"db":0,"key":"hashkey","ttl":-1,"type":"hash","value":{"field_a":"value_a","field_b":"value_b","field_c":"value_c"},"size":42} |
Important note about TTLs
One of the purposes of redis-dump is the ability to restore the database to a known state. When you restore a redis database from a redis-dump file, the expires are reset to their values at the time the dump was created. This is different from restoring from Redis’ native .rdb
or .aof
files (expires are stored relative to the actual time they were set).
Output directly to an encrypted file
For most sensitive data, you should consider encrypting the data directly without writing first to a temp file. You can do this using the power of gpg and file descriptors. Here are a couple examples:
Encrypt the data (interactive)
1 | redis-dump -u 127.0.0.1:6371 -d 15 | gpg --force-mdc -v -c > path/2/backup-db15.json.gpg |
Loading data with binary strings
If you have binary or serialized data in your Redis database, the YAJL parser may not load your dump file because it sees some of the binary data as ‘invalid bytes in UTF8 string’. If you are certain that your data is binary and not malformed UTF8, you can use the -n flag to redis-load to tell YAJL to not check the input for UTF8 validity. Use with caution!
References
[2] redis-dump | RubyGems.org | your community gem host - https://rubygems.org/gems/redis-dump/