Last active
January 14, 2021 20:02
-
-
Save stovak/13e2e61caf6de645bb3ed1e03809750a to your computer and use it in GitHub Desktop.
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 | |
echo "** If terminus is set up incorrectly on this machine, the database download will fail. **" | |
export BACKUP_FILE_NAME=backup.sql.gz | |
export DATABASE_NAME=drupal8 | |
export PANTHEON_SITE_NAME=${milken-institute} | |
### grab local credentials from the .env file | |
export MYSQL_ROOT_PASSWORD=$(grep MYSQL_ROOT_PASSWORD .env | cut -d '=' -f 2-) | |
export DB_HOST=$(grep DB_HOST .env | cut -d '=' -f 2-) | |
export DB_PORT=$(grep DB_PORT .env | cut -d '=' -f 2-) | |
export DB_NAME=$(grep DB_NAME .env | cut -d '=' -f 2-) | |
### use terminus to create backup | |
/usr/local/bin/terminus backup:create ${PANTHEON_SITE_NAME}.live --element=database --yes | |
### remove old backup if exists | |
if [ -f "db/${BACKUP_FILE_NAME}" ]; then rm "db/${BACKUP_FILE_NAME}"; fi | |
### download backup from remote to local filesystem | |
/usr/local/bin/terminus backup:get ${PANTHEON_SITE_NAME}.live --element=database --yes --to=db/${BACKUP_FILE_NAME} | |
### clear the redis cache | |
/usr/bin/redis-cli -h $CACHE_HOST flushall | |
### restore w/progress bar the database with the credentials gleaned from .env | |
pv db/${BACKUP_FILE_NAME} | gunzip | mysql -u root --password=${MYSQL_ROOT_PASSWORD} -h $DB_HOST --port ${DB_PORT} ${DATABASE_NAME} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment