Skip to content

Instantly share code, notes, and snippets.

@jackkinsella
Created April 15, 2011 11:11
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save jackkinsella/921535 to your computer and use it in GitHub Desktop.
Save jackkinsella/921535 to your computer and use it in GitHub Desktop.
Taps isn't reliable for anything but dummy databases. This command invokes the more powerful PGBackups. A side effect is that every time you pull your database locally a backup is also generated on your server.
#!/bin/bash
# Best use case is to create a file "update_local_db.sh" in your project folder and then call the command with bash update_local_db
# Follow me: @jackkinsella
function LastBackupName () {
heroku pgbackups | tail -n 1 | cut -d"|" -f 1
}
# This part assumes you have a low limit on no. of backups allowed
old_backup=$(LastBackupName)
heroku pgbackups:destroy $old_backup
heroku pgbackups:capture
new_backup=$(LastBackupName)
curl $(heroku pgbackups:url $new_backup) > temporary_backup.dump
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U REPLACE_WITH_YOUR_USER -d REPLACE_WITH_YOUR_DB_NAME temporary_backup.dump
rm -f temporary_backup.dump
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment