Created
January 8, 2013 21:27
-
-
Save rob-murray/4488126 to your computer and use it in GitHub Desktop.
A(nother) MySql database backup shell script
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/sh | |
##################################### | |
### Backup script - run_backup.sh ## | |
##################################### | |
### Desc: Runs backup on MYSQL ## | |
### database and then emails to ## | |
### confirm ## | |
##################################### | |
# Settings | |
MY_USER="YOUR DB USERNAME" | |
MY_PWORD="PASSWORD" | |
MY_DATABASE="NAME OF DATABASE" | |
# Email To ? | |
EMAIL="YOUR EMAIL ADDRESS" | |
# Get hostname | |
HOST="$(hostname)" | |
# Get date | |
NOW="$(date +"%d-%m-%Y")" | |
################################### | |
# Do backup | |
cd /home/PATH TO BACK UP FOLDER/ | |
mysqldump -u$MY_USER -p$MY_PWORD $MY_DATABASE > $NOW.sql | |
tar -zcvf "Backup"_$NOW.tgz *.sql | |
rm *.sql | |
################################### | |
# Build and send email | |
# email subject | |
SUBJECT="Database backup - "$NOW | |
# Email text/message | |
EMAILMESSAGE="/tmp/emailmessage.txt" | |
echo "CRON JOB has backed up database: "$MY_DATABASE" by User: "$MY_USER" on Server: "$HOST >$EMAILMESSAGE | |
echo " ">> $EMAILMESSAGE | |
echo "This was completed on date: "$NOW>> $EMAILMESSAGE | |
echo " ">> $EMAILMESSAGE | |
echo "Webmaster.">> $EMAILMESSAGE | |
# send an email using /bin/mail | |
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE | |
#remove the temp file | |
rm $EMAILMESSAGE | |
############################################################## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment