#!/bin/bash # Dumps site mySQL databases. # Output files are suffixed with ".dump" and existing files are overwritten. # include library file . "`dirname ${0}`/drupalLibrary.sh" printUsage() { echo -e " " echo -e "Generates a dump backup file for the site's database." echo -e "Output files are named '.dump' and are placed, by default, in the current directory." echo -e " " echo -e "Usage:" echo -e "$0 [-quiet] [-outputdir ] [-tobackupdir] ( | all ) [install group root dir]" echo -e "where:" echo -e " " echo -e "-quiet" echo -e "\tLimits output" echo -e " " echo -e "-outputdir " echo -e "\tSpecifies the directory where output is placed." echo -e "\tCannot be specified with '-tobackupdir'." echo -e "-tobackupdir" echo -e "\tSpecifies that the output for each site will be placed in that site's 'backup' directory." echo -e "\tCannot be specified with '-outputdir'." echo -e " " outputInstallGroupUsage foo echo -e " " } ######### # Param handling if [ $# -eq 0 ]; then printUsage exit 0 fi # Handle flags while (true); do case "${1}" in -quiet ) pQuiet="${1}" shift ;; -outputdir ) # Can only specify one output directive if [ -n "${pOutputDir}" -o -n "${pToBackupDir}" ]; then echo -e "** Can only specify one of '-outputdir' and '-tobackupdir'. Aborting.\n" exit 1 fi pOutputDir="${1}" targetDir="${2}" shift; shift # Validate the output directory if [ ! -d "${targetDir}" ]; then echo -e "** Specified output directory '${targetDir}' does not exist. Aborting.\n" exit 1 fi ;; -tobackupdir ) # Can only specify one output directive if [ -n "${pOutputDir}" -o -n "${pToBackupDir}" ]; then echo -e "** Can only specify one of '-outputdir' and '-tobackupdir'. Aborting.\n" exit 1 fi pToBackupDir="${1}" shift ;; * ) break ;; esac done if [ -z "${pQuiet}" ]; then echo " " fi # Check parameters if [ $# -lt 1 -o $# -gt 2 ]; then echo -e "Invalid number of parameters specified. Aborting\n" printUsage exit 1 fi # process Group Root Dir pRootDir="`getGroupRootDir "${2}"`" errorStr="`validateGroupRootDir "${pRootDir}"`" if [ -n "${errorStr}" ]; then echo -e "${errorStr}\n" printUsage exit 1 fi pInstall="$1" if [ "`toLower "${pInstall}"`" == "all" ]; then pInstall="`getSitesInGroupDir "${pRootDir}"`" else # Validate the installation errorStr="`validateSite "${pInstall}" "${pRootDir}"`" if [ -n "${errorStr}" ]; then echo -e "** Error with specified install: ${errorStr}. Aborting." exit 1 fi fi # process site(s) for site in ${pInstall}; do if [ -z "${pQuiet}" ]; then if [ "${site}" != "${pInstall}" ]; then echo -en "Processing site '${site}'.... " fi fi # Determine target directory if not already set holdTargetDir="${targetDir}" if [ -z "${holdTargetDir}" ]; then holdTargetDir="." if [ -n "${pToBackupDir}" ]; then holdTargetDir="`getBackupDir "${site}" "${pRootDir}"`" fi fi # Get database auth information dbName="`getDBName "${site}" "${pRootDir}"`" dbAuth="`getDBAuthString "${site}" "${pRootDir}"`" # perform database backup/dump ${MYSQLDUMP} ${dbAuth} ${MYSQLDUMP_FLAGS} ${dbName} > "${holdTargetDir}/${site}.dump" if [ -z "${pQuiet}" ]; then if [ "${site}" != "${pInstall}" ]; then echo -e "Done." fi fi done # Done if [ -z "${pQuiet}" ]; then if [ "${site}" != "${pInstall}" ]; then echo " " fi echo -e "** Done." fi