Created
April 15, 2016 14:32
-
-
Save jbearden0/b3b5273da1d4018407a4011fe9a144c5 to your computer and use it in GitHub Desktop.
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 | |
BACKUPTIME="$(date '+%Y%m%dT%H%M%S%z')" | |
BACKUPLOC=/home/backups | |
DBDIR=/var/lib/firebird/2.5/data | |
DBNAME=rsgdata | |
PASSLOC=/etc/firebird/2.5/SYSDBA.password | |
LEVEL=${1:-0} | |
COUNT=8 | |
FILETOTAL=$(stat -c%s "$DBDIR/$DBNAME.gdb") | |
PARTTOTAL=$(expr $(df -k $BACKUPLOC | sed -n 2p | awk '{print $2}') \* 1000) | |
PARTAVAIL=$(expr $(df -k $BACKUPLOC | sed -n 2p | awk '{print $3}') \* 1000) | |
ESTIMATED=$(expr $(expr $(expr $PARTTOTAL - $PARTAVAIL - $FILETOTAL) \* 100) / $PARTTOTAL) | |
if [ $ESTIMATED -lt 20 ]; then | |
echo "Not enough disk space to backup $DBDIR/$DBNAME.gdb to $BACKUPLOC !" | |
elif [ $FILETOTAL -gt 6000000000 ]; then | |
echo "Database file $DBDIR/$DBNAME.gdb is too big!" | |
elif [ ! -e $PASSLOC ]; then | |
echo "Database password file does not exist!" | |
else | |
source $PASSLOC | |
# /usr/bin/nbackup -U $ISC_USER -P $ISC_PASSWORD -B ${LEVEL} ${DBNAME} ${BACKUPLOC}/$(hostname).${DBNAME}-${BACKUPTIME}-level${LEVEL}.nbk | |
/usr/bin/gbak -user $ISC_USER -pas $ISC_PASSWORD -b localhost:${DBNAME} ${BACKUPLOC}/$(hostname).${DBNAME}-${BACKUPTIME}.gbk | |
/bin/gzip ${BACKUPLOC}/$(hostname).${DBNAME}-${BACKUPTIME}.gbk | |
fi | |
REMOVE=$(/usr/bin/find ${BACKUPLOC} -maxdepth 1 -type f -name '*nbk*' | sort -n -r | tail -n +$(( $COUNT + 1))) | |
if test -n "${REMOVE}"; then | |
rm ${REMOVE} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment