Created
July 21, 2015 13:15
-
-
Save MattLoyeD/d979be3600da36c52f1a to your computer and use it in GitHub Desktop.
Backup your files and DB to S3
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 | |
#-------------------- Config vars -------------------# | |
S3_BUCKET=your_s3_bucket | |
# Files | |
BACKDIR=~/backups | |
BACKTARGET=~/files | |
# Dbs | |
HOST=db_host | |
USER=db_user | |
PASS=db_pass | |
DBS="db1 db2" | |
# Settings | |
NOW_DATE=`date '+%H%M-%m-%d-%Y'` | |
# Let's do it | |
cd ${BACKDIR} ; | |
echo "Backup Files & SQL" ; | |
#------------------- Files Backup -------------------# | |
tar -czPf "${BACKDIR}/files/backup-${NOW_DATE}.tgz" ${BACKTARGET} ; | |
#--------------------- SQL Backup -------------------# | |
mysqldump -h ${HOST} --user=${USER} --password=${PASS} ${DBS} > ${BACKDIR}/sql/backup-${NOW_DATE}.sql ; | |
#---------------------- AWS SYNC --------------------# | |
aws s3 cp ${BACKDIR} s3://${S3_BUCKET}/${BACKDIR} ; | |
#---------------------- Cleaning --------------------# | |
rm -f ${BACKDIR}/files/backup-${NOW_DATE}.tgz $BACKDIR/sql/backup-${NOW_DATE}.sql ; | |
# Done ! | |
echo "Backup done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment