#!/bin/sh
#/ Usage: ghe-s3-backup-all
#/ Take snapshots of all GitHub Enterprise data, including the mysql database
#/ and backup to S3.
set -e

# Bring in the backup configuration
cd $(dirname "$0")/../..
. share/github-backup-utils/ghe-backup-config

if [ -e $HOME/.s3cfg ]; then
  echo "Using existing ~/.s3cfg ..."
else
  # Configure s3cmd if there isn't a config file already.
  s3cmd --configure
fi

# Run the backup script.
ghe-backup

# Create the bucket if it doesn't exist.
s3cmd mb s3://$GHE_S3_BUCKET

# Upload to S3.
cd "$GHE_DATA_DIR"/current
s3cmd --preserve put * s3://$GHE_S3_BUCKET
