redis数据库备份脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了redis数据库备份脚本相关的知识,希望对你有一定的参考价值。
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}
以上是关于redis数据库备份脚本的主要内容,如果未能解决你的问题,请参考以下文章
Jumpserver高可用集群部署:MariaDB及Redis数据库定时备份