-
-
Save pvmchau/3662538 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#config sites directory | |
SITES_ROOT="/usr/share/nginx/www" | |
#config database connect. Notice if multi database connect then default is a name of first connect. | |
DB_URL="mysql://root:root@localhost/drupal7;mysql://root:root@localhost/drupal7_2" | |
#setup remote for git | |
GIT_REMOTE_DB="https://github.com/tuongduy/backup_db.git" #link remote repository for database | |
GIT_REMOTE_FILES="https://github.com/tuongduy/backup_files.git" #link remote repository for files | |
#config for backup | |
SITE_NAME_BACKUP="drupal7" #name's site that you need backup | |
DB_BACKUP_DIR="/var/tam" #Directory to save backup database file | |
#config for restore | |
SITE_NAME_RESTORE="drupal7_re" | |
DRUSH_MAKE_FILE="https://raw.github.com/gist/b84fd6235b58779398c5/3324cbb4faa4d3c39a3af6b26ea7cf418c9ab00f/test.make" | |
CREATE_DB_USER_NAME="root" | |
CREATE_DB_USER_PASS="root" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Configuration: | |
PATH_CONFIG="$HOME/vietcoop" | |
FILE_ARG="$1" | |
# Check file config | |
if [ ! -f "$PATH_CONFIG/$FILE_ARG" ] | |
then | |
echo -e "Not found file config at '$PATH_CONFIG/$FILE_ARG'" | |
exit | |
fi | |
# Inlcude file config | |
source $PATH_CONFIG/$FILE_ARG | |
DRUPAL_ROOT="$SITES_ROOT/$SITE_NAME_RESTORE" | |
# Confirm from user | |
echo 'Do you really want to Restore you site? y/n?' | |
read CONFIRM | |
if [ "${CONFIRM}" == 'n*' ]; then | |
exit | |
fi | |
# Create site root | |
rm -rf $DRUPAL_ROOT | |
mkdir -p $DRUPAL_ROOT | |
cd $DRUPAL_ROOT | |
echo "Create site root at $DRUPAL_ROOT" | |
# Clone backup site db | |
echo 'Download Backup database from Repos' | |
git clone $GIT_REMOTE_DB Backupfile | |
# Make site from makefile | |
echo 'Download makefile for site' | |
wget $DRUSH_MAKE_FILE --directory-prefix="Backupfile" | |
echo 'Build site from makefile' | |
drush make Backupfile/*.make . | |
# Create settings.php file | |
echo "Create settings.php file at $DRUPAL_ROOT/ sites/default/" | |
cd sites/default/ | |
cp default.settings.php settings.php | |
#Restore db and add db_url to setting file | |
chmod 777 settings.php | |
DBURL='$db_url' | |
OIFS=$IFS; | |
IFS=";"; | |
DB_URLS=($DB_URL); | |
for ((i=0; i<${#DB_URLS[@]}; ++i)); | |
do | |
URL="${DB_URLS[$i]}" | |
DB_NAME="${URL##*/}" | |
echo "Restore database $DB_NAME" | |
mysql -u $CREATE_DB_USER_NAME -p$CREATE_DB_USER_PASS -e "CREATE DATABASE IF NOT EXISTS $DB_NAME;" | |
drush sql-cli --db-url="$URL" < "$DRUPAL_ROOT/Backupfile/db_$DB_NAME.sql" | |
if [ "$i" == 0 ]; then | |
echo "$DBURL['default'] = '$URL';" >> settings.php | |
else | |
echo "$DBURL['$DB_NAME'] = '$URL';" >> settings.php | |
fi | |
done | |
IFS=$OIFS; | |
chmod 644 settings.php | |
# Remove backup file | |
echo "Remove database backup files and makefile" | |
rm -rf $DRUPAL_ROOT/Backupfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment