Redis-dump Command installation environment refer to the link address:
http://blog.51cto.com/wujianwei/2105124
Redis Database backup script:
[Email protected] ~]# cat/data/scripts/dump_redisdata.sh
#!/bin/bashsource /etc/profile.d/rvm.sh/usr/local/rvm/bin/rvm --create ruby-2.3.4 & >/dev/nullDATENOW=`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-jsonoldDate=$(date -d "-6 days" "+%Y%m%d")cd /data/backup/redisdb for folder in $(ls -d */)do [ ${folder%/*} -lt $oldDate ] && rm -rf $folderdone
[Email protected] 20180608]# pwd
/data/backup/redisdb/20180608
The contents of the backed up data are as follows:
[[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 Database backup Script