配置文件
save "" # 取消自动生成RDB文件
dbfilename dump_6379.rdb
dir "/data/redis"
appendonly no
脚本, 可以配置计划任务, 定期备份RDB文件
#!/bin/bash
. /etc/init.d/functions
BACKUP=/backup/redis-rdb
DIR=/data/redis
FILE=dump_6379.rdb
PASS=123456
redis-cli -h 127.0.0.1 -a $PASS --no-auth-warning bgsave
result=`redis-cli -a 123456 --no-auth-warning info Persistence |grep rdb_bgsave_in_progress | sed -rn 's/.*:([0-9]+).*/\1/p'`
until [ $result -eq 0 ]; do
sleep 1
result=`redis-cli -a 123456 --no-auth-warning info Persistence | grep rdb_bgsave_in_progress | sed - rn 's/.*:([0-9]+).*/\1/p'`
done
DATE=`date +%F_%H-%M-%S`
[ -e $BACKUP ] || { mkdir -p $BACKUP; chown -R redis.redis $BACKUP; }
mv $DIR/$FILE $BACKUP/dump_6379-${DATE}.rdb
action "Backup redis RDB"
网友评论