Last active
August 3, 2017 22:30
-
-
Save mitchellurgero/ff27dd0813901dccab738a6d4f1598ad to your computer and use it in GitHub Desktop.
Backup 1 MySQL DB and the /var/www folder to backup websites - Very Basic, and does the job.
This file contains hidden or 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 | |
# Make the following DIR's: | |
# /temp | |
# /backups | |
## START CONFIG | |
TIMESTAMP=$(date +"%F") | |
BACKUP_DIR=/temp/My-Backup-$TIMESTAMP | |
MYSQL_USER="USERNAME" | |
MYSQL=/usr/bin/mysql | |
MYSQL_PASSWORD="PASSWORD" | |
MYSQLDUMP=/usr/bin/mysqldump | |
DATABASE=DB_TO_BACKUP | |
## END CONFIG | |
mkdir -p "$BACKUP_DIR/mysql" | |
$MYSQLDUMP --force --opt --user=$MYSQL_USER -p=$MYSQL_PASSWORD $DATABASE | gzip > "$BACKUP_DIR/mysql/$DATABASE.gz" | |
mkdir -p "$BACKUP_DIR/web_dir" | |
SRCDIR=/var/www/ | |
DESTDIR=$BACKUP_DIR/web_dir/ | |
FILENAME=My-WWW-Backup-$TIMESTAMP.tgz | |
tar --create --gzip --file=$DESTDIR$FILENAME $SRCDIR | |
tar --create --gzip --file=/backups/My-Backup-$TIMESTAMP.tgz $BACKUP_DIR | |
rm -rf /temp/* | |
wait | |
echo "Backup of DB and Web Directory Complete!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment