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.

50 lines
1.4 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. #! /bin/sh
  2. set -e
  3. if [ "${S3_ACCESS_KEY_ID}" = "**None**" ]; then
  4. echo "You need to set the S3_ACCESS_KEY_ID environment variable."
  5. exit 1
  6. fi
  7. if [ "${S3_SECRET_ACCESS_KEY}" = "**None**" ]; then
  8. echo "You need to set the S3_SECRET_ACCESS_KEY environment variable."
  9. exit 1
  10. fi
  11. if [ "${S3_BUCKET}" = "**None**" ]; then
  12. echo "You need to set the S3_BUCKET environment variable."
  13. exit 1
  14. fi
  15. if [ "${MYSQL_HOST}" = "**None**" ]; then
  16. echo "You need to set the MYSQL_HOST environment variable."
  17. exit 1
  18. fi
  19. if [ "${MYSQL_USER}" = "**None**" ]; then
  20. echo "You need to set the MYSQL_USER environment variable."
  21. exit 1
  22. fi
  23. if [ "${MYSQL_PASSWORD}" = "**None**" ]; then
  24. echo "You need to set the MYSQL_PASSWORD environment variable or link to a container named MYSQL."
  25. exit 1
  26. fi
  27. # env vars needed for aws tools
  28. export AWS_ACCESS_KEY_ID=$S3_ACCESS_KEY_ID
  29. export AWS_SECRET_ACCESS_KEY=$S3_SECRET_ACCESS_KEY
  30. export AWS_DEFAULT_REGION=$S3_REGION
  31. MYSQL_HOST_OPTS="-h $MYSQL_HOST --port $MYSQL_PORT -u $MYSQL_USER -p$MYSQL_PASSWORD"
  32. echo "Creating dump of ${MYSQLDUMP_DATABASE} database(s) from ${MYSQL_HOST}..."
  33. mysqldump $MYSQL_HOST_OPTS $MYSQLDUMP_OPTIONS $MYSQLDUMP_DATABASE | gzip > dump.sql.gz
  34. echo "Uploading dump to $S3_BUCKET"
  35. cat dump.sql.gz | aws s3 cp - s3://$S3_BUCKET/$S3_PREFIX/$(date +"%Y-%m-%dT%H:%M:%SZ").sql.gz || exit 2
  36. echo "SQL backup uploaded successfully"