Last active
December 5, 2018 14:28
-
-
Save populov/399840e8149f7797c18c1bba43c2b3fc to your computer and use it in GitHub Desktop.
Import local development DB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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