Last active
September 15, 2016 21:09
-
-
Save demofly/dc25af40e13d4d0a5bf9a8c4aa0d099e to your computer and use it in GitHub Desktop.
/root/scripts/rabbit-backup.sh
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 | |
DT=`date +'%Y%m%d-%H%M%S'` | |
BKPDIR=/var/backups/rabbitmq | |
BKPSYMLINK="${BKPDIR}/current" | |
BKPFILE="${BKPDIR}/rabbitmq.config.${DT}" | |
test -d "${BKPDIR}" || mkdir -pv "${BKPDIR}" | |
ln -sfv `find /var/lib/rabbitmq/mnesia/ -name rabbitmqadmin | head -n1` /usr/local/bin/ | |
chmod a+x -v /usr/local/bin/rabbitmqadmin | |
echo /usr/local/bin/rabbitmqadmin export "${BKPFILE}" | |
/usr/local/bin/rabbitmqadmin export "${BKPFILE}" | |
test -e "${BKPSYMLINK}" || touch "${BKPSYMLINK}" | |
diff "${BKPSYMLINK}" "${BKPFILE}" >/dev/null && rm -fv "${BKPFILE}" || ln -sfv "${BKPFILE}" "${BKPSYMLINK}" | |
CURRBKP=`ls -l "${BKPSYMLINK}" | sed 's#.*/##'` | |
echo "Created ${CURRBKP} ..." | |
find "${BKPDIR}" -type f -name 'rabbitmq.config.*' ! -name "${CURRBKP}" -ctime +30 -delete | |
find "${BKPDIR}" -type f -name 'rabbitmq.config.*' ! -name "${CURRBKP}" -size 0c -delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment