Last active
August 29, 2015 13:56
-
-
Save i97506051502/9339291 to your computer and use it in GitHub Desktop.
Redis バックアップ用シェルスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Variables | |
# | |
MAIL_ADDRESS="ok@example.com" | |
MAIL_SUBJECT='Redis Backup ends with No Error.' | |
ALERT_MAIL_ADDRESS="ng@example.com" | |
ALERT_MAIL_SUBJECT='Redis Backup ends with Some Error!!' | |
RDB_FILE='/var/redis/6379/dump.rdb' | |
RDB_INODE_BEFORE=`ls -i ${RDB_FILE} | cut -d ' ' -f1` | |
# | |
# Backup Redis Data | |
# | |
REDIS_CLI=`which redis-cli` | |
if [ $? != 0 ] | |
then | |
echo 'redis-cli does not exist or is not in your PATH!!' | mailx -s ${ALERT_MAIL_SUBJECT} "ng@example.com" | |
else | |
${REDIS_CLI} bgsave | |
fi | |
while true | |
do | |
RDB_INODE_AFTER=`ls -i ${RDB_FILE} | cut -d ' ' -f1` | |
if [ ${RDB_INODE_BEFORE} != ${RDB_INODE_AFTER} ] | |
then | |
RDB_CHECK=`redis-check-dump ${RDB_FILE} | tail -1` | |
if [ "${RDB_CHECK}" = "CRC64 checksum is OK" ] | |
then | |
NUMBER_OF_DATA=`redis-cli dbsize | cut -d ' ' -f2` | |
echo "Redis Backup ends with No Error. Number of Data is ${NUMBER_OF_DATA}." | mailx -s ${MAIL_SUBJECT} "ok@example.com" | |
# scp などでリモートサーバーにコピー | |
break | |
else | |
echo "Redis Backup ends with Some Error!!" | mailx -s ${ALERT_MAIL_SUBJECT} "ng@example.com" | |
break | |
fi | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment