Last active
August 29, 2015 14:18
-
-
Save joaoffcosta/cca7b897ab2dab655f13 to your computer and use it in GitHub Desktop.
Download latest Heroku DB backup
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
if [ "$1" = "" ]; then | |
echo Missing params: heroku-app-name | |
exit 1 | |
fi | |
if [ "$2" = "" ]; then | |
echo Missing params: dump-prefix | |
exit 1 | |
fi | |
export DATABASE_NAME=JADE | |
echo Heroku app: $1 | |
echo Dump prefix: $2 | |
echo Database: $DATABASE_NAME | |
echo Finding out the correct version... | |
heroku pg:backups -a $1 | grep $DATABASE_NAME > app_backups_list.txt | |
head -n 1 app_backups_list.txt | awk '{ print substr($0, index($0, " +0000") - 19, 19) }' | awk '{ gsub(/[\/ :-]/, ""); print $0 }' > app_backups_last.txt | |
head -n 1 app_backups_list.txt | awk '{ print substr($0, 0, index($0, " ")) }' > app_backups_last_id.txt | |
export APP_LATEST=$2_`tail -n 1 app_backups_last.txt`.dump | |
export APP_LATEST_ID=`tail -n 1 app_backups_last_id.txt` | |
rm app_backups_list.txt | |
rm app_backups_last.txt | |
rm app_backups_last_id.txt | |
echo Saving $APP_LATEST_ID to $APP_LATEST | |
echo # new line | |
read -p "Are you sure you want to continue? [y/N] " -n 1 -r | |
echo # new line | |
if [[ ! $REPLY =~ ^[Yy]$ ]] | |
then | |
echo Exiting... | |
exit 1 | |
fi | |
echo Downloading $APP_LATEST_ID backup... | |
echo # new line | |
curl `heroku pg:backups public-url $APP_LATEST_ID -a $1 | grep https` > ~/Downloads/$APP_LATEST | |
echo #new line | |
echo File is ready at ~/Downloads/$APP_LATEST |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment