Created
October 21, 2012 18:11
-
-
Save mitio/3927935 to your computer and use it in GitHub Desktop.
Simple database backup script for our teaching websites' DBs
This file contains hidden or 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/sh | |
PROJECT=$1 # E.g. pyfmi | |
EDITION=$2 # E.g. 2012 | |
if [ -z "$PROJECT" ] | |
then | |
echo Usage: $0 project edition | |
echo E.g.: $0 pyfmi 2012 | |
exit 1 | |
fi | |
PROJECT_PATH=/data/rails/$PROJECT-$EDITION/current | |
TMPDIR=/tmp/$PROJECT-$EDITION-db/db | |
S3SYNC=/root/s3sync/s3sync.rb | |
AS_USER=pyfmi | |
# Prepare the backup location | |
test -d $TMPDIR || mkdir -p $TMPDIR | |
TMPNAME=$TMPDIR/${PROJECT}_$EDITION.dump | |
rm -f $TMPNAME | |
chown $AS_USER:$AS_USER $TMPDIR | |
echo Backing up from $PROJECT_PATH to $TMPNAME... | |
su - $AS_USER -c "cd $PROJECT_PATH && bundle exec rake backup[$TMPNAME] RAILS_ENV=production" | |
if [ -e $TMPNAME ]; then | |
echo Sending backup to S3... | |
$S3SYNC -v -r --ssl $TMPDIR pyfmi: | |
echo All done. | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment