Skip to content

Instantly share code, notes, and snippets.

@blobaugh
Created August 30, 2016 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blobaugh/a7c114f1f935a7a19d23ef6f5f626649 to your computer and use it in GitHub Desktop.
Save blobaugh/a7c114f1f935a7a19d23ef6f5f626649 to your computer and use it in GitHub Desktop.
Quick and dirty db backup. Stores backups for 30 days
#!/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