Redis备份工具Redis-dump
Posted 青衫解衣
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Redis备份工具Redis-dump相关的知识,希望对你有一定的参考价值。
Redis-dump 文档和地址:
https://github.com/delano/redis-dump/
https://rubygems.org/gems/redis-dump
安装ruby依赖:
yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel \\
libyaml-devel libffi-devel openssl-devel make \\
bzip2 autoconf automake libtool bison iconv-devel sqlite-devel
安装系统ruby:
yum install ruby -y
替换ruby源:
gem sources --remove https://rubygems.org/
gem sources -a https://mirrors.aliyun.com/rubygems/
gem source -l
安装rvm:
yum install curl -y
curl -L get.rvm.io | bash -s stable
报错:
[root@harbor ~]# curl -sSL https://get.rvm.io | bash -s stable
curl: (7) Failed connect to raw.githubusercontent.com:443; Connection refused
解决办法:
打开网站https://www.ipaddress.com/,查询一下raw.githubusercontent.com对应的IP 地址。
/etc/hosts文件新增:
185.199.108.133 raw.githubusercontent.com
/etc/resolv.conf文件新增:
nameserver 8.8.8.8
输出内容复制下面内容运行:
command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
command curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -
再次运行:
curl -L get.rvm.io | bash -s stable
更新配置文件:
source /etc/profile.d/rvm.sh
安装ruby2.3.3版本:
安装中替换老的ruby.
rvm install 2.3.3 (2.3.3以上版本都可以)
查看可以安装的Ruby版本:
rvm list known
安装备份工具redis-dump:
gem install redis-dump -V
测试redis-dump备份:
第一种写法:
[root@harbor ~]# redis-dump -u:redhat@127.0.0.1:6379 > /backup/db_full.json
[root@harbor ~]# cat /backup/db_full.json
{"db":0,"key":"name","ttl":-1,"type":"string","value":"mew","size":3}
第二种写法:
[root@harbor ~]# redis-dump -p 6379 -a redhat > /backup/db2.json
[root@harbor ~]# cat /backup/db2.json
{"db":0,"key":"name","ttl":-1,"type":"string","value":"mew","size":3}
测试name值改为meng,再新建一个值,恢复看是否会覆盖或者影响其他值:
新建的2个key:
恢复备份:
# cat /backup/db_full.json | redis-load -u:redhat@127.0.0.1:6379
以上是关于Redis备份工具Redis-dump的主要内容,如果未能解决你的问题,请参考以下文章
redis 备份和恢复 :redis-dump安装与导出redis数据