Skip to content

Instantly share code, notes, and snippets.

@mikedamoiseau
Created August 28, 2020 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikedamoiseau/8045b24aa26a6e7379380471a8e9d367 to your computer and use it in GitHub Desktop.
Save mikedamoiseau/8045b24aa26a6e7379380471a8e9d367 to your computer and use it in GitHub Desktop.
Drupal - Backup DB using Drush
#!/bin/bash
# staging or production
DB_ENV="staging"
##### DO NOT EDIT FROM HERE #####
# Find the container
CONTAINER="$(docker ps | grep c-${DB_ENV} | awk '{print $1}')"
# Timestamp (used to build dump filename)
DATE=$(date +"%Y%m%d%H%M%S")
# Dump filename
DUMP_FILENAME="sigel_${DB_ENV}_${DATE}.sql"
# Export the DB
docker exec -w /var/www/html ${CONTAINER} drush sql-dump --gzip --structure-tables-key=common --result-file=/tmp/${DUMP_FILENAME}
# Move the dump to the backups folder
mv /tmp/${DUMP_FILENAME}.gz ~/backups/${DB_ENV}/${DUMP_FILENAME}.gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment