Created
April 21, 2017 18:43
-
-
Save mikedotexe/f765acc6489ff9ad3cbaa1da1418fe1d to your computer and use it in GitHub Desktop.
Bash script to run postgres backup using AWS CLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PATH=/usr/bin:/bin:/home/ubuntu/.local/bin:$PATH | |
# create dump file | |
TIMESTAMP=$(date +%Y-%m-%d--%H_%M_%S) | |
FILENAME="ridelist_"$TIMESTAMP".dump" | |
pg_dump -U postgres -h localhost -p 6059 ridelist > $FILENAME | |
# compress | |
tar czvf $FILENAME".tar.gz" $FILENAME | |
# upload to S3 | |
# get access to the AWS keys | |
# the environment variable for AWS CLI is located at ~/.aws/credentials | |
# format: http://docs.aws.amazon.com/cli/latest/topic/config-vars.html#config-file-format | |
# the credentials are found in ~/.aws/config | |
aws s3 cp $FILENAME".tar.gz" s3://untold-ride-list-backups/ | |
# if it completed successfully | |
# see http://docs.aws.amazon.com/cli/latest/topic/return-codes.html | |
if [ $? -eq 0 ]; then | |
# remove compressed backup | |
rm $FILENAME".tar.gz" | |
fi | |
# remove uncompressed backup | |
rm $FILENAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment