redis-dump命令安装环境参考一下链接地址:
https://blog.51cto.com/wujianwei/2105124
redis数据库备份脚本:
[root@localhost ~]# cat /data/scripts/dump_redisdata.sh
#!/bin/bash
source /etc/profile.d/rvm.sh
/usr/local/rvm/bin/rvm --create ruby-2.3.4 & >/dev/null
DATENOW=`date +%Y%m%d`
DIR=/data/backup/redisdb/"$DATENOW"
DATETIME=`date +%H%M`
if [ ! -d "$DIR" ]
then
mkdir -p /data/backup/redisdb/"$DATENOW"
fi
/usr/local/rvm/gems/ruby-2.3.4/bin/redis-dump -u 127.0.0.1:6379 >"$DIR"/redis$DATETIME-json
oldDate=$(date -d "-6 days" "+%Y%m%d")
cd /data/backup/redisdb
for folder in $(ls -d */)
do
[ ${folder%/*} -lt $oldDate ] && rm -rf $folder
done
[root@localhost 20180608]# pwd
/data/backup/redisdb/20180608
备份出来的数据内容如下:
[root@localhost 20180608]# tail -2 redis1230-json
{"db":0,"key":"/a","ttl":-1,"type":"string","value":"http://www.jd.com","size":17}
{"db":0,"key":"/b","ttl":-1,"type":"string","value":"http://www.51cto.com","size":20}
转载于:https://blog.51cto.com/wujianwei/2128998