Created
August 30, 2016 20:29
-
-
Save blobaugh/a7c114f1f935a7a19d23ef6f5f626649 to your computer and use it in GitHub Desktop.
Quick and dirty db backup. Stores backups for 30 days
This file contains 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 | |
# Database credentials | |
user="USERNAME" | |
password="PASSWORD" | |
host="HOST" | |
db_name="DATABASE" | |
# General config | |
backup_path="/WHERE/TO/PUT/BACKUP/FILE" | |
date=$(date +"%b-%d-%Y") | |
# Set default file permissions | |
umask 177 | |
backup_file=$backup_path/$date-$db_name.sql.gz | |
# Backup and compress database | |
mysqldump -u $user -p$password -h $host $db_name | gzip > $backup_file | |
# Notify Brad Williams about the backup file | |
if [ -f $backup_file ]; then | |
echo "Microsoft Dynamics PROD DB Successfully backed up" | mail -s "DB Backup Successful" -r YOUR@EMAIL.ADDRESS | |
else | |
echo "Microsoft Dynamics PROD DB backup FAILED" | mail -s "DB Backup FAILED!!!" -r YOUR@EMAIL.ADDRESS | |
fi | |
# Delete files older than 30 days | |
find $backup_path/* -mtime +30 -exec rm {} \; | |
~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment