Created
January 19, 2012 15:27
-
-
Save virtualstaticvoid/1640598 to your computer and use it in GitHub Desktop.
Automate Heroku database backups
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 | |
# | |
# Script to create and download a database backup on Heroku | |
# Written by Chris Stefano (https://github.com/virtualstaticvoid) | |
# | |
# See http://devcenter.heroku.com/articles/pgbackups for details | |
# | |
appname=$1 | |
filename=${appname}_db_$(date +%Y%m%d)_$(date +%H%M).pg_backup | |
# list backup | |
# heroku pgbackups --app $appname | |
# may need to delete old backups: | |
# heroku pgbackups:destroy XXXX --app $appname | |
# create a backup | |
heroku pgbackups:capture --app $appname | |
# get the temp URL for it (AWS S3) | |
backup_url=`heroku pgbackups:url --app $appname` | |
# download it locally | |
curl -o $filename $backup_url |
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 | |
# Script to "clean up" old database backups on Heroku | |
# Written by Chris Stefano (https://github.com/virtualstaticvoid) | |
# | |
# See http://devcenter.heroku.com/articles/pgbackups for details | |
# | |
# NOTE: Heroku seems to only allow 2 backups at any given time, presumable on the free tier?, | |
# | |
# !!! USE AT YOUR OWN RISK!!! | |
# | |
appname=$1 | |
# get the backup line-items from the `pgbackups` command | |
backup=`heroku pgbackups --app $appname | grep ^b[0-9]*` | |
# extract the name of it | |
backup_name=${backup:0:4} | |
# BE GONE!!! | |
heroku pgbackups:destroy $backup_name --app $appname |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! Thanks for this. :)
I took the liberty of forking and making a few tweaks of my own; you might be interested:
--expire
option, removing need for second script (I think).dump
extensionhttps://gist.github.com/tiredpixel/4774216