Skip to content

Instantly share code, notes, and snippets.

@populov
Last active December 5, 2018 14:28
Show Gist options
  • Select an option

  • Save populov/399840e8149f7797c18c1bba43c2b3fc to your computer and use it in GitHub Desktop.

Select an option

Save populov/399840e8149f7797c18c1bba43c2b3fc to your computer and use it in GitHub Desktop.
Import local development DB
#!/usr/bin/env bash
DATABASE=dbname
CHECK_TABLE=Users
SQL_DUMP_FILE='dump_2018-01-01.sql'
BUCKET='https://s3-us-west-2.amazonaws.com/mybucket'
# Check if table exists
if [[ $(mysql -h'db' -u'user' -p'secret' -e "SHOW TABLES LIKE '${CHECK_TABLE}'" ${DATABASE}) ]]
then
echo "Database already imported"
else
echo "Restore database"
cd /tmp
wget ${BUCKET}/${SQL_DUMP_FILE}.zip
unzip ${SQL_DUMP_FILE}.zip
rm -rf ${SQL_DUMP_FILE}.zip
mysql -h'db' -u'user' -p'secret' ${DATABASE} < ${SQL_DUMP_FILE}
rm -rf ${SQL_DUMP_FILE}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment