Code Monkey home page Code Monkey logo

redis-dump-go's Introduction

Build status go report card

Redis-dump-go

Dump Redis keys to a file. Similar in spirit to https://www.npmjs.com/package/redis-dump and https://github.com/delano/redis-dump but:

  • Will dump keys across several processes & connections
  • Uses SCAN rather than KEYS * for much reduced memory footprint with large databases
  • Easy to deploy & containerize - single binary.
  • Generates a RESP file rather than a JSON or a list of commands. This is faster to ingest, and recommended by Redis for mass-inserts.

Warning: like similar tools, Redis-dump-go does NOT provide Point-in-Time backups. Please use Redis backups methods when possible.

Features

  • Dumps all databases present on the Redis server
  • Keys TTL are preserved by default
  • Configurable Output (Redis commands, RESP)
  • Redis password-authentication

Installation

Download the appropriate version for your operating system on ŧhe release page, or use the Docker image:

$ docker run ghcr.io/yannh/redis-dump-go:latest -h
Usage of /redis-dump-go:
[...]

Bandwidth costs: Redis-dump-go is hosted on on Github Container Registry which is currently in Beta. During that period, bandwidth is free. After that period, a Github Account might be required / bandwidth costs might be applicable.

Run

$ ./bin/redis-dump-go -h
Usage of ./bin/redis-dump-go:
  -batchSize int
        HSET/RPUSH/SADD/ZADD only add 'batchSize' items at a time (default 1000)
  -db uint
        only dump this database (default: all databases)
  -filter string
        Key filter to use (default "*")
  -host string
        Server host (default "127.0.0.1")
  -n int
        Parallel workers (default 10)
  -noscan
        Use KEYS * instead of SCAN - for Redis <=2.8
  -output string
        Output type - can be resp or commands (default "resp")
  -port int
        Server port (default 6379)
  -s    Silent mode (disable logging of progress / stats)
  -ttl
        Preserve Keys TTL (default true)

$ ./bin/redis-dump-go > dump.resp
Database 0: 9 element dumped
Database 1: 1 element dumped

For password-protected Redis servers, set the shell variable REDISDUMPGO_AUTH:

$ export REDISDUMPGO_AUTH=myRedisPassword
$ redis-dump-go

Build

Given a correctly configured Go environment:

$ go get github.com/yannh/redis-dump-go
$ cd ${GOPATH}/src/github.com/yannh/redis-dump-go
$ go test ./...
$ go install

Importing the data

redis-cli --pipe < redis-backup.txt

Release Notes & Gotchas

  • By default, no cleanup is performed before inserting data. When importing the resulting file, hashes, sets and queues will be merged with data already present in the Redis.

redis-dump-go's People

Contributors

abdullahalshaad avatar adrilo avatar hsshss avatar iswiftliu avatar sonirico avatar yannh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

redis-dump-go's Issues

Create a release tag

Hi Yann,

Thanks for redis-dump-go, that's a nice tool. But it could be even nicer properly packaged in all of our favorites distributions :-)

Could you please create a tag or release a first version of the project ?

Best regards

dump all dbs doesn't work

Hello,

redis-server 5.0.9
redis-dump-go v0.7.0

Dump and restore all dbs doesn't work. All dbs (3,5,7) restoring to 0 db.

before restore:

Keyspace

db0:keys=280317,expires=279847,avg_ttl=208563507
db7:keys=8927,expires=0,avg_ttl=0

backup:
REDISDUMPGO_AUTH=pass redis-dump-go -port 6379 -host 127.0.0.1 -n 100 > redis.dump
REDISDUMPGO_AUTH=pass redis-cli -c -h 127.0.0.1 -p 6379 --pipe < redis.dump

after restore:

Keyspace

db0:keys=289432,expires=280032,avg_ttl=214048507

Is it normal behaviour now?

Thanks.

Add integration tests

The "silent" flag was causing redis-dump-go to hang in v0.3.1, we should have some sort of simple integration tests guaranteeing that basic functionality works.

Dependencies upgrade required

While trying to build the project, I encountered errors with golang.org/x/xerrors package

$ export GOPATH=$(mktemp -d)
$ go get github.com/yannh/redis-dump-go
# github.com/yannh/redis-dump-go/vendor/golang.org/x/xerrors
/tmp/tmp.H8Wn4abREk/src/github.com/yannh/redis-dump-go/vendor/golang.org/x/xerrors/adaptor_go1_13.go:16:14: undefined: errors.Frame
/tmp/tmp.H8Wn4abREk/src/github.com/yannh/redis-dump-go/vendor/golang.org/x/xerrors/format_go1_13.go:12:18: undefined: errors.Formatter

Steps to reproduce the bug

$ export GOPATH=$(mktemp -d)
$ go get github.com/yannh/redis-dump-go
...error...
$ cd ${GOPATH}/src/github.com/yannh/redis-dump-go
$ go build
go: downloading github.com/mediocregopher/radix/v3 v3.3.2
go: extracting github.com/mediocregopher/radix/v3 v3.3.2
go: downloading golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522
go: extracting golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522
go: finding github.com/mediocregopher/radix/v3 v3.3.2
go: finding golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522
# golang.org/x/xerrors
../../../../pkg/mod/golang.org/x/[email protected]/adaptor_go1_13.go:16:14: undefined: errors.Frame
../../../../pkg/mod/golang.org/x/[email protected]/format_go1_13.go:12:18: undefined: errors.Formatter

Fix

$ cd ${GOPATH}/src/github.com/yannh/redis-dump-go
$ go get -u ./...
go: finding github.com/mediocregopher/radix/v3 v3.4.1
go: finding golang.org/x/xerrors latest
go: downloading github.com/mediocregopher/radix/v3 v3.4.1
go: extracting github.com/mediocregopher/radix/v3 v3.4.1
go: downloading golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898
go: extracting golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898
$ go build
$ go install

support json format output?

I want to view the data in json format ,but I found -output not support.
-output string
Output type - can be resp or commands (default "resp")

unreconized type stream

I am attempting to use this to backup a redis instance that I am using with lorawan-stack and when I run the tool I am getting the following output:

*2
$6
SELECT
$1
0
Database 0: 5 element dumpedError: Key ttn:v3:ns:application-uplinks:uid:halter:uplinks:invalidation is of unreconized type stream

For more context I am using AWS ElastiCache engine version 5.0.5.

Special characters in password

Version: v0.7.0
Platform: Linux CentOS 7.9.2009 x86_64

redis-dump-go/main.go

Lines 109 to 114 in 0c04870

s := redisdump.Host{
Host: c.Host,
Port: c.Port,
Password: url.QueryEscape(redisPassword),
TlsHandler: tlshandler,
}

Why its using url.QueryEscape for password?
I have a password with special characters. And result: ERR invalid password

Example Password for this issue (randomly generated, safe, not using anywhere):
,u[!m&bd3*+tQK,ZC#YS%=}Fn#qw)~$<

Script

#!/bin/sh
export REDISDUMPGO_AUTH=",u[!m&bd3*+tQK,ZC#YS%=}Fn#qw)~$<"
./redis-dump-go

I tried without QueryEscape and its worked for me.

Support for Redis Cluster Mode

I have tried to take backup when Redis is running in Cluster Mode. The backup only contains data from one shard. To be precise, when the scan command is run, it only list the data from one node in the shard.

Is there any workaround using which I can take backup when Redis is running in Cluster Mode ?

Cannot dump data with null values to other redis nodes

When I dumped the data from one node and dumped it to other nodes, I found that the dumping of data with null value failed with the following error

using -output commands

ERR wrong number of arguments for 'set' command

The format of this type of data in the dump file is similar to the following

SET keyofnovalue 

It seems to work if I put it in double quote

SET keyofnovalue ""

But I'm not sure if it can be solved by double quotes for other types of data as well.

Is it possible to put double quotes for all types of data value if applicable

Auth issues with the latest build

I'm getting authentication error with the latest build. It was working fine with version 0.5.1.
Seems like getDBIndexes function is not using the password. Can the auth error be because of that?

Replace the `logger *log.Logger` dependence with interface

I am trying to use your application through importing it from golang.
The way the code works is that it requires a log.Logger then uses the log.Printf and log.Print function from this struct.
If we could replace the log.Logger with lets say a "Printer" interface which contains only Printf and Print then users can write their own and have the value saved to a struct or something else.

Importing the data ERROR

redis version: 5.0.4
redis-dump: 0.4.6

[root@mtl-gslb-redis ~]# redis-cli info
# Keyspace
db0:keys=6890,expires=0,avg_ttl=0
db1:keys=86949,expires=0,avg_ttl=0             large keys is in db1
db2:keys=1217,expires=0,avg_ttl=0
db3:keys=8196,expires=0,avg_ttl=0
db4:keys=493653,expires=0,avg_ttl=0
db5:keys=1178,expires=0,avg_ttl=0
db6:keys=1,expires=0,avg_ttl=0
db8:keys=1,expires=0,avg_ttl=0
db12:keys=155,expires=0,avg_ttl=0

redis dump success
but import data error:

[root@mtl-gslb-redis ~]# redis-cli -n 2  --pipe < 2.resp    
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
All data transferred. Waiting for the last reply...
Last reply received from server.
errors: 0, replies: 1218
[root@mtl-gslb-redis ~]# redis-cli -n 1 --pipe < 1.resp   
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
ERR Protocol error: invalid multibulk length
Error reading from the server: Connection reset by peer

Filter keys

Thanks @yannh You've created a very nice tool and it works perfectly well. I just have one query on keys filtering. How can I filter specific keys and dump those only?
eg: xyz:

Build doc notice

Hello
looks like you need to update the build section of readme with adding env variable
GO111MODULE=off
overwise ${GOPATH}/src folder is empty after go get:
/bin/sh: cd: line 1: can't cd to /go/src/github.com/yannh/redis-dump-go: No such file or directory

Redis with more than 16 db?

Hi,

What's the reason for having this check:

		if dbIndex > 16 {
			return nil, fmt.Errorf("Error parsing INFO keyspace")
		}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.