Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TSTART=`date +%s`
- LDATE=`date "+%Y%m%d%H%M"`
- DBUSER='bkpuser'
- DBPASS='SANITIZED'
- BKPDIR='/backup/accounting-bkp'
- LOGDIR='/backup/accounting-bkp-logs'
- BKPLOG="${LOGDIR}/accounting_backup.log"
- LOCK_FILE="/tmp/accounting_backup.lock"
- STATUSFILE="${LOGDIR}/accounting_backup.status"
- RSYNC_BIN="/usr/bin/rsync"
- RSYNC_OPTIONS="-azq --numeric-ids --timeout=172800 --delete-before --delete"
- REMOTESERVER=backups.gammanetworking.com
- DESTINATION="${REMOTESERVER}::`hostname`/"
- #Function to write in the log file
- #what is passed in first param.
- write_to_log() {
- TIMESTAMP=`date "+%b %d %T"`
- echo -e "$TIMESTAMP $1" >> $BKPLOG
- }
- #Try to get lock file
- exec 8>$LOCK_FILE;
- flock --nonblock --exclusive 8
- # If we were able to get exclusive lock
- if [ $? -eq 0 ]; then {
- # Initialize the backup file
- > $BKPLOG
- write_to_log "[INFO] Dump of workspace_accounting database started"
- # Start the dump of the database, redirect any error messages to the
- # log file
- /bin/mysqldump -S /var/lib/mysql/mysql.sock --user=${DBUSER} --password=${DBPASS} --databases workspace_accounting --single-transaction --add-drop-database > $BKPDIR/workspace_accounting.sql 2>${BKPLOG}
- # Was the backup successful?
- if [ $? -eq 0 ]; then {
- #Yes, backup was successful
- write_to_log "[INFO] Dump of workspace_accounting database completed successfully"
- #Ship this backup over to the backup server
- write_to_log "[INFO] Shipping the backup over to ${REMOTESERVER}..."
- ${RSYNC_BIN} ${RSYNC_OPTIONS} ${BKPDIR} ${DESTINATION} >> $BKPLOG 2>&1
- if [ $? -eq 0 ] ; then
- write_to_log "[INFO] Shipment completed successfully"
- else
- write_to_log "[ERROR] Shipment failed, please check the log files!"
- fi
- } else {
- # Reaching here, the backup failed for some reason
- write_to_log "[ERROR] Dump failed, please check the log files"
- exit 1;
- }
- fi
- #All steps have completed successfully!
- write_to_log "[INFO] All backup steps have completed successfully!"
- exit 0;
- } else {
- #Failed to get the exclusive lock
- write_to_log "Can't get exclusive lock"
- exit 1;
- }
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement