来源
https://www.cnblogs.com/dadonggg/p/8662455.html
https://blog.csdn.net/chenxinchongcn/article/details/78666374
安装过程
安装ruby
安装redis-dump之前首先需要安装ruby
$ yum install ruby rubygems ruby-devel -y
报错
安装完成后,安装redis-dump说ruby版本过低,一查才知道原来Redis需要ruby的版本过低,升级版本
[root@izuf63g0jydq42k49eo7zcz ~]# gem install redis-dump
Fetching: yajl-ruby-1.4..gem (%)
Building native extensions. This could take a while...
Successfully installed yajl-ruby-1.4.
Fetching: redis-4.1..gem (%)
ERROR: Error installing redis-dump:
redis requires Ruby version >= 2.2..
安装rvm
利用curl安装rvm,如果没有curl请使用yum安装
$ yum install curl
$ curl -L get.rvm.io | bash -s stable
rvm安装完成后会有两种方式来安装
[root@izuf63g0jydq42k49eo7zcz ~]# curl -L get.rvm.io | bash -s stable
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
--:--:-- --:--:-- --:--:--
:: :: --:--:--
Downloading https://github.com/rvm/rvm/archive/1.29.7.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.7/1.29.7.tar.gz.asc
gpg: directory `/root/.gnupg' created
gpg: new configuration file `/root/.gnupg/gpg.conf' created
gpg: WARNING: options in `/root/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/root/.gnupg/pubring.gpg' created
gpg: Signature made Fri Jan :: AM CST using RSA key ID 39499BDB
gpg: Can't check signature: No public key
GPG signature verification failed for '/usr/local/rvm/archives/rvm-1.29.7.tgz' - 'https://github.com/rvm/rvm/releases/download/1.29.7/1.29.7.tar.gz.asc'! Try to install GPG v2 and then fetch the public key: gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB or if it fails: command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
command curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import - In case of further problems with validation please refer to https://rvm.io/rvm/security
我选择第一种,然后接下来进行一系列安装
$ gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
$ \curl -sSL https://get.rvm.io | bash -s stable $ source ~/.bashrc $ source ~/.bash_profile $ source /usr/local/rvm/scripts/rvm $ rvm list known #列出版本 $ rvm install 2.5. #选择一个高版本的安装 $ rvm use 2.5. #使用安装的版本 $ ruby --version #不放心,可以查看下版本
安装redis-dump
$ gem install redis-dump
安装完成,查看使用方法
[root@centos_7_6 ~]# redis-dump -h
Try: /usr/local/rvm/gems/ruby-2.5./bin/redis-dump show-commands
Usage: /usr/local/rvm/gems/ruby-2.5./bin/redis-dump [global options] COMMAND [command options]
-u, --uri=S Redis URI (e.g. redis://hostname[:port])
-d, --database=S Redis database (e.g. -d )
-a, --password=S Redis password (e.g. -a 'my@pass/word')
-s, --sleep=S Sleep for S seconds after dumping (for debugging)
-c, --count=S Chunk size (default: )
-f, --filter=S Filter selected keys (passed directly to redis' KEYS command)
-b, --base64 Encode key values as base64 (useful for binary values)
-O, --without_optimizations Disable run time optimizations
-V, --version Display version
-D, --debug
--nosafe [root@centos_7_6 ~]# redis-load
Usage: cat dumpfile_db15.json | redis-load -d
[root@centos_7_6 ~]# redis-load -h
Try: /usr/local/rvm/gems/ruby-2.5./bin/redis-load show-commands
Usage: /usr/local/rvm/gems/ruby-2.5./bin/redis-load [global options] COMMAND [command options]
-u, --uri=S Redis URI (e.g. redis://hostname[:port])
-d, --database=S Redis database (e.g. -d )
-a, --password=S Redis password (e.g. -a 'my@pass/word')
-s, --sleep=S Sleep for S seconds after dumping (for debugging)
-b, --base64 Decode key values from base64 (used with redis-dump -b)
-n, --no_check_utf8
-V, --version Display version
-D, --debug --nosafe
导出
# redis-dump >> /root/redis.json //地址密码
# redis-dump -a123456 -u127.0.0.1:6379 /root/redis.json
导入
cat /root/redis.json | redis-load //有密码使用-a
cat /root/redis.json | redis-load -adatitest1234