redis-dump命令安装环境参考一下链接地址:
http://blog.51cto.com/wujianwei/2105124
redis数据库备份脚本:
[[email protected] ~]# 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
[[email protected] 20180608]# pwd
/data/backup/redisdb/20180608
备份出来的数据内容如下:
[[email protected] 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}
原文地址:http://blog.51cto.com/wujianwei/2128998
时间: 2024-10-31 21:08:30