Skip to content

Instantly share code, notes, and snippets.

@sowenjub
Created June 19, 2011 07:29
Show Gist options
  • Select an option

  • Save sowenjub/1033876 to your computer and use it in GitHub Desktop.

Select an option

Save sowenjub/1033876 to your computer and use it in GitHub Desktop.

Revisions

  1. sowenjub revised this gist Jun 19, 2011. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -7,8 +7,6 @@

    # Just replace any uppercase string with your own data

    # Let's head to the place where you'd like to keep a copy of the dump in case anything goes wrong

    #
    # CAPTURE
    #
  2. sowenjub created this gist Jun 19, 2011.
    32 changes: 32 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    #!/bin/bash

    # This script does the following:
    # 1/ capture and download the latest backup
    # 2/ load it to your local database
    # 3/ run your app and open Safari

    # Just replace any uppercase string with your own data

    # Let's head to the place where you'd like to keep a copy of the dump in case anything goes wrong

    #
    # CAPTURE
    #
    cd YOUR_LOCAL_BACKUP_FOLDER
    heroku pgbackups:capture --expire --app YOUR_APP_NAME
    file_path="db_$(date +%Y_%m_%d-%H_%M_%S).dump"
    curl `heroku pgbackups:url --app YOUR_APP_NAME` > $file_path

    #
    # LOAD
    #
    pg_restore --verbose --clean --no-acl --no-owner -h localhost -u YOUR_LOCAL_DB_USERNAME -d YOUR_LOCAL_DB_NAME $file_path
    cd YOUR_LOCAL_APP # for me something like ~/Sites/app_name

    #
    # RUN
    #
    # Tell to launch Safari after 10 seconds, which should be enough to load the server
    eval "sleep 10; open -a Safari http://localhost:3001/" &
    # Run your app. I use an environment with caching which is closer to the production environment than my standard dev environment.
    bundle exec thin start -e dev_with_caching -p 3001