• Stars
    star
    795
  • Rank 57,274 (Top 2 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 14 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Backup and restore your Redis data to and from JSON.

Redis-Dump v0.4 BETA

Backup and restore your Redis data to and from JSON.

NOTE: This is beta software. TEST IT BEFORE RELYING ON IT.

Usage

There are two executables: redis-dump and redis-load.

$ 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
# OR
$ cat db_full | redis-load
$ cat db_db15.json | redis-load -d 15

# You can specify the redis URI via an environment variable
$ export REDIS_URI=127.0.0.1:6371
$ redis-dump

# If your instance uses a password (such as on RedisToGo), you
# can specify the Redis URL as such:
# :<password>@<domain>:<port>
# Note the leading colon is important for specifying no username.
$ redis-dump -u :[email protected]:9055

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:

{"db":0,"key":"hashkey","ttl":-1,"type":"hash","value":{"field_a":"value_a","field_b":"value_b","field_c":"value_c"},"size":42}
{"db":0,"key":"listkey","ttl":-1,"type":"list","value":["value_0","value_1","value_2","value_0","value_1","value_2"],"size":42}
{"db":0,"key":"setkey","ttl":-1,"type":"set","value":["value_2","value_0","value_1","value_3"],"size":28}
{"db":0,"key":"zsetkey","ttl":-1,"type":"zset","value":[["value_0","100"],["value_1","100"],["value_2","200"],["value_3","300"],["value_4","400"]],"size":50}
{"db":0,"key":"stringkey","ttl":79,"type":"string","value":"stringvalue","size":11}

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](www.gnupg.org/) and file descriptors. Here are a couple examples:

# Encrypt the data (interactive)
$ redis-dump -u 127.0.0.1:6371 -d 15 | gpg --force-mdc -v -c > path/2/backup-db15.json.gpg

# Encrypt the data (automated)
$ redis-dump -u 127.0.0.1:6371 -d 15 | 3</path/2/passphrase.txt gpg --force-mdc -v -c --passphrase-fd 3 > path/2/backup-db15.json.gpg

# Decrypt the file (interactive)
$ gpg path/2/backup-db15.json.gpg
Enter passphrase: *******

# Decrypt the file (automated)
$  3</path/2/passphrase.txt gpg --passphrase-fd 3 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!

Installation

$ gem install redis-dump

Or of you want to run it directly:

$ git clone https://github.com/delano/redis-dump.git
$ cd redis-dump
$ gem install redis
$ gem install uri-redis
$ gem install yajl-ruby
$ gem install drydock
$ ruby -r rubygems bin/redis-dump

More Info

Credits

Thanks

  • antirez and the funky redis bunch!

More Repositories

1

rye

Safe, parallel access to Unix shells from Ruby
Ruby
232
star
2

gibbler

Implementation-agnostic git-like hashes and history for Ruby objects
Ruby
146
star
3

storable

Marshal Ruby classes into and out of multiple formats (yaml, json, csv, tsv)
Ruby
31
star
4

scruffy

An unofficial fork of the Ruby graphing library with sexy defaults for hi-res charts. (NOT MAINTAINED)
Ruby
31
star
5

sysinfo

All your system-independent infoz in one handy (Ruby) class
Ruby
23
star
6

otto

Auto-define your rack-apps in plaintext.
Ruby
19
star
7

tryouts

Ruby tests that read like documentation.
Ruby
19
star
8

net-scp

Pure Ruby implementation of the SCP protocol
Ruby
15
star
9

caesars

Rapid and delicious DSL prototyping in Ruby (NOT MAINTAINED)
Ruby
14
star
10

benelux

A mad timeline for your Ruby codes.
Ruby
6
star
11

attic

A place for Ruby objects to hide instance variables
Ruby
5
star
12

delano.github.com

I'm ❤️ building healthy, high-performing teams.
HTML
4
star
13

bluth

A simple queuing system built on Redis (with worker and scheduler daemons!)
Ruby
4
star
14

saxony

Parse gigantic XML files with pleasure and without running out of memory. (NOT MAINTAINED)
Ruby
3
star
15

uri-redis

URI support for Redis connection settings
Ruby
3
star
16

jerkstore

A database alternative for mostly-read applications NOT MAINTAINED
Ruby
3
star
17

hexoid

Generate Ruby style object ids
Ruby
3
star
18

insults

An insulting Ruby library.
Ruby
2
star
19

familia

A little help with Redis.
Ruby
2
star
20

data-all

A Perl module that provides access to data in many formats from many places
Perl
2
star
21

mrbelvedere

Basic operational stats for web apps. IN PROGRESS
Ruby
2
star
22

delanotes

The Delano Entertainment System
Ruby
2
star
23

annoy

Like your annoying friend that asks you questions all the time.
Ruby
2
star