多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## 1. redis备份 脚本: ~~~ #!/bin/bash set -x BACKUPDIR=/data/redis/backup PASSWD='redis密码' DATADIR=`/usr/local/bin/redis-cli -p 端口 -a "$PASSWD" config get dir|grep -Ev 'dir|grep'` DATE=`date +'%Y-%m-%d-%H:%M'` if [ ! -d $BACKUPDIR ];then mkdir $BACKUPDIR \ || echo "can't make dir !!!" \ && exit 1 fi cp $DATADIR/dump.rdb $BACKUPDIR/$DATE.rdb if [ $? -eq 0 ];then echo '1' >> $BACKUPDIR/record.log else echo '0' >> $BACKUPDIR/record.log fi ~~~ * 设置定时任务备份数据 1. 执行crontab -e 加入 30 23 * * * /home/redis/backup/redisBackup.sh 2. 保存 ## redis恢复 ~~~ #!/bin/bash set -x CONF=/etc/redis/6379.conf REDIS_DATA_DIR=`cat $CONF | grep -Ev "grep|^#"|grep "dir"|awk '{print $2}'|sed -r 's/"//g'` BACKUP_DIR=/data/redis/backup BACKUP_FILE=`ls $BACKUP_DIR |grep -Ev "grep"| grep $1 ` if [ -f $REDIS_DATA_DIR/dump.rdb ];then echo -e "\033[41;37m ERROR:dump.rdb exits !!! \033[0m" exit 1 fi echo -e "\033[40;33m Coping $BACKUP_FILE to $REDIS_DATA_DIR ... \033[0m" cp $BACKUP_DIR/$BACKUP_FILE $REDIS_DATA_DIR \ && mv $REDIS_DATA_DIR/$BACKUP_FILE $REDIS_DATA_DIR/dump.rdb \ `chown -R redis.redis $REDIS_DATA_DIR/` \ && echo -e "\033[40;32m OK \033[0m" ~~~ 1. service redis stop 2. 确认dir目录下没有dump.rdb文件 3. 执行./redisRecover.sh 08-29 命令(表示还原到8月29日的数据) 4. service redis start