redis-dump 0.3.6 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.pre-commit-config.yaml +69 -0
- data/.rubocop.yml +13 -0
- data/CHANGES.txt +25 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +76 -0
- data/LICENSE.txt +7 -5
- data/README.md +82 -0
- data/Rakefile +5 -56
- data/{bin → exe}/redis-dump +25 -15
- data/{bin → exe}/redis-load +19 -13
- data/lib/redis/dump/version.rb +7 -0
- data/lib/redis/dump.rb +48 -42
- data/redis-dump.gemspec +23 -0
- data/sig/redis/dump.rbs +6 -0
- data/try/10_redis_dump_try.rb +17 -12
- data/try/20_dump_specific_keys_try.rb +7 -11
- data/try/30_dump_base64_try.rb +52 -0
- data/try/redis.conf +3 -3
- metadata +27 -110
- checksums.yaml.gz.sig +0 -0
- data/README.rdoc +0 -107
- data/VERSION +0 -1
- data.tar.gz.sig +0 -1
- metadata.gz.sig +0 -1
- /data/{bin → exe}/redis-report +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bd6bb93f7ba8bf8297d3c1726ac91eda76d0f230a36cedf730d90bbdf815ab5f
|
4
|
+
data.tar.gz: 31993502c019c5723073dcf1e3c0b0d2dbf187a1657d396261e0506a1870506f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e448efa86667cd48563fd1e50df277c686c963156db5465e17e333b542a04267b730c640ec96ed1323a1bd9378c252383890359bda11f89c6b973cafc84267d2
|
7
|
+
data.tar.gz: 0ce386d440465041cc33f5a52a079272ad2c11080e757690887e46a3e3e944fa405065d0ab73063fe9666386be52a7ecf27e0835e277b2f0451387ae31aa8381
|
@@ -0,0 +1,69 @@
|
|
1
|
+
##
|
2
|
+
# Pre-Commit Configuration
|
3
|
+
#
|
4
|
+
# Initial setup:
|
5
|
+
#
|
6
|
+
# 0. Install the pre-commit framework (if it isn't already on your system):
|
7
|
+
|
8
|
+
# $ pip install pre-commit
|
9
|
+
#
|
10
|
+
# 1. Install the git hook:
|
11
|
+
#
|
12
|
+
# $ pre-commit install
|
13
|
+
#
|
14
|
+
#
|
15
|
+
# Other commands:
|
16
|
+
#
|
17
|
+
# Run it on all the files in this repo:
|
18
|
+
# $ pre-commit run --all-files
|
19
|
+
#
|
20
|
+
# Updating plugin repositories:
|
21
|
+
# $ pre-commit autoupdate
|
22
|
+
#
|
23
|
+
# Automatically enable pre-commit on repositories
|
24
|
+
# $ git config --global init.templateDir ~/.git-template
|
25
|
+
# $ pre-commit init-templatedir ~/.git-template
|
26
|
+
#
|
27
|
+
# See also:
|
28
|
+
# - https://pre-commit.com for more information
|
29
|
+
# - https://pre-commit.com/hooks.html for more hooks
|
30
|
+
#
|
31
|
+
|
32
|
+
default_install_hook_types:
|
33
|
+
- pre-commit
|
34
|
+
- prepare-commit-msg
|
35
|
+
|
36
|
+
fail_fast: true
|
37
|
+
|
38
|
+
repos:
|
39
|
+
- repo: meta
|
40
|
+
hooks:
|
41
|
+
- id: check-hooks-apply
|
42
|
+
- id: check-useless-excludes
|
43
|
+
- id: identity
|
44
|
+
|
45
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
46
|
+
rev: v4.6.0
|
47
|
+
hooks:
|
48
|
+
- id: trailing-whitespace
|
49
|
+
- id: end-of-file-fixer
|
50
|
+
- id: check-yaml
|
51
|
+
- id: detect-private-key
|
52
|
+
- id: mixed-line-ending
|
53
|
+
- id: check-added-large-files
|
54
|
+
args: ["--maxkb=1000"]
|
55
|
+
- id: no-commit-to-branch
|
56
|
+
args: ["--branch", "develop", "--branch", "rel/.*"]
|
57
|
+
- id: check-merge-conflict
|
58
|
+
- id: forbid-submodules
|
59
|
+
|
60
|
+
- repo: https://github.com/avilaton/add-msg-issue-prefix-hook
|
61
|
+
rev: v0.0.11
|
62
|
+
hooks:
|
63
|
+
- id: add-msg-issue-prefix
|
64
|
+
stages: [prepare-commit-msg]
|
65
|
+
name: Link commit to Github issue
|
66
|
+
args:
|
67
|
+
- "--default=[NOJIRA]"
|
68
|
+
- "--pattern=[a-zA-Z0-9]{0,10}-?[0-9]{1,5}"
|
69
|
+
- "--template=[#{}]"
|
data/.rubocop.yml
ADDED
data/CHANGES.txt
CHANGED
@@ -1,5 +1,30 @@
|
|
1
1
|
REDIS-DUMP, CHANGES
|
2
2
|
|
3
|
+
#### 0.6.0 (2024-06-17) ###############################
|
4
|
+
|
5
|
+
* ADDED: Supports redis-rb 5.0
|
6
|
+
* ADDED: Supports SSL via rediss://
|
7
|
+
* CHANGED: Updated dependencies (see https://github.com/delano/redis-dump/pull/37)
|
8
|
+
* FIXED: Resolved `sadd` warnings in redis 4.0 #35
|
9
|
+
|
10
|
+
|
11
|
+
#### 0.5.0 (2023-01-17) ###############################
|
12
|
+
|
13
|
+
* ADDED: Timeout support for redis connections
|
14
|
+
* CHANGED: uri-redis dependency to 1.0.0
|
15
|
+
|
16
|
+
|
17
|
+
#### 0.4.0 (2017-11-23) ###############################
|
18
|
+
|
19
|
+
* ADDED: support for redis >= 4.0
|
20
|
+
* ADDED: support for base64 encoded string keys
|
21
|
+
* FIXED: redis passwords with special characters
|
22
|
+
|
23
|
+
|
24
|
+
#### 0.3.6 (2017-11-09) ###############################
|
25
|
+
|
26
|
+
* FIXED: redis < 4.0 dependency [Clemens Fuchslocher]
|
27
|
+
|
3
28
|
#### 0.3.5 (2013-02-07) ###############################
|
4
29
|
|
5
30
|
* Array#select fix for Ruby 1.8 [TIT]
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "drydock", ">= 0.6.9"
|
6
|
+
gem "oj", ">= 3.16.4"
|
7
|
+
gem "redis", ">= 4.0", "< 6.0"
|
8
|
+
gem "uri-redis", ">= 1.3.0"
|
9
|
+
gem "yajl-ruby", ">= 1.4.3"
|
10
|
+
|
11
|
+
gem "pry-byebug", "~> 3.10.1", require: false, group: :development
|
12
|
+
gem "rake", "~> 13.0", require: false, group: :development
|
13
|
+
gem "rubocop", "~> 1.64.1", require: false, group: :development
|
14
|
+
gem "tryouts", "~> 2.2.0", require: false, group: :development
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
ast (2.4.2)
|
5
|
+
bigdecimal (3.1.8)
|
6
|
+
byebug (11.1.3)
|
7
|
+
coderay (1.1.3)
|
8
|
+
connection_pool (2.4.1)
|
9
|
+
drydock (0.6.9)
|
10
|
+
json (2.7.2)
|
11
|
+
language_server-protocol (3.17.0.3)
|
12
|
+
method_source (1.1.0)
|
13
|
+
oj (3.16.4)
|
14
|
+
bigdecimal (>= 3.0)
|
15
|
+
parallel (1.25.1)
|
16
|
+
parser (3.3.3.0)
|
17
|
+
ast (~> 2.4.1)
|
18
|
+
racc
|
19
|
+
pry (0.14.2)
|
20
|
+
coderay (~> 1.1)
|
21
|
+
method_source (~> 1.0)
|
22
|
+
pry-byebug (3.10.1)
|
23
|
+
byebug (~> 11.0)
|
24
|
+
pry (>= 0.13, < 0.15)
|
25
|
+
racc (1.8.0)
|
26
|
+
rainbow (3.1.1)
|
27
|
+
rake (13.2.1)
|
28
|
+
redis (5.2.0)
|
29
|
+
redis-client (>= 0.22.0)
|
30
|
+
redis-client (0.22.2)
|
31
|
+
connection_pool
|
32
|
+
regexp_parser (2.9.2)
|
33
|
+
rexml (3.3.0)
|
34
|
+
strscan
|
35
|
+
rubocop (1.64.1)
|
36
|
+
json (~> 2.3)
|
37
|
+
language_server-protocol (>= 3.17.0)
|
38
|
+
parallel (~> 1.10)
|
39
|
+
parser (>= 3.3.0.2)
|
40
|
+
rainbow (>= 2.2.2, < 4.0)
|
41
|
+
regexp_parser (>= 1.8, < 3.0)
|
42
|
+
rexml (>= 3.2.5, < 4.0)
|
43
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
44
|
+
ruby-progressbar (~> 1.7)
|
45
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
46
|
+
rubocop-ast (1.31.3)
|
47
|
+
parser (>= 3.3.1.0)
|
48
|
+
ruby-progressbar (1.13.0)
|
49
|
+
storable (0.10.0)
|
50
|
+
strscan (3.1.0)
|
51
|
+
sysinfo (0.10.0)
|
52
|
+
drydock (< 1.0)
|
53
|
+
storable (~> 0.10)
|
54
|
+
tryouts (2.2.0)
|
55
|
+
sysinfo (~> 0.10)
|
56
|
+
unicode-display_width (2.5.0)
|
57
|
+
uri-redis (1.3.0)
|
58
|
+
yajl-ruby (1.4.3)
|
59
|
+
|
60
|
+
PLATFORMS
|
61
|
+
arm64-darwin-22
|
62
|
+
ruby
|
63
|
+
|
64
|
+
DEPENDENCIES
|
65
|
+
drydock (>= 0.6.9)
|
66
|
+
oj (>= 3.16.4)
|
67
|
+
pry-byebug (~> 3.10.1)
|
68
|
+
rake (~> 13.0)
|
69
|
+
redis (>= 4.0, < 6.0)
|
70
|
+
rubocop (~> 1.64.1)
|
71
|
+
tryouts (~> 2.2.0)
|
72
|
+
uri-redis (>= 1.3.0)
|
73
|
+
yajl-ruby (>= 1.4.3)
|
74
|
+
|
75
|
+
BUNDLED WITH
|
76
|
+
2.5.9
|
data/LICENSE.txt
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2010-2024 Delano Mandelbaum
|
2
4
|
|
3
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
6
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -7,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
9
|
copies of the Software, and to permit persons to whom the Software is
|
8
10
|
furnished to do so, subject to the following conditions:
|
9
11
|
|
10
|
-
The above copyright notice and this permission notice shall be included in
|
11
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
12
14
|
|
13
15
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
16
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
17
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Redis::Dump - v0.6
|
2
|
+
|
3
|
+
*Redis to JSON and back again. Dump and load Redis databases to/from JSON files.*
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
One of:
|
9
|
+
1. Gemfile: `gem 'redis-dump', '~> 0.4.0'`
|
10
|
+
2. Install manually: `gem install redis-dump`
|
11
|
+
3. Clone with git: `git clone git@github.com:delano/redis-dump.git`
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
There are two executables: `redis-dump` and `redis-load`.
|
18
|
+
|
19
|
+
```bash
|
20
|
+
$ redis-dump
|
21
|
+
$ redis-dump -u 127.0.0.1:6379 > db_full.json
|
22
|
+
$ redis-dump -u 127.0.0.1:6379 -d 15 > db_db15.json
|
23
|
+
|
24
|
+
$ < db_full.json redis-load
|
25
|
+
$ < db_db15.json redis-load -d 15
|
26
|
+
# OR
|
27
|
+
$ cat db_full | redis-load
|
28
|
+
$ cat db_db15.json | redis-load -d 15
|
29
|
+
|
30
|
+
# You can specify the redis URI via an environment variable
|
31
|
+
$ export REDIS_URI=127.0.0.1:6379
|
32
|
+
$ redis-dump
|
33
|
+
|
34
|
+
# If your instance uses a password (such as on RedisToGo), you
|
35
|
+
# can specify the Redis URL as such:
|
36
|
+
# :<password>@<domain>:<port>
|
37
|
+
# Note the leading colon is important for specifying no username.
|
38
|
+
$ redis-dump -u :234288a830f009980e08@example.redistogo.com:9055
|
39
|
+
```
|
40
|
+
|
41
|
+
### Output format
|
42
|
+
|
43
|
+
All redis datatypes are output to a simple JSON object. All objects have the following 5 fields:
|
44
|
+
|
45
|
+
* db (Integer)
|
46
|
+
* key (String)
|
47
|
+
* ttl (Integer): The amount of time in seconds that the key will live. If no expire is set, it's -1.
|
48
|
+
* type (String), one of: string, list, set, zset, hash, none.
|
49
|
+
* value (String): A JSON-encoded string. For keys of type list, set, zset, and hash, the data is given a specific structure (see below).
|
50
|
+
|
51
|
+
Here are examples of each datatype:
|
52
|
+
|
53
|
+
```json
|
54
|
+
{"db":0,"key":"hashkey","ttl":-1,"type":"hash","value":{"field_a":"value_a","field_b":"value_b","field_c":"value_c"},"size":42}
|
55
|
+
{"db":0,"key":"listkey","ttl":-1,"type":"list","value":["value_0","value_1","value_2","value_0","value_1","value_2"],"size":42}
|
56
|
+
{"db":0,"key":"setkey","ttl":-1,"type":"set","value":["value_2","value_0","value_1","value_3"],"size":28}
|
57
|
+
{"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}
|
58
|
+
{"db":0,"key":"stringkey","ttl":79,"type":"string","value":"stringvalue","size":11}
|
59
|
+
```
|
60
|
+
|
61
|
+
## Important notes
|
62
|
+
|
63
|
+
### About TTLs
|
64
|
+
|
65
|
+
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).
|
66
|
+
|
67
|
+
### Output directly to an encrypted file
|
68
|
+
|
69
|
+
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](http://www.gnupg.org/) and file descriptors. Here are a couple examples:
|
70
|
+
|
71
|
+
```bash
|
72
|
+
# Encrypt the data (interactive)
|
73
|
+
$ redis-dump -u 127.0.0.1:6379 -d 15 | gpg --force-mdc -v -c > path/2/backup-db1
|
74
|
+
```
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/delano/redis-dump.
|
79
|
+
|
80
|
+
## License
|
81
|
+
|
82
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -1,59 +1,8 @@
|
|
1
|
-
|
2
|
-
require "rake"
|
3
|
-
require "rake/clean"
|
4
|
-
require "rdoc/task"
|
1
|
+
# frozen_string_literal: true
|
5
2
|
|
6
|
-
|
7
|
-
|
8
|
-
name = "redis-dump"
|
9
|
-
|
10
|
-
$:.unshift File.join(File.dirname(__FILE__), 'lib')
|
11
|
-
require "redis/dump"
|
12
|
-
version = Redis::Dump::VERSION.to_s
|
13
|
-
|
14
|
-
begin
|
15
|
-
require "jeweler"
|
16
|
-
Jeweler::Tasks.new do |s|
|
17
|
-
s.version = version
|
18
|
-
s.name = name
|
19
|
-
s.summary = "Backup and restore your Redis data to and from JSON."
|
20
|
-
s.description = s.summary
|
21
|
-
s.email = "delano@solutious.com"
|
22
|
-
s.homepage = "http://github.com/delano/redis-dump"
|
23
|
-
s.authors = ["Delano Mandelbaum"]
|
24
|
-
|
25
|
-
s.add_dependency("yajl-ruby", ">= 0.1")
|
26
|
-
s.add_dependency("redis", ">= 2.0", "< 4.0")
|
27
|
-
s.add_dependency("uri-redis", ">= 0.4.0")
|
28
|
-
s.add_dependency("drydock", ">= 0.6.9")
|
29
|
-
|
30
|
-
s.license = "MIT"
|
31
|
-
|
32
|
-
s.signing_key = File.join('/mnt/gem/', 'gem-private_key.pem')
|
33
|
-
s.cert_chain = ['gem-public_cert.pem']
|
34
|
-
end
|
35
|
-
Jeweler::GemcutterTasks.new
|
36
|
-
rescue LoadError
|
37
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
38
|
-
end
|
39
|
-
|
40
|
-
require 'rake/testtask'
|
41
|
-
Rake::TestTask.new do |t|
|
42
|
-
t.libs = ["lib", "test"]
|
43
|
-
end
|
44
|
-
|
45
|
-
extra_files = %w[LICENSE.txt THANKS.txt CHANGES.txt ]
|
46
|
-
RDoc::Task.new do |rdoc|
|
47
|
-
rdoc.rdoc_dir = "rdoc"
|
48
|
-
rdoc.title = "#{name} #{version}"
|
49
|
-
rdoc.generator = 'hanna' # gem install hanna-nouveau
|
50
|
-
rdoc.main = 'README.rdoc'
|
51
|
-
rdoc.rdoc_files.include("README*")
|
52
|
-
rdoc.rdoc_files.include("bin/*.rb")
|
53
|
-
rdoc.rdoc_files.include("lib/**/*.rb")
|
54
|
-
extra_files.each { |file|
|
55
|
-
rdoc.rdoc_files.include(file) if File.exists?(file)
|
56
|
-
}
|
57
|
-
end
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rubocop/rake_task"
|
58
5
|
|
6
|
+
RuboCop::RakeTask.new
|
59
7
|
|
8
|
+
task default: :rubocop
|
data/{bin → exe}/redis-dump
RENAMED
@@ -1,10 +1,10 @@
|
|
1
|
-
#!/usr/bin/ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# = Redis-Dump
|
4
|
-
#
|
4
|
+
#
|
5
5
|
#
|
6
6
|
# Usage:
|
7
|
-
#
|
7
|
+
#
|
8
8
|
# $ redis-dump -h
|
9
9
|
# $ redis-dump > dumpfile_full.json
|
10
10
|
# $ redis-dump -d 15 > dumpfile_db15.json
|
@@ -13,7 +13,7 @@
|
|
13
13
|
|
14
14
|
RD_HOME = File.expand_path File.join(File.dirname(__FILE__), '..')
|
15
15
|
lib_dir = File.join(RD_HOME, 'lib')
|
16
|
-
$:.unshift lib_dir
|
16
|
+
$:.unshift lib_dir
|
17
17
|
|
18
18
|
require 'redis/dump'
|
19
19
|
require 'drydock'
|
@@ -21,17 +21,28 @@ require 'drydock'
|
|
21
21
|
# Command-line interface for bin/redis-dump
|
22
22
|
class Redis::Dump::CLI
|
23
23
|
extend Drydock
|
24
|
-
|
24
|
+
|
25
25
|
default :dump
|
26
26
|
trawler :dump
|
27
|
-
|
27
|
+
|
28
28
|
global :u, :uri, String, "Redis URI (e.g. redis://hostname[:port])"
|
29
29
|
global :d, :database, Integer, "Redis database (e.g. -d 15)"
|
30
|
+
global :a, :password, String, "Redis password (e.g. -a 'my@pass/word')" do |v|
|
31
|
+
Redis::Dump.password = v
|
32
|
+
end
|
33
|
+
global :t, :timeout, Integer, "Configure connect, read, and write timeouts (ruby redis client)" do |t|
|
34
|
+
Redis::Dump.timeout = t
|
35
|
+
end
|
30
36
|
global :s, :sleep, Integer, "Sleep for S seconds after dumping (for debugging)"
|
31
37
|
global :c, :count, Integer, "Chunk size (default: #{Redis::Dump.chunk_size})"
|
32
38
|
global :f, :filter, String, "Filter selected keys (passed directly to redis' KEYS command)"
|
33
|
-
global :
|
34
|
-
|
39
|
+
global :b, :base64, "Encode key values as base64 (useful for binary values)" do
|
40
|
+
Redis::Dump.with_base64 = true
|
41
|
+
end
|
42
|
+
global :O, :without_optimizations, "Disable run time optimizations" do
|
43
|
+
Redis::Dump.with_optimizations = false
|
44
|
+
end
|
45
|
+
global :V, :version, "Display version" do
|
35
46
|
puts "redis-dump v#{Redis::Dump::VERSION.to_s}"
|
36
47
|
exit 0
|
37
48
|
end
|
@@ -41,24 +52,23 @@ class Redis::Dump::CLI
|
|
41
52
|
global :nosafe do
|
42
53
|
Redis::Dump.safe = false
|
43
54
|
end
|
44
|
-
|
55
|
+
|
45
56
|
before do |obj|
|
46
57
|
obj.global.uri ||= ENV['REDIS_URI']
|
47
58
|
obj.global.uri ||= 'redis://%s:%s' % [Redis::Dump.host, Redis::Dump.port]
|
48
59
|
obj.global.uri = 'redis://' << obj.global.uri unless obj.global.uri.match(/^redis:\/\//)
|
49
60
|
obj.global.database &&= obj.global.database.to_i
|
50
61
|
obj.global.database ||= (0..15)
|
51
|
-
Redis::Dump.with_optimizations = false if obj.global.without_optimizations
|
52
62
|
Redis::Dump.chunk_size = obj.global.count if obj.global.count
|
53
63
|
Redis::Dump.ld "redis_uri: #{obj.global.uri} (#{obj.global.database})"
|
54
64
|
Redis::Dump.ld "Process: #{$$}; Memory: #{Redis::Dump.memory_usage}" if Redis::Dump.debug
|
55
65
|
end
|
56
|
-
|
66
|
+
|
57
67
|
after do |obj|
|
58
68
|
Redis::Dump.ld "Process: #{$$}; Memory: #{Redis::Dump.memory_usage}" if Redis::Dump.debug
|
59
69
|
sleep obj.global.sleep.to_i if obj.global.sleep
|
60
70
|
end
|
61
|
-
|
71
|
+
|
62
72
|
usage "redis-dump > dumpfile_full.json"
|
63
73
|
usage "redis-dump -d 15 > dumpfile_db15.json"
|
64
74
|
usage "redis-dump -d 15 -c 100_000 > dumpfile_db15.json"
|
@@ -70,10 +80,10 @@ class Redis::Dump::CLI
|
|
70
80
|
puts records
|
71
81
|
end
|
72
82
|
end
|
73
|
-
|
83
|
+
|
74
84
|
end
|
75
85
|
|
76
|
-
|
86
|
+
|
77
87
|
begin
|
78
88
|
Drydock.run!(ARGV, STDIN) if Drydock.run? && !Drydock.has_run?
|
79
89
|
rescue RuntimeError => ex
|
@@ -91,4 +101,4 @@ rescue Interrupt
|
|
91
101
|
rescue => ex
|
92
102
|
STDERR.puts "ERROR (#{ex.class.to_s}): #{ex.message}"
|
93
103
|
STDERR.puts ex.backtrace if Redis::Dump.debug
|
94
|
-
end
|
104
|
+
end
|
data/{bin → exe}/redis-load
RENAMED
@@ -1,10 +1,10 @@
|
|
1
|
-
#!/usr/bin/ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# = Redis-Dump
|
4
|
-
#
|
4
|
+
#
|
5
5
|
#
|
6
6
|
# Usage:
|
7
|
-
#
|
7
|
+
#
|
8
8
|
# $ redis-load -h
|
9
9
|
# $ <dumpfile_full.json redis-load
|
10
10
|
# $ <dumpfile_db15.json redis-load -d 15
|
@@ -13,7 +13,7 @@
|
|
13
13
|
|
14
14
|
RD_HOME = File.expand_path File.join(File.dirname(__FILE__), '..')
|
15
15
|
lib_dir = File.join(RD_HOME, 'lib')
|
16
|
-
$:.unshift lib_dir
|
16
|
+
$:.unshift lib_dir
|
17
17
|
|
18
18
|
require 'redis/dump'
|
19
19
|
require 'drydock'
|
@@ -21,17 +21,23 @@ require 'drydock'
|
|
21
21
|
# Command-line interface for bin/redis-dump
|
22
22
|
class Redis::Dump::CLI
|
23
23
|
extend Drydock
|
24
|
-
|
24
|
+
|
25
25
|
default :load
|
26
26
|
trawler :load
|
27
|
-
|
27
|
+
|
28
28
|
global :u, :uri, String, "Redis URI (e.g. redis://hostname[:port])"
|
29
29
|
global :d, :database, Integer, "Redis database (e.g. -d 15)"
|
30
|
+
global :a, :password, String, "Redis password (e.g. -a 'my@pass/word')" do |v|
|
31
|
+
Redis::Dump.password = v
|
32
|
+
end
|
30
33
|
global :s, :sleep, Integer, "Sleep for S seconds after dumping (for debugging)"
|
34
|
+
global :b, :base64, "Decode key values from base64 (used with redis-dump -b)" do
|
35
|
+
Redis::Dump.with_base64 = true
|
36
|
+
end
|
31
37
|
global :n, :no_check_utf8 do
|
32
38
|
Redis::Dump.check_utf8 = false
|
33
39
|
end
|
34
|
-
global :V, :version, "Display version" do
|
40
|
+
global :V, :version, "Display version" do
|
35
41
|
puts "redis-dump v#{Redis::Dump::VERSION.to_s}"
|
36
42
|
exit 0
|
37
43
|
end
|
@@ -41,7 +47,7 @@ class Redis::Dump::CLI
|
|
41
47
|
global :nosafe do
|
42
48
|
Redis::Dump.safe = false
|
43
49
|
end
|
44
|
-
|
50
|
+
|
45
51
|
before do |obj|
|
46
52
|
obj.global.uri ||= ENV['REDIS_URI']
|
47
53
|
obj.global.uri ||= 'redis://%s:%s' % [Redis::Dump.host, Redis::Dump.port]
|
@@ -51,12 +57,12 @@ class Redis::Dump::CLI
|
|
51
57
|
Redis::Dump.ld "redis_uri: #{obj.global.uri} (#{obj.global.database})"
|
52
58
|
Redis::Dump.ld "Process: #{$$}; Memory: #{Redis::Dump.memory_usage}" if Redis::Dump.debug
|
53
59
|
end
|
54
|
-
|
60
|
+
|
55
61
|
after do |obj|
|
56
62
|
Redis::Dump.ld "Process: #{$$}; Memory: #{Redis::Dump.memory_usage}" if Redis::Dump.debug
|
57
63
|
sleep obj.global.sleep.to_i if obj.global.sleep
|
58
64
|
end
|
59
|
-
|
65
|
+
|
60
66
|
usage "<dumpfile_full.json redis-load"
|
61
67
|
usage "<dumpfile_db15.json redis-load -d 15"
|
62
68
|
command :load do |obj|
|
@@ -64,7 +70,7 @@ class Redis::Dump::CLI
|
|
64
70
|
raise "Usage: cat dumpfile_db15.json | redis-load -d 15" if STDIN.tty?
|
65
71
|
rd.load STDIN
|
66
72
|
end
|
67
|
-
|
73
|
+
|
68
74
|
about "Add test data to redis"
|
69
75
|
usage "redis-load populate -c 1000"
|
70
76
|
usage "redis-load -d 1 populate -c 1000"
|
@@ -97,7 +103,7 @@ class Redis::Dump::CLI
|
|
97
103
|
puts time.to_s
|
98
104
|
end
|
99
105
|
end
|
100
|
-
|
106
|
+
|
101
107
|
command :info do |obj|
|
102
108
|
rd = Redis::Dump.new obj.global.database, obj.global.uri
|
103
109
|
memory = nil
|
@@ -111,7 +117,7 @@ class Redis::Dump::CLI
|
|
111
117
|
end
|
112
118
|
end
|
113
119
|
|
114
|
-
|
120
|
+
|
115
121
|
begin
|
116
122
|
Drydock.run!(ARGV, STDIN) if Drydock.run? && !Drydock.has_run?
|
117
123
|
rescue RuntimeError => ex
|
data/lib/redis/dump.rb
CHANGED
@@ -1,10 +1,16 @@
|
|
1
|
+
|
2
|
+
|
1
3
|
unless defined?(RD_HOME)
|
2
4
|
RD_HOME = File.expand_path(File.join(File.dirname(__FILE__), '..', '..') )
|
3
5
|
end
|
4
6
|
|
5
7
|
require 'redis'
|
6
|
-
require 'uri/redis'
|
7
8
|
require 'yajl'
|
9
|
+
require 'base64'
|
10
|
+
|
11
|
+
require 'uri/redis'
|
12
|
+
|
13
|
+
require_relative "dump/version"
|
8
14
|
|
9
15
|
class Redis
|
10
16
|
class Dump
|
@@ -18,8 +24,9 @@ class Redis
|
|
18
24
|
@parser = Yajl::Parser.new
|
19
25
|
@chunk_size = 10000
|
20
26
|
@with_optimizations = true
|
27
|
+
@with_base64 = false
|
21
28
|
class << self
|
22
|
-
attr_accessor :debug, :encoder, :parser, :safe, :host, :port, :chunk_size, :with_optimizations
|
29
|
+
attr_accessor :debug, :encoder, :parser, :safe, :host, :port, :password, :timeout, :chunk_size, :with_optimizations, :with_base64
|
23
30
|
def le(msg)
|
24
31
|
STDERR.puts "#%.4f: %s" % [Time.now.utc.to_f, msg]
|
25
32
|
end
|
@@ -37,7 +44,7 @@ class Redis
|
|
37
44
|
end
|
38
45
|
attr_accessor :dbs, :uri
|
39
46
|
attr_reader :redis_connections
|
40
|
-
def initialize(dbs=nil,uri="redis://#{Redis::Dump.host}:#{Redis::Dump.port}")
|
47
|
+
def initialize(dbs=nil, uri="redis://#{Redis::Dump.host}:#{Redis::Dump.port}")
|
41
48
|
@redis_connections = {}
|
42
49
|
@uri = uri
|
43
50
|
unless dbs.nil?
|
@@ -50,8 +57,13 @@ class Redis
|
|
50
57
|
redis_connections["#{uri}/#{db}"] ||= connect("#{uri}/#{db}")
|
51
58
|
end
|
52
59
|
def connect(this_uri)
|
53
|
-
|
54
|
-
|
60
|
+
self.class.ld 'CONNECT: ' << this_uri
|
61
|
+
opts = {
|
62
|
+
:url => this_uri
|
63
|
+
}
|
64
|
+
opts[:password] = Redis::Dump.password if Redis::Dump.password
|
65
|
+
opts[:timeout] = Redis::Dump.timeout if Redis::Dump.timeout
|
66
|
+
Redis.new **opts
|
55
67
|
end
|
56
68
|
|
57
69
|
def each_database
|
@@ -60,23 +72,21 @@ class Redis
|
|
60
72
|
end
|
61
73
|
end
|
62
74
|
|
63
|
-
# See each_key
|
64
75
|
def dump filter=nil
|
65
76
|
filter ||= '*'
|
66
77
|
entries = []
|
67
78
|
each_database do |redis|
|
68
79
|
chunk_entries = []
|
80
|
+
Redis::Dump.ld "[db#{redis.connection[:db]}] Memory before: #{Redis::Dump.memory_usage}kb"
|
69
81
|
dump_keys = redis.keys(filter)
|
70
82
|
dump_keys_size = dump_keys.size
|
71
|
-
Redis::Dump.ld "
|
83
|
+
Redis::Dump.ld "[db#{redis.connection[:db]}] Dumping #{dump_keys_size} keys: #{dump_keys.join(', ')}"
|
72
84
|
dump_keys.each_with_index do |key,idx|
|
73
85
|
entry, idxplus = key, idx+1
|
74
|
-
#self.class.ld " #{key} (#{key_dump['type']}): #{key_dump['size'].to_bytes}"
|
75
|
-
#entry_enc = self.class.encoder.encode entry
|
76
86
|
if block_given?
|
77
87
|
chunk_entries << entry
|
78
88
|
process_chunk idx, dump_keys_size do |count|
|
79
|
-
Redis::Dump.ld " dumping #{chunk_entries.size} (#{count}) from #{redis.
|
89
|
+
Redis::Dump.ld " dumping #{chunk_entries.size} (#{count}) from #{redis.connection[:id]}"
|
80
90
|
output_buffer = []
|
81
91
|
chunk_entries = chunk_entries.select do |key|
|
82
92
|
type = Redis::Dump.type(redis, key)
|
@@ -100,6 +110,8 @@ class Redis
|
|
100
110
|
entries << self.class.encoder.encode(Redis::Dump.dump(redis, entry))
|
101
111
|
end
|
102
112
|
end
|
113
|
+
|
114
|
+
Redis::Dump.ld "[db#{redis.connection[:db]}] Memory after: #{Redis::Dump.memory_usage}kb"
|
103
115
|
end
|
104
116
|
entries
|
105
117
|
end
|
@@ -121,9 +133,9 @@ class Redis
|
|
121
133
|
entry, idxplus = Redis::Dump.report(redis, key), idx+1
|
122
134
|
chunk_entries << entry
|
123
135
|
process_chunk idx, dump_keys_size do |count|
|
124
|
-
Redis::Dump.ld " reporting on #{chunk_entries.size} (#{idxplus}) from #{redis.
|
136
|
+
Redis::Dump.ld " reporting on #{chunk_entries.size} (#{idxplus}) from #{redis.connection[:id]}"
|
125
137
|
chunk_entries.each do |e|
|
126
|
-
|
138
|
+
puts record if obj.global.verbose >= 1
|
127
139
|
dbs[e['db']] ||= 0
|
128
140
|
dbs[e['db']] += e['size']
|
129
141
|
total_size += e['size']
|
@@ -146,14 +158,20 @@ class Redis
|
|
146
158
|
next
|
147
159
|
end
|
148
160
|
this_redis = redis(obj["db"])
|
149
|
-
|
161
|
+
Redis::Dump.ld "load[#{this_redis.hash}, #{obj}]"
|
150
162
|
if each_record.nil?
|
151
163
|
if Redis::Dump.safe && this_redis.exists(obj['key'])
|
152
|
-
|
164
|
+
Redis::Dump.ld " record exists (no change)"
|
153
165
|
next
|
154
166
|
end
|
155
167
|
begin
|
156
|
-
|
168
|
+
val, type = obj['value'], obj['type']
|
169
|
+
Redis::Dump.ld " > load `#{val}`"
|
170
|
+
if Redis::Dump.with_base64 && type === 'string'
|
171
|
+
Redis::Dump.ld " > load+decode64 for `#{val}`"
|
172
|
+
val = Base64.decode64 val
|
173
|
+
end
|
174
|
+
ret = Redis::Dump.set_value this_redis, obj['key'], type, val, obj['ttl']
|
157
175
|
rescue => ex
|
158
176
|
Redis::Dump.le '(key: %s) %s' % [obj['key'], ex.message]
|
159
177
|
end
|
@@ -171,21 +189,23 @@ class Redis
|
|
171
189
|
type
|
172
190
|
end
|
173
191
|
def report(this_redis, key)
|
174
|
-
info = { 'db' => this_redis.
|
192
|
+
info = { 'db' => this_redis.connection[:db], 'key' => key }
|
175
193
|
info['type'] = type(this_redis, key)
|
176
194
|
info['size'] = stringify(this_redis, key, info['type'], info['value']).size
|
177
195
|
info['bytes'] = info['size'].to_bytes
|
178
|
-
#ld "report[#{this_redis.hash}, #{info}]"
|
179
196
|
info
|
180
197
|
end
|
181
198
|
def dump(this_redis, key, type=nil)
|
182
199
|
type ||= type(this_redis, key)
|
183
|
-
info = { 'db' => this_redis.
|
200
|
+
info = { 'db' => this_redis.connection[:db], 'key' => key }
|
184
201
|
info['ttl'] = this_redis.ttl key
|
185
202
|
info['type'] = type
|
203
|
+
stringified = stringify(this_redis, key, info['type'], info['value'])
|
186
204
|
info['value'] = value(this_redis, key, info['type'])
|
187
|
-
info['size'] =
|
188
|
-
|
205
|
+
info['size'] = stringified.size
|
206
|
+
if Redis::Dump.with_base64 && type === 'string'
|
207
|
+
info['value'] = Base64.encode64(info['value'])
|
208
|
+
end
|
189
209
|
info
|
190
210
|
end
|
191
211
|
def dump_strings(this_redis, keys)
|
@@ -193,10 +213,14 @@ class Redis
|
|
193
213
|
idx = -1
|
194
214
|
keys.collect { |key|
|
195
215
|
idx += 1
|
216
|
+
val = vals[idx].to_s
|
196
217
|
info = {
|
197
|
-
'db'
|
198
|
-
'
|
199
|
-
'
|
218
|
+
'db' => this_redis.connection[:db],
|
219
|
+
'key' => key,
|
220
|
+
'ttl' => this_redis.ttl(key),
|
221
|
+
'type' => 'string',
|
222
|
+
'value' => Redis::Dump.with_base64 ? Base64.encode64(val) : val,
|
223
|
+
'size' => vals[idx].to_s.size
|
200
224
|
}
|
201
225
|
block_given? ? yield(info) : info
|
202
226
|
}
|
@@ -220,7 +244,7 @@ class Redis
|
|
220
244
|
list.each { |value| this_redis.rpush key, value }
|
221
245
|
end
|
222
246
|
def set_value_set(this_redis, key, set)
|
223
|
-
set.each { |value| this_redis.sadd key, value }
|
247
|
+
set.each { |value| this_redis.sadd? key, value }
|
224
248
|
end
|
225
249
|
def set_value_zset(this_redis, key, zset)
|
226
250
|
zset.each { |pair| this_redis.zadd key, pair[1].to_f, pair[0] }
|
@@ -247,24 +271,6 @@ class Redis
|
|
247
271
|
end
|
248
272
|
extend Redis::Dump::ClassMethods
|
249
273
|
|
250
|
-
module VERSION
|
251
|
-
@path = File.join(RD_HOME, 'VERSION')
|
252
|
-
class << self
|
253
|
-
attr_reader :version, :path
|
254
|
-
def version
|
255
|
-
@version || read_version
|
256
|
-
end
|
257
|
-
def read_version
|
258
|
-
return if @version
|
259
|
-
@version = File.read(path).strip!
|
260
|
-
end
|
261
|
-
def prerelease?() false end
|
262
|
-
def to_a() version.split('.') end
|
263
|
-
def to_s() version end
|
264
|
-
def inspect() version end
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
274
|
class Problem < RuntimeError
|
269
275
|
def initialize(*args)
|
270
276
|
@args = args.flatten.compact
|
data/redis-dump.gemspec
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/redis/dump/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "redis-dump"
|
7
|
+
spec.version = Redis::Dump::VERSION
|
8
|
+
spec.authors = ["delano"]
|
9
|
+
spec.email = "gems@solutious.com"
|
10
|
+
|
11
|
+
spec.summary = "Backup and restore your Redis data to and from JSON."
|
12
|
+
spec.description = "Backup and restore your Redis data to and from JSON by database, key, or key pattern."
|
13
|
+
spec.homepage = "https://rubygems.org/gems/redis-dump"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.8")
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{\A(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor})
|
19
|
+
end
|
20
|
+
spec.bindir = "bin"
|
21
|
+
spec.executables = spec.files.grep(%r{\Abin/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
end
|
data/sig/redis/dump.rbs
ADDED
data/try/10_redis_dump_try.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../lib/redis/dump'
|
2
4
|
|
3
5
|
# The test instance of redis must be running:
|
4
|
-
# $ redis-server try/redis
|
6
|
+
# $ redis-server try/redis.conf
|
5
7
|
|
6
|
-
@uri_base = "redis://127.0.0.1:
|
8
|
+
@uri_base = "redis://127.0.0.1:6379"
|
7
9
|
|
8
10
|
Redis::Dump.debug = false
|
9
11
|
Redis::Dump.safe = true
|
10
12
|
|
13
|
+
|
11
14
|
## Connect to DB
|
12
15
|
@rdump = Redis::Dump.new 0, @uri_base
|
13
16
|
@rdump.redis_connections.size
|
@@ -20,7 +23,7 @@ Redis::Dump.safe = true
|
|
20
23
|
@rdump.redis(0).hset 'hashkey', 'field_b', 'value_b'
|
21
24
|
@rdump.redis(0).hset 'hashkey', 'field_c', 'value_c'
|
22
25
|
3.times { |idx| @rdump.redis(0).rpush 'listkey', "value_#{idx}" }
|
23
|
-
4.times { |idx| @rdump.redis(0).sadd 'setkey', "value_#{idx}" }
|
26
|
+
4.times { |idx| @rdump.redis(0).sadd? 'setkey', "value_#{idx}" }
|
24
27
|
5.times { |idx| @rdump.redis(0).zadd 'zsetkey', idx.zero? ? 100 : 100*idx, "value_#{idx}" }
|
25
28
|
@rdump.redis(0).keys.size
|
26
29
|
#=> 5
|
@@ -30,12 +33,6 @@ Redis::Dump.safe = true
|
|
30
33
|
@values.size
|
31
34
|
#=> 5
|
32
35
|
|
33
|
-
# Clear DB 0
|
34
|
-
db0 = Redis::Dump.new 0, @uri_base
|
35
|
-
db0.redis(0).flushdb
|
36
|
-
db0.redis(0).keys.size
|
37
|
-
#=> 0
|
38
|
-
|
39
36
|
## Can load data
|
40
37
|
@rdump.load @values.join
|
41
38
|
@rdump.redis(0).keys.size
|
@@ -43,8 +40,8 @@ db0.redis(0).keys.size
|
|
43
40
|
|
44
41
|
## DB 0 content matches previous dump content
|
45
42
|
values = @rdump.dump
|
46
|
-
values.
|
47
|
-
#=> @values.
|
43
|
+
[values[0], values.size]
|
44
|
+
#=> [@values[0], @values.size]
|
48
45
|
|
49
46
|
## Won't load data in safe mode if records exist
|
50
47
|
@rdump.load @values.join
|
@@ -55,6 +52,14 @@ Redis::Dump.safe = false
|
|
55
52
|
@rdump.load @values.join
|
56
53
|
#=> 5
|
57
54
|
|
55
|
+
## Clear DB 0
|
56
|
+
db0 = Redis::Dump.new 0, @uri_base
|
57
|
+
db0.redis(0).flushdb
|
58
|
+
db0.redis(0).keys.size
|
59
|
+
#=> 0
|
60
|
+
|
61
|
+
## Clear DB 0 in safe mode
|
58
62
|
Redis::Dump.safe = true
|
59
63
|
db0 = Redis::Dump.new 0, @uri_base
|
60
64
|
db0.redis(0).flushdb
|
65
|
+
#=> "OK"
|
@@ -1,13 +1,16 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../lib/redis/dump'
|
2
4
|
|
3
5
|
# The test instance of redis must be running:
|
4
|
-
# $ redis-server try/redis
|
6
|
+
# $ redis-server try/redis.conf
|
5
7
|
|
6
|
-
@uri_base = "redis://127.0.0.1:
|
8
|
+
@uri_base = "redis://127.0.0.1:6379"
|
7
9
|
|
8
10
|
Redis::Dump.debug = false
|
9
11
|
Redis::Dump.safe = true
|
10
12
|
|
13
|
+
|
11
14
|
## Connect to DB
|
12
15
|
@rdump = Redis::Dump.new 0..1, @uri_base
|
13
16
|
@rdump.redis_connections.size
|
@@ -30,14 +33,7 @@ Redis::Dump.safe = true
|
|
30
33
|
@rdump.dump('*gloria*').sort
|
31
34
|
#=> ['{"db":0,"key":"gloria:0","ttl":-1,"type":"string","value":"gloria_value[0]","size":15}','{"db":0,"key":"gloria:1","ttl":-1,"type":"string","value":"gloria_value[1]","size":15}','{"db":0,"key":"gloria:2","ttl":-1,"type":"string","value":"gloria_value[2]","size":15}']
|
32
35
|
|
33
|
-
|
34
|
-
## Dump none existent keys (NOT SUPPORTED AS OF 0.3.0)
|
35
|
-
unknown_keys = [URI.parse("#{@uri_base}/0/unknownkey1"), URI.parse("#{@uri_base}/1/unknownkey2")]
|
36
|
-
@rdump.dump(unknown_keys).sort
|
37
|
-
##=> ['{"db":0,"key":"unknownkey1","ttl":-1,"type":"none","value":"","size":0}', '{"db":1,"key":"unknownkey2","ttl":-1,"type":"none","value":"","size":0}']
|
38
|
-
|
39
|
-
|
40
36
|
Redis::Dump.safe = true
|
41
37
|
db0 = Redis::Dump.new 0..1, @uri_base
|
42
38
|
db0.redis(0).flushdb
|
43
|
-
db0.redis(1).flushdb
|
39
|
+
db0.redis(1).flushdb
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../lib/redis/dump'
|
4
|
+
# require 'pry-byebug'
|
5
|
+
|
6
|
+
# The test instance of redis must be running:
|
7
|
+
# $ redis-server try/redis.conf
|
8
|
+
|
9
|
+
@uri_base = "redis://127.0.0.1:6379"
|
10
|
+
|
11
|
+
Redis::Dump.debug = true # leave enabled for CI workflow
|
12
|
+
Redis::Dump.safe = true
|
13
|
+
Redis::Dump.with_base64 = true
|
14
|
+
|
15
|
+
## Connect to DB
|
16
|
+
@rdump = Redis::Dump.new 0..1, @uri_base
|
17
|
+
@rdump.redis_connections.size
|
18
|
+
#=> 2
|
19
|
+
|
20
|
+
## Populate
|
21
|
+
@rdump.redis(0).set 'stringkey1', 'stringvalue1'
|
22
|
+
@rdump.redis(0).set 'stringkey2', 'stringvalue2'
|
23
|
+
@rdump.redis(0).keys.size
|
24
|
+
#=> 2
|
25
|
+
|
26
|
+
## Values are base64 encoded when with_base64=true
|
27
|
+
@values = @rdump.dump
|
28
|
+
# Check for values without relying on the order the keys were returned in
|
29
|
+
encoded_str = "{\"db\":0,\"key\":\"stringkey1\",\"ttl\":-1,\"type\":\"string\",\"value\":\"c3RyaW5ndmFsdWUx\\n\",\"size\":12}"
|
30
|
+
encoded_str2 = "{\"db\":0,\"key\":\"stringkey2\",\"ttl\":-1,\"type\":\"string\",\"value\":\"c3RyaW5ndmFsdWUy\\n\",\"size\":12}"
|
31
|
+
[@values.include?(encoded_str), @values.include?(encoded_str2)]
|
32
|
+
#=> [true, true]
|
33
|
+
|
34
|
+
## Can dump
|
35
|
+
@values = @rdump.dump
|
36
|
+
@values.size
|
37
|
+
#=> 2
|
38
|
+
|
39
|
+
## Can load data
|
40
|
+
@rdump.load @values.join
|
41
|
+
@rdump.redis(0).keys.size
|
42
|
+
#=> 2
|
43
|
+
|
44
|
+
# Clear DB 0
|
45
|
+
db0 = Redis::Dump.new 0, @uri_base
|
46
|
+
db0.redis(0).flushdb
|
47
|
+
db0.redis(0).keys.size
|
48
|
+
##=> 0
|
49
|
+
|
50
|
+
Redis::Dump.safe = true
|
51
|
+
db0 = Redis::Dump.new 0, @uri_base
|
52
|
+
db0.redis(0).flushdb
|
data/try/redis.conf
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# redis-dump redis config
|
2
|
-
#
|
2
|
+
# 2017-11-09
|
3
3
|
|
4
4
|
dir /tmp
|
5
5
|
pidfile redisdump-test.pid
|
6
6
|
logfile redisdump-test.log
|
7
7
|
dbfilename redisdump-test.rdb
|
8
8
|
|
9
|
-
#requirepass
|
9
|
+
# requirepass @/
|
10
10
|
|
11
11
|
bind 127.0.0.1
|
12
|
-
port
|
12
|
+
port 6379
|
13
13
|
databases 16
|
14
14
|
|
15
15
|
timeout 30
|
metadata
CHANGED
@@ -1,130 +1,48 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-dump
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
autorequire:
|
7
|
+
- delano
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
|
-
cert_chain:
|
11
|
-
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
FgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDGJ4TbZ9H+qZ08
|
18
|
-
pQfJhPJTHaDCyQvCsKTFrL5O9z3tllQ7B/zksMMM+qFBpNYu9HCcg4yBATacE/PB
|
19
|
-
qVVyUrpr6lbH/XwoN5ljXm+bdCfmnjZvTCL2FTE6o+bcnaF0IsJyC0Q2B1fbWdXN
|
20
|
-
6Off1ZWoUk6We2BIM1bn6QJLxBpGyYhvOPXsYoqSuzDf2SJDDsWFZ8kV5ON13Ohm
|
21
|
-
JbBzn0oD8HF8FuYOewwsC0C1q4w7E5GtvHcQ5juweS7+RKsyDcVcVrLuNzoGRttS
|
22
|
-
KP4yMn+TzaXijyjRg7gECfJr3TGASaA4bQsILFGG5dAWcwO4OMrZedR7SHj/o0Kf
|
23
|
-
3gL7P0axAgMBAAGjezB5MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
|
24
|
-
BBQF8qLA7Z4zg0SJGtUbv3eoQ8tjIzAfBgNVHREEGDAWgRRuZXRzc2hAc29sdXRp
|
25
|
-
b3VzLmNvbTAfBgNVHRIEGDAWgRRuZXRzc2hAc29sdXRpb3VzLmNvbTANBgkqhkiG
|
26
|
-
9w0BAQUFAAOCAQEATd8If+Ytmhf5lELy24j76ahGv64m518WTCdV2nIViGXB2BnV
|
27
|
-
uLQylGRb1rcgUS3Eh9TE28hqrfhotKS6a96qF9kN0mY2H6UwPWswJ+tj3gA1vLW8
|
28
|
-
wlZNlYGJ91Ig9zULPSbATyOOprUZyggy5p1260BaaI3LQYDeGJOSqpHCVu+TuMcy
|
29
|
-
k00ofiLT1crDSUl2WE/OIFK8AXpmd798AMsef8okHeoo+Dj7zCXn0VSimN+MO1mE
|
30
|
-
L4d54WIy4HkZCqQXoTSiK5HZMIdXkPk3F1bZdJ8Dy1sMRru0rUkkM5mW7TQ75mfW
|
31
|
-
Zp0QrZyNZhtitrXFbZneGRrIA/8G2Krft5Ly/A==
|
32
|
-
-----END CERTIFICATE-----
|
33
|
-
date: 2017-11-10 00:00:00.000000000 Z
|
34
|
-
dependencies:
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: yajl-ruby
|
37
|
-
requirement: !ruby/object:Gem::Requirement
|
38
|
-
requirements:
|
39
|
-
- - ">="
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
version: '0.1'
|
42
|
-
type: :runtime
|
43
|
-
prerelease: false
|
44
|
-
version_requirements: !ruby/object:Gem::Requirement
|
45
|
-
requirements:
|
46
|
-
- - ">="
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
version: '0.1'
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: redis
|
51
|
-
requirement: !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - "<"
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: '4.0'
|
56
|
-
- - ">="
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
version: '2.0'
|
59
|
-
type: :runtime
|
60
|
-
prerelease: false
|
61
|
-
version_requirements: !ruby/object:Gem::Requirement
|
62
|
-
requirements:
|
63
|
-
- - "<"
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
version: '4.0'
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '2.0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: uri-redis
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: 0.4.0
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 0.4.0
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: drydock
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 0.6.9
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 0.6.9
|
97
|
-
description: Backup and restore your Redis data to and from JSON.
|
98
|
-
email: delano@solutious.com
|
99
|
-
executables:
|
100
|
-
- redis-dump
|
101
|
-
- redis-load
|
102
|
-
- redis-report
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-06-17 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Backup and restore your Redis data to and from JSON by database, key,
|
14
|
+
or key pattern.
|
15
|
+
email: gems@solutious.com
|
16
|
+
executables: []
|
103
17
|
extensions: []
|
104
|
-
extra_rdoc_files:
|
105
|
-
- LICENSE.txt
|
106
|
-
- README.rdoc
|
18
|
+
extra_rdoc_files: []
|
107
19
|
files:
|
20
|
+
- ".pre-commit-config.yaml"
|
21
|
+
- ".rubocop.yml"
|
108
22
|
- CHANGES.txt
|
23
|
+
- Gemfile
|
24
|
+
- Gemfile.lock
|
109
25
|
- LICENSE.txt
|
110
|
-
- README.
|
26
|
+
- README.md
|
111
27
|
- Rakefile
|
112
|
-
-
|
113
|
-
-
|
114
|
-
-
|
115
|
-
- bin/redis-report
|
28
|
+
- exe/redis-dump
|
29
|
+
- exe/redis-load
|
30
|
+
- exe/redis-report
|
116
31
|
- gem-public_cert.pem
|
117
32
|
- lib/redis/dump.rb
|
33
|
+
- lib/redis/dump/version.rb
|
118
34
|
- redis-dump.gemspec
|
35
|
+
- sig/redis/dump.rbs
|
119
36
|
- try/10_redis_dump_try.rb
|
120
37
|
- try/20_dump_specific_keys_try.rb
|
38
|
+
- try/30_dump_base64_try.rb
|
121
39
|
- try/db0.json
|
122
40
|
- try/redis.conf
|
123
|
-
homepage:
|
41
|
+
homepage: https://rubygems.org/gems/redis-dump
|
124
42
|
licenses:
|
125
43
|
- MIT
|
126
44
|
metadata: {}
|
127
|
-
post_install_message:
|
45
|
+
post_install_message:
|
128
46
|
rdoc_options: []
|
129
47
|
require_paths:
|
130
48
|
- lib
|
@@ -132,16 +50,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
132
50
|
requirements:
|
133
51
|
- - ">="
|
134
52
|
- !ruby/object:Gem::Version
|
135
|
-
version:
|
53
|
+
version: 2.7.8
|
136
54
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
55
|
requirements:
|
138
56
|
- - ">="
|
139
57
|
- !ruby/object:Gem::Version
|
140
58
|
version: '0'
|
141
59
|
requirements: []
|
142
|
-
|
143
|
-
|
144
|
-
signing_key:
|
60
|
+
rubygems_version: 3.5.7
|
61
|
+
signing_key:
|
145
62
|
specification_version: 4
|
146
63
|
summary: Backup and restore your Redis data to and from JSON.
|
147
64
|
test_files: []
|
checksums.yaml.gz.sig
DELETED
Binary file
|
data/README.rdoc
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
= Redis-Dump v0.3 ALPHA
|
2
|
-
|
3
|
-
<i>Backup and restore your Redis data to and from JSON.</i>
|
4
|
-
|
5
|
-
<b>NOTE: This is alpha software. TEST IT BEFORE RELYING ON IT.</b>
|
6
|
-
|
7
|
-
|
8
|
-
== Usage
|
9
|
-
|
10
|
-
There are two executables: <tt>redis-dump</tt> and <tt>redis-load</tt>.
|
11
|
-
|
12
|
-
$ redis-dump
|
13
|
-
$ redis-dump -u 127.0.0.1:6371 > db_full.json
|
14
|
-
$ redis-dump -u 127.0.0.1:6371 -d 15 > db_db15.json
|
15
|
-
|
16
|
-
$ < db_full.json redis-load
|
17
|
-
$ < db_db15.json redis-load -d 15
|
18
|
-
# OR
|
19
|
-
$ cat db_full | redis-load
|
20
|
-
$ cat db_db15.json | redis-load -d 15
|
21
|
-
|
22
|
-
# You can specify the redis URI via an environment variable
|
23
|
-
$ export REDIS_URI=127.0.0.1:6371
|
24
|
-
$ redis-dump
|
25
|
-
|
26
|
-
# If your instance uses a password (such as on RedisToGo), you
|
27
|
-
# can specify the Redis URL as such:
|
28
|
-
# :<password>@<domain>:<port>
|
29
|
-
# Note the leading colon is important for specifying no username.
|
30
|
-
$ redis-dump -u :234288a830f009980e08@example.redistogo.com:9055
|
31
|
-
|
32
|
-
== Output format
|
33
|
-
|
34
|
-
All redis datatypes are output to a simple JSON object. All objects have the following 5 fields:
|
35
|
-
|
36
|
-
* db (Integer)
|
37
|
-
* key (String)
|
38
|
-
* ttl (Integer): The amount of time in seconds that the key will live. If no expire is set, it's -1.
|
39
|
-
* type (String), one of: string, list, set, zset, hash, none.
|
40
|
-
* value (String): A JSON-encoded string. For keys of type list, set, zset, and hash, the data is given a specific structure (see below).
|
41
|
-
|
42
|
-
Here are examples of each datatype:
|
43
|
-
|
44
|
-
{"db":0,"key":"hashkey","ttl":-1,"type":"hash","value":{"field_a":"value_a","field_b":"value_b","field_c":"value_c"},"size":42}
|
45
|
-
{"db":0,"key":"listkey","ttl":-1,"type":"list","value":["value_0","value_1","value_2","value_0","value_1","value_2"],"size":42}
|
46
|
-
{"db":0,"key":"setkey","ttl":-1,"type":"set","value":["value_2","value_0","value_1","value_3"],"size":28}
|
47
|
-
{"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}
|
48
|
-
{"db":0,"key":"stringkey","ttl":79,"type":"string","value":"stringvalue","size":11}
|
49
|
-
|
50
|
-
=== Important note about TTLs
|
51
|
-
|
52
|
-
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, <em>the expires are reset to their values at the time the dump was created</em>. This is different from restoring from Redis' native .rdb or .aof files (expires are stored relative to the actual time they were set).
|
53
|
-
|
54
|
-
|
55
|
-
== Output directly to an encrypted file
|
56
|
-
|
57
|
-
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](http://www.gnupg.org/) and file descriptors. Here are a couple examples:
|
58
|
-
|
59
|
-
# Encrypt the data (interactive)
|
60
|
-
$ redis-dump -u 127.0.0.1:6371 -d 15 | gpg --force-mdc -v -c > path/2/backup-db15.json.gpg
|
61
|
-
|
62
|
-
# Encrypt the data (automated)
|
63
|
-
$ 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
|
64
|
-
|
65
|
-
# Decrypt the file (interactive)
|
66
|
-
$ gpg path/2/backup-db15.json.gpg
|
67
|
-
Enter passphrase: *******
|
68
|
-
|
69
|
-
# Decrypt the file (automated)
|
70
|
-
$ 3</path/2/passphrase.txt gpg --passphrase-fd 3 path/2/backup-db15.json.gpg
|
71
|
-
|
72
|
-
|
73
|
-
== Loading data with binary strings
|
74
|
-
|
75
|
-
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!
|
76
|
-
|
77
|
-
== Installation
|
78
|
-
|
79
|
-
$ gem install redis-dump
|
80
|
-
|
81
|
-
Or of you want to run it directly:
|
82
|
-
|
83
|
-
$ git clone https://github.com/delano/redis-dump.git
|
84
|
-
$ cd redis-dump
|
85
|
-
$ gem install redis
|
86
|
-
$ gem install uri-redis
|
87
|
-
$ gem install yajl-ruby
|
88
|
-
$ gem install drydock
|
89
|
-
$ ruby -rubygems bin/redis-dump
|
90
|
-
|
91
|
-
|
92
|
-
== More Info
|
93
|
-
|
94
|
-
* Codes[http://github.com/delano/redis-dump]
|
95
|
-
* Docs[http://goldensword.ca/redis-dump/]
|
96
|
-
|
97
|
-
|
98
|
-
== Credits
|
99
|
-
|
100
|
-
* delano[http://github.com/delano]
|
101
|
-
|
102
|
-
|
103
|
-
== Thanks
|
104
|
-
|
105
|
-
* antirez and the funky redis bunch!
|
106
|
-
|
107
|
-
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.3.6
|
data.tar.gz.sig
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
��!k��Ơ̵'}D�[��fH�[�C��s��ǻ��r�@��UNIQ�P�+�!l�'�z��TW*�?z�T�=@/�V���H�����4����d��`�yÍV:��2lz��4�Һ_r���ݛm�'���K�Ѕ!£���ȟ{�~���L���8�P|�D���7�O�zj3\Ğ��{��&a��6U&� �X�����$��ׂ�!b>:!������M�b��a!�V�NƱ�q�-��5�
|
metadata.gz.sig
DELETED
/data/{bin → exe}/redis-report
RENAMED
File without changes
|