Skip to content

Instantly share code, notes, and snippets.

@jbroadway jbroadway/s3backup.sh
Last active Mar 31, 2019

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