Skip to content

Instantly share code, notes, and snippets.

@quangthe
Created March 21, 2019 09:28
Show Gist options
  • Save quangthe/8fe0d3e5d4ceefd47cccb540f862e20e to your computer and use it in GitHub Desktop.
Save quangthe/8fe0d3e5d4ceefd47cccb540f862e20e to your computer and use it in GitHub Desktop.
Restore tienluong db from dump/snapshot file (stored in S3)
#!/usr/bin/env bash
# Run this script to prepare DB for "prod" profile.
# Require environment variable:
# AWS_ACCESS_KEY_ID
# AWS_SECRET_ACCESS_KEY
set -e
BUCKET=dtcorpbackup
echo "Get latest backup"
OBJECT="$(aws s3 ls $BUCKET --recursive | sort | tail -n 1 | awk '{print $4}')"
aws s3 cp s3://$BUCKET/$OBJECT $OBJECT
echo "Restore DB to latest backup"
cat $OBJECT | docker exec -i tienluong-db psql -U postgres
rm $OBJECT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment