redis aof 与 rdb 介绍
相关链接1 相关连接2 相关连接3
- 开启appendonly 当前生效
127.0.0.1:6379> config get appendonly
1) "appendonly"
2) "no"
127.0.0.1:6379> config set appendonly yes
127.0.0.1:6379> config set save ""
127.0.0.1:6379> config get aof-use-rdb-preamble
1) "aof-use-rdb-preamble"
2) "yes"
- 修改redis.conf
vim redis.conf
save ""
appendonly yes
- aof持久化相关参数介绍
appendfsync everysec
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
- 备份脚本与计划任务
脚本地址
脚本如下
[root@iZwz9c0rnhno789fl3ibk6Z scripts]
workdir=`cd $(dirname $0);pwd`
same_day=`date +%F`
seven_day_age=`date -d '-7 day' "+%F"`
data_dir=/usr/local/redis/var
backup_dir=/datawww/backup/redis
logfile=$workdir/backup_reids.log
redis=/usr/local/bin/redis-cli
echo "----`date` started sh---------------------------" >> $logfile
if [ -d $backup_dir ];then
echo "`date` $backup_dir 备份目录已存在" >> $logfile
else
echo "`date` $backup_dir 备份目录不存在 正在创建 " >> $logfile
mkdir -p $backup_dir
fi
while :
do
sleep 1
number=`$redis info Persistence |grep rdb_bgsave_in_progress |awk -F":" '{print $NF}'`
if [ `echo ${number} | awk -v tem=0 '{print($1>tem)? "1":"0"}'` -eq "0" ];then
echo "rdb_bgsave_in_progress为 0 正在退出循环 执行备份中" >> $logfile
break
fi
done
if [ -d $backup_dir/${same_day} ];then
echo "`date` $backup_dir/${same_day} 备份目录已存在" >> $logfile
else
echo "`date` $backup_dir/${same_day} 备份目录不存在 正在创建" >> $logfile
mkdir -p $backup_dir/${same_day}
fi
echo "`date` cp aoffile start " >> $logfile
cp -arf $data_dir/appendonly.aof $backup_dir/${same_day}
echo "`date` start bgsave " >> $logfile
$redis bgsave
sleep 30
echo "`date` end bgsave" >> $logfile
cp -arf $data_dir/dump.rdb $backup_dir/${same_day}
echo "`date` backup complete" >> $logfile
rm -rf $backup_dir/${seven_day_age}
计划任务
0 1 * * * /usr/bin/bash /datawww/scripts/redis_backup_aof.sh
aof文件备份恢复
redis应用1当下key的数量
redis 应用2当下key的数量
上传redis应用2aof文件到redis应用1上 数据目录如下 上传新的aof文件
重启redis应用
[root@iZwz9conqz5shxfx2gmnfkZ data]
重启失败
chown redis.redis appendonly.aof
[root@iZwz9conqz5shxfx2gmnfkZ data]
本文参考:https://www.codeleading.com/article/10122519892/ 本文参考:https://blog.csdn.net/csd753111111/article/details/100428659 本文参考:https://blog.csdn.net/xiaobaiing/article/details/51371880
|