Last active
December 19, 2015 22:09
-
-
Save Raven24/6025663 to your computer and use it in GitHub Desktop.
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 | |
############################# | |
#### MySQL Backup Script #### | |
############################# | |
########## CONFIG ########### | |
OUTPUT_FOLDER="/home/server/DBbackup" | |
ROOT_USER="root" | |
ROOT_PASS="" | |
############################# | |
SUBFOLDER=`date '+%Y-%m'` | |
DATE_STR=`date '+%Y-%m'`_`date '+%a'` | |
BAKFILE=`echo "sqldump_$DATE_STR" | tr '[:upper:]' '[:lower:]'` | |
BAKFOLDER="$OUTPUT_FOLDER/$SUBFOLDER" | |
# create a sql dump | |
TMPFILE="$OUTPUT_FOLDER/$BAKFILE.sql" | |
OUTFILE="$BAKFOLDER/$BAKFILE.sql.xz" | |
mysqldump -u$ROOT_USER -p$ROOT_PASS --opt --all-databases > "$TMPFILE" | |
# make sure backup folder exists | |
if [ ! -d "$BAKFOLDER" ] ; then | |
mkdir "$BAKFOLDER" | |
fi | |
# compress the backup | |
xz -c "$TMPFILE" > "$OUTFILE" | |
# cleanup | |
rm "$TMPFILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment