数据库
首页 > 数据库> > redis备份

redis备份

作者:互联网

#!/bin/bash
echo "start..."
sdate=$(date "+ %Y-%m-%d %H:%M:%S")
msg=`redis-cli -p $1 -a $2 bgsave`
echo "start bgsave time:$sdate"
result=`redis-cli -p $1 -a $2 info Persistence | grep "rdb_bgsave_in_progress" | awk -F":" '{print $2}'`
while [ `echo ${result} | awk -v tem="0" '{print($1>tem)? "1":"0"}'` -eq "1" ] ; do
    sleep 1
    result=`redis-cli -p $1 -a $2 info Persistence | grep "rdb_bgsave_in_progress" | awk -F":" '{print $2}'`
done
edate=$(date "+ %Y-%m-%d %H:%M:%S")
echo "end bgsave time:$edate"
echo "renaming rdb file..."
date=$(date "+ %Y%m%d")
mv "../db03/dump.rdb" "../db03/${date}.rdb"
echo "finish backup rdb file"
echo "end"

标签:-%,redis,备份,bgsave,echo,rdb,date
来源: https://www.cnblogs.com/xjzyy/p/16184841.html