Skip to content

Instantly share code, notes, and snippets.

@burdandrei
Created March 10, 2015 14:49
Show Gist options
  • Save burdandrei/1590bbe19e9b93dd9a59 to your computer and use it in GitHub Desktop.
Save burdandrei/1590bbe19e9b93dd9a59 to your computer and use it in GitHub Desktop.
Simple script to back up your bitnami app to s3
#!/bin/bash
#
# Script for backing up bitnami app and upload tarballs to S3
set -e
usage(){
echo "Usage: BITNAMI_APP=<> BITNAMI_DB_PASSWORD=<> S3_BUCKET=<> $0"
exit 1
}
# Checking We have all the Information
if [[ -z $BITNAMI_APP ]]; then
echo "BITNAMI_APP is not provided" 1>&2
usage
exit 1
fi
if [[ -z $BITNAMI_DB_PASSWORD ]]; then
echo "BITNAMI_DB_PASSWORD is not provided" 1>&2
usage
exit 1
fi
if [[ -z $S3_BUCKET ]]; then
echo "S3_BUCKET is not provided" 1>&2
usage
exit 1
fi
CONNECTION_STRING="-h localhost -u bn_${BITNAMI_APP} -p${BITNAMI_DB_PASSWORD}"
DATABASE_NAME="bitnami_${BITNAMI_APP}"
BACKUP_DATE=$(date +%Y_%m_%d-%s)
BACKUP_DIR=$(mktemp -d)
/opt/bitnami/mysql/bin/mysqldump --single-transaction -R $CONNECTION_STRING $DATABASE_NAME | gzip -6 > ${BACKUP_DIR}/${DATABASE_NAME}_${BACKUP_DATE}.gz
tar czf ${BACKUP_DIR}/${BITNAMI_APP}_files_${BACKUP_DATE}.tgz /opt/bitnami/apps/${BITNAMI_APP}/htdocs/*
s3cmd put ${BACKUP_DIR}/${DATABASE_NAME}_${BACKUP_DATE}.gz s3://$S3_BUCKET/
s3cmd put ${BACKUP_DIR}/${BITNAMI_APP}_files_${BACKUP_DATE}.tgz s3://$S3_BUCKET/
rm -rf $BACKUP_DIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment