Skip to content

Instantly share code, notes, and snippets.

@hugovk
Last active August 29, 2015 14:13
Show Gist options
  • Save hugovk/dff8650d4202ce6fb112 to your computer and use it in GitHub Desktop.
Save hugovk/dff8650d4202ce6fb112 to your computer and use it in GitHub Desktop.
pandb.sh downloads and extracts a database from Pantheon in a local environment. updb.sh extracts the last downloaded DB.
#!/bin/bash
echo $1
DATABASENAME="TODO_ENTER_YOUR_DATABASE_NAME"
# From the Pantheon dashboard Backups tab, copy the temporary link for the
# database. Call this script with that link (in quotes) as a parameter.
if [ -z "$1" ];
then
echo 'Usage: pandb.sh "PANTHEON_DATABASE_DOWNLOAD_LINK"';
exit 0
fi
# Check parameter looks a bit like a Pantheon database download URL
if [[ "$1" != https*pantheon-backups*database.sql.gz* ]]
then
echo 'Usage: pandb.sh "PANTHEON_DATABASE_DOWNLOAD_LINK"';
echo "Check parameter is Pantheon database download link:" $1;
exit 0
fi
# Remove old DB file
rm database.sql.gz
# Download new DB file, update DB, clear cache
echo "Download database..." && \
curl -o database.sql.gz $1
#!/bin/bash
# Check if zip is still valid
if [[ $(file --mime-type database.sql.gz) == "database.sql.gz: application/xml" ]];
then
if grep --quiet "Request has expired" database.sql.gz;
then
echo "Database link has expired, get a new one from the Pantheon dashboard"
exit 0
fi
echo "Problem with database link, get a new one from the Pantheon dashboard"
exit 0
fi
echo "Update database..." && \
gunzip < database.sql.gz | mysql -uTODO_ENTER_YOUR_DATABASE_USERNAME -pTODO_ENTER_YOUR_DATABASE_PASSWORD $DATABASENAME && \
echo "Clear cache..." && \
drush cc all && \
echo "Done."
#!/bin/bash
DATABASENAME="TODO_ENTER_YOUR_DATABASE_NAME"
echo "Update database..." && \
gunzip < database.sql.gz | mysql -uTODO_ENTER_YOUR_DATABASE_USERNAME -pTODO_ENTER_YOUR_DATABASE_PASSWORD $DATABASENAME && \
echo "Clear cache..." && \
drush cc all && \
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment