Skip to content

Instantly share code, notes, and snippets.

@jbroadway
Last active March 31, 2019 17:11
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 jbroadway/a669e25fc4a71fa11ad3801745947090 to your computer and use it in GitHub Desktop.
Save jbroadway/a669e25fc4a71fa11ad3801745947090 to your computer and use it in GitHub Desktop.
A simple Elefant CMS backup script to Amazon S3 (requires s3cmd)
#!/bin/bash
# modify these as needed
BUCKET=bucketname
HOSTNAME=example.com
ROOT=/usr/share/nginx/html
BACKUP=/usr/share/nginx/backup
# ensure backup folder exists
mkdir -p $BACKUP
STAMP=`date +"%s - %A %d %B %Y @ %H%M"`
# export the database
cd $ROOT
./elefant export-db $BACKUP/db-$STAMP.sql
# gzip the site and database
tar -czf $BACKUP/site-$STAMP.tar.gz $ROOT $BACKUP/db-$STAMP.sql
cd $BACKUP
rm db-$STAMP.sql
# backup to s3
s3cmd put "$BACKUP/site-$STAMP.tar.gz" "s3://$BUCKET/$HOSTNAME/site-$STAMP.tar.gz" > /var/log/s3backup.log 2>&1 &
# sleep for 5 seconds while file uploads
sleep 5
# remove tmp file
rm -f site-$STAMP.tar.gz
# Backup nightly at 2:00 AM
0 2 * * * /path/to/s3backup.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment