Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@MattLoyeD
Created July 21, 2015 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MattLoyeD/d979be3600da36c52f1a to your computer and use it in GitHub Desktop.
Save MattLoyeD/d979be3600da36c52f1a to your computer and use it in GitHub Desktop.
Backup your files and DB to S3
#!/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