Last active
December 21, 2015 02:59
-
-
Save nekoruri/6238957 to your computer and use it in GitHub Desktop.
RedisのBGSAVEコマンドを実行し、LASTSAVEが更新されるのを待つ。
タイムアウト時間を超えたら exit status 1 で終了する。
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/bash | |
# RedisのBGSAVEコマンドを実行し、LASTSAVEが変わる(=dump.rdbが更新される)のを待つ。 | |
# タイムアウト時間を超えたら exit status 1 で終了する。 | |
TIMEOUT=30 | |
# Timeout handler | |
# http://stackoverflow.com/questions/1226094/how-to-include-a-timer-in-bash-scripting | |
set_timer() { | |
trap handle_timer ALRM | |
(sleep $TIMEOUT; kill -ALRM $$)& | |
timer_pid=$! | |
} | |
unset_timer() { | |
kill $timer_pid | |
trap - ALRM | |
} | |
handle_timer() { | |
exit 1 | |
} | |
export PATH=/bin:/usr/bin | |
set_timer | |
# 丁度この瞬間に組込のBGSAVEが走る可能性があるので、 | |
# BGSAVEの前にLASTSAVEを取得 | |
LASTSAVE=`redis-cli LASTSAVE` | |
redis-cli BGSAVE | |
# LASTSAVEが変わるまで待つ。 | |
while [ $LASTSAVE == `redis-cli LASTSAVE` ]; do | |
sleep 1 | |
done | |
unset_timer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment