Created
July 3, 2013 20:30
-
-
Save AlexPashley/5922527 to your computer and use it in GitHub Desktop.
SHELL: Simple Shell Script to create database backups
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
# Backup mysql databases into seperate files | |
USER="mysql-username" | |
PASSWORD="mysql-password" | |
OUTPUTDIR="/path/to/db/backup/dir" | |
MYSQLDUMP="/usr/bin/mysqldump" | |
MYSQL="/usr/bin/mysql" | |
NOW=$(date +"%m-%d-%Y") | |
MSG="Just to let you know that a full backup of db has been made onto the VPS.Kind Regards" | |
# Remove previous backups | |
rm "$OUTPUTDIR/*bak" > /dev/null 2>&1 | |
# get a list of databases | |
databases=`$MYSQL --user=$USER --password=$PASSWORD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database` | |
# dump each database in turn | |
for db in $databases; do | |
echo $db | |
$MYSQLDUMP --force --opt --user=$USER --password=$PASSWORD --databases $db > "$OUTPUTDIR/$db.bak" | |
done | |
# emaili reminder of backup | |
echo $MSG | mail -s "VPS Server Backup - Backup Created on $NOW" [email protected] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment