Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.