Skip to content

Instantly share code, notes, and snippets.

@jwood
Created November 17, 2010 14:28
Show Gist options
  • Save jwood/703438 to your computer and use it in GitHub Desktop.
Save jwood/703438 to your computer and use it in GitHub Desktop.
Create a pgbackup on Heroku for a given project, and then download it for local storage
#!/usr/bin/ruby
#
# This script assumes that you have either 0 or 1 pgbackups stored
# on Heroku, and that you already have the heroku gem installed
# and configured on your system.
#
PROJECT_DIRECTORY = "/home/jwood/dev/myproj"
BACKUP_FILE = "/home/jwood/backup/myproj.dump"
def log(message)
puts message
end
Dir.chdir(PROJECT_DIRECTORY)
list = `heroku pgbackups`
unless list =~ /No backups/
list =~ /^(b\d+)/
backup_id = $1
log "Found backup '#{backup_id}'. Proceeding to delete it."
`heroku pgbackups:destroy #{backup_id}`
else
log "No backups found"
end
log "Capturing new backup"
`heroku pgbackups:capture`
log "Fetching url for backup"
url = `heroku pgbackups:url`
log "Downloading backup file"
system("wget \"#{url.strip}\" -O #{BACKUP_FILE}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment