Skip to content
/ rutil Public

rutil is a small command line utility that lets you selectively dump, restore and query a Redis database

License

Notifications You must be signed in to change notification settings

Sensedia/rutil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

rutil is a small command line utility that lets you selectively dump, restore and query a redis database, peek into stored data and pretty print json contents.

Attention!!! This code is a fork of project rutil We try to contact the initial developers: pampa/rutil#6. Parallel to this, improvements were made to the code to be compiled with Go 1.15 and a Docker image was created to facilitate distribution and use.

Credits for:

Thanks @otavioprado for making improvements to the code to be compiled with Go 1.15 and creating the Dockerfile for easy distribution and use.

Demostration

rutil

Installation

Clone this repository with command:

git clone https://github.com/Sensedia/rutil

cd rutil

Using Docker

Install Docker following the instructions in this tutorial.

Generate new image with command:

make image

Or:

docker build -t rutil:latest .

List the Docker images:

docker images

Run a container:

docker run --rm rutil --help

More information about docker run command: https://docs.docker.com/engine/reference/run/

Compiling with go

Install Go following the instructions in this tutorial.

Compile rutil with Go:

make build

Or:

go build -o bin/rutil .

Run rutil:

./bin/rutil --help

Usage

rutil [global options] command [command options] [arguments...]

COMMANDS:
   dump      dump redis database to a file
   pipe      dump a redis database to stdout in a format compatible with | redis-cli --pipe
   restore   restore redis database from a file
   query, q  query keys matching the pattern provided by --keys
   help, h   Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --host value, -s value  redis host (default: "127.0.0.1")
   --auth value, -a value  authentication password
   --port value, -p value  redis port (default: 6379)
   --cluster, -c           redis cluster connection
   --help, -h              show help
   --version, -v           print the version

Examples

Command dump

rutil [global options] dump [command options] [arguments...]

GLOBAL OPTIONS:
   --host value, -s value  redis host (default: "127.0.0.1")
   --auth value, -a value  authentication password
   --port value, -p value  redis port (default: 6379)
   --cluster, -c           redis cluster connection
   --help, -h              show help
   --version, -v           print the version

OPTIONS:
   --keys value, -k value   keys pattern (passed to redis 'keys' command) (default: "*")
   --match value, -m value  regexp filter for key names
   --invert, -v             invert match regexp
   --auto, -a               make up a file name for the dump - redisYYYYMMDDHHMMSS.rdmp

Cluster

Make a dump of all keys of Redis cluster:

./bin/rutil -c --host 192.168.0.1 --port 6379 dump /tmp/dump_all_keys.rdmp

A file will be created /tmp/dump_all_keys.rdmp.

Or:

./bin/rutil -c --host 192.168.0.1 --port 6379 dump -a

A file will be created in the current directory with the following pattern: redisYYYYMMDDHHMMSS.rdmp.

Using Docker:

docker run --rm -v $PWD:/tmp rutil -c --host 192.168.0.1 --port 6379 dump /tmp/file2.rdmp

Or:

docker run --rm -v $PWD:/tmp rutil -c --host 192.168.0.1 --port 6379 dump -a

Node

Make a dump of all keys of Redis node (ommiting -c option):

./bin/rutil --host 192.168.0.1 --port 6379 dump /tmp/dump_all_keys.rdmp

A file will be created /tmp/dump_all_keys.rdmp.

Or:

./bin/rutil --host 192.168.0.1 --port 6379 dump -a

A file will be created in the current directory with the following pattern: redisYYYYMMDDHHMMSS.rdmp.

Using Docker (ommiting -c option):

docker run --rm -v $PWD:/tmp rutil --host 192.168.0.1 --port 6379 dump /tmp/file2.rdmp

Or:

docker run --rm -v $PWD:/tmp rutil --host 192.168.0.1 --port 6379 dump -a

Pipe

rutil [global options] pipe [command options] [arguments...]

GLOBAL OPTIONS:
   --host value, -s value  redis host (default: "127.0.0.1")
   --auth value, -a value  authentication password
   --port value, -p value  redis port (default: 6379)
   --cluster, -c           redis cluster connection
   --help, -h              show help
   --version, -v           print the version

OPTIONS:
   --keys value, -k value   keys pattern (passed to redis 'keys' command) (default: "*")
   --match value, -m value  regexp filter for key names
   --invert, -v             invert match regexp

Restore

rutil [global options] estore [command options] [arguments...]

GLOBAL OPTIONS:
   --host value, -s value  redis host (default: "127.0.0.1")
   --auth value, -a value  authentication password
   --port value, -p value  redis port (default: 6379)
   --cluster, -c           redis cluster connection
   --help, -h              show help
   --version, -v           print the version

OPTIONS:
   --dry-run, -r  pretend to restore
   --flushdb, -f  flush the database before restoring
   --delete, -d   delete key before restoring
   --ignore, -g   ignore BUSYKEY restore errors
   --stdin, -i    read dump from STDIN

Cluster

Simulate restore all keys of Redis cluster:

./bin/rutil --host 192.168.0.1 -c --port 6379 restore --dry-run /tmp/file2.rdmp

Or:

docker run --rm -v $PWD:/tmp rutil -c --host 192.168.0.1 --port 6379 restore --dry-run /tmp/file2.rdmp

Restore all keys of Redis cluster:

./bin/rutil -c --host 192.168.0.1 --port 6379 restore --flushdb /tmp/file2.rdmp

Or:

docker run --rm -v $PWD:/tmp rutil -c --host 192.168.0.1 --port 6379 restore --flushdb /tmp/file2.rdmp

Node

Simulate restore all keys of Redis node (ommiting -c option):

./bin/rutil --host 192.168.0.1 --port 6379 restore --dry-run /tmp/file2.rdmp

Or:

docker run --rm -v $PWD:/tmp rutil --host 192.168.0.1 --port 6379 restore --dry-run /tmp/file2.rdmp

Restore all keys of Redis node (ommiting -c option):

./bin/rutil --host 192.168.0.1 --port 6379 restore --flushdb /tmp/file2.rdmp

Or:

docker run --rm -v $PWD:/tmp rutil --host 192.168.0.1 --port 6379 restore --flushdb /tmp/file2.rdmp

Query

rutil [global options] query [command options] [arguments...]

GLOBAL OPTIONS:
   --host value, -s value  redis host (default: "127.0.0.1")
   --auth value, -a value  authentication password
   --port value, -p value  redis port (default: 6379)
   --cluster, -c           redis cluster connection
   --help, -h              show help
   --version, -v           print the version

OPTIONS:
   --keys value, -k value   keys pattern (passed to redis 'keys' command)
   --match value, -m value  regexp filter for key names
   --invert, -v             invert match regexp
   --delete                 delete keys
   --print, -p              print key values
   --field value, -f value  hash fields to print (default all)
   --json, -j               attempt to parse and pretty print strings as json

Cluster

List all keys in Redis cluster:

./bin/rutil -c --host 192.168.0.1 --port 6379 query --keys '*'

Or:

docker run --rm rutil -c --host 192.168.0.1 --port 6379 query --keys '*'

Make a query in Redis cluster:

./bin/rutil -c --host 192.168.0.1 --port 6379 query --keys 'testing:abcde:BOOK*'

Or:

docker run --rm rutil -c --host 192.168.0.1 --port 6379 query --keys 'testing:abcde:BOOK*'

Delete a key in Redis cluster:

./bin/rutil -c --host 192.168.0.1 --port 6379 query --keys 'testing:abcde:BOOK:55' --delete

Or:

docker run --rm rutil -c --host 192.168.0.1 --port 6379 query --keys 'testing:abcde:BOOK:55' --delete

Print value of a key in Redis cluster:

./bin/rutil -c --host 192.168.0.1 --port 6379 query --keys 'testing:abcde:BOOK:55' --print

Or:

docker run --rm rutil -c --host 192.168.0.1 --port 6379 query --keys 'testing:abcde:BOOK:55' --print

More information: https://redis.io/commands/keys

Node

List all keys in Redis node (ommiting -c option):

./bin/rutil --host 192.168.0.1 --port 6379 query --keys '*'

Or:

docker run --rm rutil --host 192.168.0.1 --port 6379 query --keys '*'

Make a query in Redis node (ommiting -c option):

./bin/rutil --host 192.168.0.1 --port 6379 query --keys 'testing:abcde:BOOK*'

Or:

docker run --rm rutil --host 192.168.0.1 --port 6379 query --keys 'testing:abcde:BOOK*'

Delete a key in Redis node (ommiting -c option):

./bin/rutil --host 192.168.0.1 --port 6379 query --keys 'testing:abcde:BOOK:55' --delete

Or:

docker run --rm rutil --host 192.168.0.1 --port 6379 query --keys 'testing:abcde:BOOK:55' --delete

Print value of a key in Redis node (ommiting -c option):

./bin/rutil --host 192.168.0.1 --port 6379 query --keys 'testing:abcde:BOOK:55' --print

Or:

docker run --rm rutil --host 192.168.0.1 --port 6379 query --keys 'testing:abcde:BOOK:55' --print

More information: https://redis.io/commands/keys