#!/bin/bash IFS=$'\n' ROOT_PATH="/var/www/vhosts" # # get directories # if [ -f "./vhosts.du" ]; then du_output=$(cat "./vhosts.du") else echo echo -e "Reading disk usage for every directory in ${ROOT_PATH}. Please wait..." echo cd ${ROOT_PATH} du_output=$(du -sh */ | column --table -R1) fi # # convert directorires into menu items # index=0 menu_items=() for dir in $du_output; do menu_items+=("$index $dir" "") index=$(expr $index + 1) done # # show menu # dialog --no-lines --menu "Choose a directory from ${ROOT_PATH}:" 0 0 0 "${menu_items[@]}" 2> /tmp/menu_choice menu_choice=$(cat /tmp/menu_choice) rm -f /tmp/menu_choice echo # # Find the site root directory # SELECTED_DIR=$(echo ${menu_choice} | awk '{print $3}') [ "${SELECTED_DIR}" == "" ] && echo "No directory selected" && exit [ ! -d "${SELECTED_DIR}" ] && echo "Cannot find selected directory ${SELECTED_DIR}" && exit echo "SELECTED_DIR :" $SELECTED_DIR #VHOST_DIR=${ROOT_PATH}/${SELECTED_DIR} #[ ! -d "${SELECTED_DIR}" ] && echo "Cannot find selected vhost directory ${VHOST_DIR}" && exit #echo -e "VHOST_DIR :" $VHOST_DIR # # Find the index.php or index.html, the full path and the dir name # SITE_INDEX=$(find ${SELECTED_DIR} -name index.php -printf "%d %p\n"|sort -n|perl -pe 's/^\d+\s//;' | head -n1) if [ "${SITE_INDEX}" == "" ];then SITE_INDEX=$(find ${SELECTED_DIR} -name index.html -printf "%d %p\n"|sort -n|perl -pe 's/^\d+\s//;' | head -n1) fi echo -e "INDEX :" $SITE_INDEX INDEX_PATH=$(dirname $SITE_INDEX) echo -e "INDEX_PATH :" $INDEX_PATH INDEX_DIR=$(echo $INDEX_PATH | awk -F/ '{print $NF}') echo -e "INDEX_DIR :" $INDEX_DIR TARGET_DIR=${INDEX_PATH} # # Determine the type of the site # SITE_TYPE="unknown" [ -d "${INDEX_PATH}/core" ] && [ -d "${INDEX_PATH}/sites" ] && SITE_TYPE="drupal" [ -d "${INDEX_PATH}/admin" ] && [ -d "${INDEX_PATH}/mod" ] && SITE_TYPE="moodle" # # If its composer site get the parent directory of web/ # if [ ${INDEX_DIR} == "web" ]; then TARGET_DIR=$(dirname ${INDEX_PATH}) fi echo -e "TARGET_DIR :" $TARGET_DIR echo cd /root # # Confirm this is the right type of site # read -p "This is a ${SITE_TYPE} site. Continue to backup [y/n] ? " -n 1 -r if [[ $REPLY =~ ^[Yy]$ ]]; then echo # # Send path to back script # [ ${SITE_TYPE} == 'drupal' ] && bash ./backup-${SITE_TYPE}.sh ${TARGET_DIR} & [ ${SITE_TYPE} == 'moodle' ] && echo "Backup for type ${SITE_TYPE} not implemented yet!" && exit [ ${SITE_TYPE} == 'unknown' ] && echo "Backup for ${SITE_TYPE} types has not yet implemented!" && exit fi echo