Skip to content

Instantly share code, notes, and snippets.

@nekoruri
Last active December 21, 2015 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nekoruri/6238957 to your computer and use it in GitHub Desktop.
Save nekoruri/6238957 to your computer and use it in GitHub Desktop.
RedisのBGSAVEコマンドを実行し、LASTSAVEが更新されるのを待つ。 タイムアウト時間を超えたら exit status 1 で終了する。
#!/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