Created
May 18, 2015 13:57
-
-
Save sitano/0b5d557ec6b95122e2e8 to your computer and use it in GitHub Desktop.
Force redis sync rdb snapshot, backup, tar gzip pack and rotate older then 5 days
This file contains hidden or 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 | |
# 25 0 * * * /root/redis.backup.sh | |
PRIVATE_IPV4=`cat /etc/network/interfaces | grep -A 2 'iface eth1' | head -n +2 | tail -n 1 | awk '{print $2}'` | |
# 1. Dump RDB | |
(printf "select 2\r\nsave\r\n" | nc ${PRIVATE_IPV4} 6379) || exit 1 | |
# 2. Copy dump | |
SRCPATH="/var/lib/redis/6379" | |
SRCFILE="dump.rdb" | |
DESTPATH="/var/lib/backup/redis" | |
DESTFILE=`date '+%Y-%m-%d-%H%M%S'`-redis-topx.rdb.tar.gz | |
DEST="${DESTPATH}/${DESTFILE}" | |
cd ${SRCPATH} && tar cfz ${DEST} ${SRCFILE} | |
# 3. Manage soft link | |
SOFT="${DESTPATH}/redis-topx.rdb.tar.gz" | |
ln -Tfs ${DEST} ${SOFT} | |
# 4. Rotate old | |
find ${DESTPATH}/*-redis-topx.rdb.tar.gz -mtime +5 -exec rm {} \; > /dev/null 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment