Created
March 2, 2018 15:46
-
-
Save jhyland87/7d0ee9f09ff6462d3d37604b8dd5a35a 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 | |
# Backup mysql databases nightly | |
# Scott B. | |
# 6/2/2013 | |
# Create a current date string | |
DATE=`date +%Y.%m.%d-%H.%M.%S` | |
BACKUP_DIR=/mnt/CHD_DB_BACKUP/ | |
BACKUP_FILE=$BACKUP_DIR$DATE"_Mysql44_databases.sql" | |
echo "------------- MySQL Backup Starting on " $DATE " -------------" | |
# Back up all databases to one file | |
#mysqldump --single-transaction --all-databases --add-drop-database > $BACKUP_FILE | |
mysqldump --single-transaction --all-databases --add-drop-database | bzip2 -c > $BACKUP_FILE | |
END_DATE=`date +%Y.%m.%d-%H.%M.%S` | |
echo "------------- MySQL Backup Complete at " $END_DATE " -------------" | |
COMP_DATE=`date +%Y.%m.%d-%H.%M.%S` | |
echo "------------- MySQL Compression Starting on " $COMP_DATE " -------------" | |
# Compress previous backup(s) - Do not compress tonight's backup (18 hours old) | |
# It is needed for staging refresh (until staging moves to PNAP) | |
#find $BACKUP_DIR -type f -mmin +1080 -exec bzip2 {} \; | |
# Clean up the backup space - keep 5 days of backups | |
find $BACKUP_DIR -type f -mtime +5 -exec rm -f {} \; | |
COMP_END_DATE=`date +%Y.%m.%d-%H.%M.%S` | |
echo "------------- MySQL Compression Complete at " $COMP_END_DATE " -------------" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment