#!/usr/bin/env bash # usage ./mulitsite-db-dump.bash path_to_sites_directory # path_to_sites_directory is the full path drupals sites directory (something like /var/www/drupal/web/sites) # This script will get the directories in the sites directory and cd into the directory and run drush sql-dump #switched to actual directories instead of symlinks as we have multiple symlinks for some production directories #excludes the all and the current directory (.). [ $# -ne 1 ] && { echo "Usage: $0 path_to_site_directory"; exit 1; } cd "$1" list="$(find ./ -maxdepth 1 -type d)" for link in $list ; do if [ "$(basename "$link")" != "all" ] && [ "$(basename "$link")" != "." ] ; then cd "$link" filename=$(basename "$link") if [ -f "./settings.php" ]; then echo "backing up database for site: $filename" ../../../vendor/bin/drush sql-dump --result-file=/var/www/backups/db-dump-"$filename"-$(date +%F).sql if [ $? -ne 0 ]; then echo "Error: Drush command failed for site: $site_name" fi fi cd "$1" fi done exit