Last active
March 31, 2019 17:11
-
-
Save jbroadway/a669e25fc4a71fa11ad3801745947090 to your computer and use it in GitHub Desktop.
A simple Elefant CMS backup script to Amazon S3 (requires s3cmd)
This file contains 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 | |
# 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 |
This file contains 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
# 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