Skip to content

Instantly share code, notes, and snippets.

@ivobenedito
Created February 16, 2017 19:23
Show Gist options
  • Select an option

  • Save ivobenedito/a6bbb506874a17943b4a0f01ba9a3a72 to your computer and use it in GitHub Desktop.

Select an option

Save ivobenedito/a6bbb506874a17943b4a0f01ba9a3a72 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Exit if any subcommand fails
set -e
USER=<INSERT_USER_HERE>
PASSWORD=<INSERT_PASSWORD_HERE>
HOST=<INSERT_HOST_HERE>
EXCLUDED_TABLES='(table1|table2|table3)'
DB_NAME=<INSERT_DB_NAME_HERE>
FILE=$PWD/tmp/dump.sql
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NO_COLOR='\033[0m'
CLEAR_LINE='\r\033[K'
printf "${CLEAR_LINE}[1/5]⏳ Setting up Ruby dependencies via Bundler\n"
gem install bundler --conservative
bundle check || bundle install
printf "${CLEAR_LINE}[2/5]⏳ Recreating local database"
RAILS_ENV=development bin/rake db:drop
RAILS_ENV=development bin/rake db:create
printf "${GREEN} [OK]${NO_COLOR}\n"
printf "${CLEAR_LINE}[3/5]⏳ Creating Dump"
PGPASSWORD=$PASSWORD pg_dump -U $USER -h $HOST ebdb --exclude-table-data=$EXCLUDED_TABLES > $FILE
printf "${GREEN} [OK]${NO_COLOR}\n"
printf "${CLEAR_LINE}[4/5]⏳ Importing Dump"
psql $DB_NAME < $FILE
printf "${GREEN} [OK]${NO_COLOR}\n"
printf "${CLEAR_LINE}[5/5]⏳ Removing Dump"
rm $FILE
printf "${GREEN} [OK]${NO_COLOR}\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment