You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
#!/bin/sh
set -eo pipefail
if [ "${S3_ACCESS_KEY_ID}" == "**None**" ]; then echo "Warning: You did not set the S3_ACCESS_KEY_ID environment variable." fi
if [ "${S3_SECRET_ACCESS_KEY}" == "**None**" ]; then echo "Warning: You did not set the S3_SECRET_ACCESS_KEY environment variable." fi
if [ "${S3_BUCKET}" == "**None**" ]; then echo "You need to set the S3_BUCKET environment variable." exit 1 fi
if [ "${MYSQL_HOST}" == "**None**" ]; then echo "You need to set the MYSQL_HOST environment variable." exit 1 fi
if [ "${MYSQL_USER}" == "**None**" ]; then echo "You need to set the MYSQL_USER environment variable." exit 1 fi
if [ "${MYSQL_PASSWORD}" == "**None**" ]; then echo "You need to set the MYSQL_PASSWORD environment variable or link to a container named MYSQL." exit 1 fi
if [ "${S3_IAMROLE}" != "true" ]; then # env vars needed for aws tools - only if an IAM role is not used export AWS_ACCESS_KEY_ID=$S3_ACCESS_KEY_ID export AWS_SECRET_ACCESS_KEY=$S3_SECRET_ACCESS_KEY export AWS_DEFAULT_REGION=$S3_REGION fi
if [ "${S3_ENDPOINT}" == "**None**" ]; then AWS_ARGS="" else AWS_ARGS="--endpoint-url ${S3_ENDPOINT}" fi
if [ "${S3_FILENAME}" == "**None**" ]; then echo "Finding latest backup" S3_FILENAME=$(aws $AWS_ARGS s3 ls s3://$S3_BUCKET/$S3_PREFIX/ | sort | tail -n 1 | awk '{ print $4 }') fi
MYSQL_HOST_OPTS="${MYSQL_OPTS} -h $MYSQL_HOST -P $MYSQL_PORT -u$MYSQL_USER -p$MYSQL_PASSWORD"
echo "Fetching ${S3_FILENAME} from S3"
aws $AWS_ARGS s3 cp s3://$S3_BUCKET/$S3_PREFIX/${S3_FILENAME} dump.sql.gz gzip -d dump.sql.gz
echo "Restoring ${S3_FILENAME}"
mysql $MYSQL_HOST_OPTS < dump.sql
echo "MySQL Restore complete"
|