Redis教程

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备份的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!