#!/usr/bin/env bash # # This script should receive certain values: # DEPLOY_ROOT: The base root for deployments. # DEPLOY_DIR: The directory for this current deployment. # # The current deployment is symlinked to from ${DEPLOY_ROOT}/current # The previous deployment is symlinked to from ${DEPLOY_ROOT}/previous # set -e WEBROOT=${DEPLOY_ROOT}/current/web PATH=${PATH}:${HOME}/bin # Sites we'll target for auto-migration. cd "${WEBROOT}" MIGRATE_SITES=$(drush sa | grep '^@' | grep -Ev "^(@none|@self)$") # Make DB backups from existing deploy location. cd "${WEBROOT}" for SITE in $MIGRATE_SITES; do echo "DB backup for ${SITE}" BACKUP=/container/application/backups/${SITE}.pre-release.$( basename "$DEPLOY_DIR" ).sql drush "${SITE}" sql-dump --result-file="${BACKUP}" --gzip --extra="--no-tablespaces --column-statistics=0" done cd "${DEPLOY_ROOT}" mv current previous mv next current # Execute DB updates & snapshot. cd "${WEBROOT}" for ALIAS in $MIGRATE_SITES; do echo "DB update for ${ALIAS}" SITE="${ALIAS//@/}" drush -y "${ALIAS}" updb BACKUP=/container/application/backups/${SITE}.post-update.$( basename "$DEPLOY_DIR" ).sql echo "DB dump for ${ALIAS}" drush "${ALIAS}" sql-dump --result-file="${BACKUP}" --gzip --extra="--no-tablespaces --column-statistics=0" done