Skip to content

Instantly share code, notes, and snippets.

@drushman
Forked from pvmchau/restore_script.sh
Created September 7, 2012 01:26
Show Gist options
  • Save drushman/3662340 to your computer and use it in GitHub Desktop.
Save drushman/3662340 to your computer and use it in GitHub Desktop.
#!/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="$SITE_ROOT/$SITE_NAME_RESTORE"
#DRUPAL_DIR="$DRUPAL_ROOT/sites/default"
# Create site root
rm -rf $DRUPAL_ROOT
mkdir -p $DRUPAL_ROOT
cd $DRUPAL_ROOT
#echo "cd $DRUPAL_ROOT"
# Restore site db
git clone $GIT_REMOTE_DB Backupfile
#DBURL='$db_url=array('
DBURL="$DBURL);"
echo $DBURL
#exit
# Make site from makefile
wget $DRUSH_MAKE_FILE --directory-prefix="Backupfile"
drush make Backupfile/*.make .
# Create settings.php file
#mkdir $DRUPAL_DIR
cd sites/default/
cp default.settings.php settings.php
chmod 777 settings.php -R
OIFS=$IFS;
IFS=";";
DB_URLS=($DB_URL);
for ((i=0; i<${#DB_URLS[@]}; ++i));
do
URL="${DB_URLS[$i]}"
DB_NAME="${URL##*/}"
drush sql-cli --db-url="$URL" < "$DRUPAL_ROOT/Backupfile/db_$DB_NAME.sql"
DBURL='$db_url'
if [ "$i" == 0 ]; then
echo "$DBURL['default'] = '$URL';" >> settings.php
else
echo "$DBURL['$DB_NAME'] = '$URL';" >> settings.php
fi
#DBURL="$DBURL'$URL',"
done
IFS=$OIFS;
chmod 644 settings.php
# Remove backup file
rm -rf $DRUPAL_ROOT/Backupfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment