Skip to main content

Create Replication of drupal using script in linux

First of all Copy the settings.php & civicrm settings.php files & paste it as settings.php.dist & civicrm.settings.php.dist.

Edit the settings.php.dist :-
$db_url=' ';
$db_prefix = ' ';

Edit Civicrm settings.php :-
Replace the code from the file with the following code .
1)  define( 'CIVICRM_UF_DSN'           , ' ' );
2)  define( 'CIVICRM_DSN'          , ' ' );
3)  $civicrm_root = '';
4)  define( 'CIVICRM_TEMPLATE_COMPILEDIR', '' );
5)  define( 'CIVICRM_UF_BASEURL'      , '' );

After that create one script file as filename.sh ( for ex.  drupal-rep.sh)  &  copy the following code into the file.

/************************ Script file code **********************************/

echo "Have you copy files 'civicrm.settings.php.dist' and 'settings.php.dist'
      in sites/default of the source drupal ( 'y' or 'n' ) ? "
read copyFile

if [ -z $copyFile ]
then
echo "Please copy the files mention above "
exit 1
elif [ $copyFile = n ]
    then
    echo "Please copy the files mention above "
    exit 1
fi

echo -n "Enter Drupal Source Path "
read mainSource

if [ -z $mainSource ]
then
    exit 1
fi
MAIN_SOURCEPATH=$mainSource
SOURCEPATH=$MAIN_SOURCEPATH"/*"

echo -n "Enter Drupal Detination Path "
read destination

if [ -z $destination ]
then
    exit 1
fi
DESTINATION=$destination
LOGFILE=$DESTINATION/copy-log.log
DATESTAMP=`date`

echo -n "Enter Source Drupal Database Name "
read sourceDbName

if [ -z $sourceDbName ]
then
    exit 1
fi
SOURCE_DB_NAME=$sourceDbName

echo -n "Enter Source Drupal Database User Name "
read sourceDbUserName

if [ -z $sourceDbUserName ]
then
    exit 1
fi
SOURCE_DB_USER=$sourceDbUserName

echo -n "Enter Source Drupal Database Password "
read sourceDbPassword

if [ -z $sourceDbPassword ]
then
    exit 1
fi
SOURCE_DB_PASS=$sourceDbPassword

echo -n "Enter Destination Drupal Database Name "
read destinationDbName

if [ -z $destinationDbName ]
then
    exit 1
fi
DESTINATION_DB_NAME=$destinationDbName

echo -n "Enter Destination Drupal Database User Name "
read destinationDbUserName

if [ -z $destinationDbUserName ]
then
    exit 1
fi
DESTINATION_DB_USER=$destinationDbUserName

echo -n "Enter Destination Drupal Database Password "
read destinationDbPassword

if [ -z $destinationDbPassword ]
then
    exit 1
fi
DESTINATION_DB_PASS=$destinationDbPassword

echo -n "Enter Destination Database Server Name "
read destinationDbServerName

if [ -z $destinationDbServerName ]
then
    exit 1
fi
DESTINATION_DB_SERVER=$destinationDbServerName

echo -n "Enter Destination Drupal Url "
read destinationUrl

if [ -z $destinationUrl ]
then
    exit 1
fi
DESTINATION_URL=$destinationUrl

echo -n "Enter Source Civicrm Database Name "
read sourceCiviDbName

if [ -z $sourceCiviDbName ]
then
    exit 1
fi
SOURCE_CIVICRM_DB_NAME=$sourceCiviDbName

echo -n "Enter Source Civicrm Database User Name "
read sourceCiviDbUser

if [ -z $sourceCiviDbUser ]
then
    exit 1
fi
SOURCE_CIVICRM_DB_USER=$sourceCiviDbUser

echo -n "Enter Source Civicrm Database Password "
read sourceCiviDbPassword

if [ -z $sourceCiviDbPassword ]
then
    exit 1
fi
SOURCE_CIVICRM_DB_PASS=$sourceCiviDbPassword

echo -n "Enter Destination Civicrm Database Name "
read destinationCiviDbName

if [ -z $destinationCiviDbName ]
then
    exit 1
fi
DESTINATION_CIVICRM_DB_NAME=$destinationCiviDbName

echo -n "Enter Destination Civicrm Database User Name "
read destinationCiviDbUserName

if [ -z $destinationCiviDbUserName ]
then
    exit 1
fi
DESTINATION_CIVICRM_DB_USER=$destinationCiviDbUserName

echo -n "Enter Destination Civicrm Database Password "
read destinationCiviDbPass

if [ -z $destinationCiviDbPass ]
then
    exit 1
fi
DESTINATION_CIVICRM_DB_PASS=$destinationCiviDbPass

cd $MAIN_SOURCEPATH"/sites/default/files"
sudo chmod -R 777 civicrm
sudo chmod -R 777 civicrm/templates_c

#copy cose base
mkdir $DESTINATION
echo $DATESTAMP."copying code base...">>$LOGFILE
cp -R $SOURCEPATH $DESTINATION>>$LOGFILE
cp -R $MAIN_SOURCEPATH/.htaccess $DESTINATION>>$LOGFILE

#database dump
echo $DATESTAMP."copying database...">>$LOGFILE
mysqldump -u$SOURCE_DB_USER -p$SOURCE_DB_PASS $SOURCE_DB_NAME > $DESTINATION/$SOURCE_DB_NAME.sql

#create new database
echo "Creating a database for $DESTINATION_DB_NAME">>$LOGFILE
DBS=`mysql -u$DESTINATION_DB_USER -p$DESTINATION_DB_PASS -Bse 'show databases'| egrep -v 'information_schema|mysql'`
flag=0
for db in $DBS; do
if [ "$db" = "$DESTINATION_DB_NAME" ]
then
    flag=1
    echo "This database already exists : exiting now">>$LOGFILE
    break
fi
done
if [ $flag = 0 ]
then
    mysqladmin -u$DESTINATION_DB_USER -p$DESTINATION_DB_PASS create $DESTINATION_DB_NAME;
    mysql -u$DESTINATION_DB_USER -p$DESTINATION_DB_PASS $DESTINATION_DB_NAME < $DESTINATION/$SOURCE_DB_NAME.sql
fi

#civicrm database dump
echo $DATESTAMP."copying civicrm  database...">>$LOGFILE
mysqldump -u$SOURCE_CIVICRM_DB_USER -p$SOURCE_CIVICRM_DB_PASS $SOURCE_CIVICRM_DB_NAME > $DESTINATION/$SOURCE_CIVICRM_DB_NAME.sql


#create new database for CIVICRM
echo $DATESTAMP."Creating a database for $DESTINATION_CIVICRM_DB_NAME">>$LOGFILE
DBS=`mysql -u$DESTINATION_CIVICRM_DB_USER -p$DESTINATION_CIVICRM_DB_PASS -Bse 'show databases'| egrep -v 'information_schema|mysql'`
flag=0
for db in $DBS; do
if [ "$db" = "$DESTINATION_CIVICRM_DB_NAME" ]
then
    flag=1
    echo $DATESTAMP."This database already exists : exiting now">>$LOGFILE
    break
fi
done
if [ $flag = 0 ]
then
    mysqladmin -u$DESTINATION_CIVICRM_DB_USER -p$DESTINATION_CIVICRM_DB_PASS create $DESTINATION_CIVICRM_DB_NAME;
    mysql -u$DESTINATION_CIVICRM_DB_USER -p$DESTINATION_CIVICRM_DB_PASS $DESTINATION_CIVICRM_DB_NAME < $DESTINATION/$SOURCE_CIVICRM_DB_NAME.sql
fi
mysql -u$DESTINATION_CIVICRM_DB_USER -p$DESTINATION_CIVICRM_DB_PASS -e "truncate table "$DESTINATION_CIVICRM_DB_NAME".civicrm_group_contact_cache"
mysql -u$DESTINATION_CIVICRM_DB_USER -p$DESTINATION_CIVICRM_DB_PASS -e "truncate table "$DESTINATION_CIVICRM_DB_NAME".civicrm_cache"
mysql -u$DESTINATION_CIVICRM_DB_USER -p$DESTINATION_CIVICRM_DB_PASS -e "truncate table "$DESTINATION_CIVICRM_DB_NAME".civicrm_acl_contact_cache"
mysql -u$DESTINATION_CIVICRM_DB_USER -p$DESTINATION_CIVICRM_DB_PASS -e "truncate table "$DESTINATION_CIVICRM_DB_NAME".civicrm_acl_cache"
mysql -u$DESTINATION_CIVICRM_DB_USER -p$DESTINATION_CIVICRM_DB_PASS -e "update "$DESTINATION_CIVICRM_DB_NAME".civicrm_domain SET config_backend = NULL WHERE civicrm_domain.id =1"
mysql -u$DESTINATION_CIVICRM_DB_USER -p$DESTINATION_CIVICRM_DB_PASS -e "UPDATE "$DESTINATION_CIVICRM_DB_NAME".civicrm_preferences SET navigation = NULL"
cd $DESTINATION"/sites/default/"
rm -f settings.php
rm -rf /files/civicrm/templates_c/*
sed "s|$db_url='';|$db_url='mysqli://"$DESTINATION_DB_USER":"$DESTINATION_DB_PASS"@"$DESTINATION_DB_SERVER"/"$DESTINATION_DB_NAME"';|" files/settings.php
cp -f files/settings.php settings.php
sed "s|define( 'CIVICRM_UF_DSN'           , '' );|define( 'CIVICRM_UF_DSN'           , 'mysql://$DESTINATION_CIVICRM_DB_USER:$DESTINATION_CIVICRM_DB_PASS@$DESTINATION_DB_SERVER/$DESTINATION_CIVICRM_DB_NAME?new_link=true' );|" files/civicrm.settings.php
sed "s|define( 'CIVICRM_DSN'          , '' );|define( 'CIVICRM_DSN'           , 'mysql://$DESTINATION_CIVICRM_DB_USER:$DESTINATION_CIVICRM_DB_PASS@$DESTINATION_DB_SERVER/$DESTINATION_CIVICRM_DB_NAME?new_link=true' );|" civicrm.settings.php
sed "s|$civicrm_root = '';|$civicrm_root = '"$DESTINATION"/sites/all/modules/civicrm';|" files/civicrm.settings.php
sed "s|define( 'CIVICRM_TEMPLATE_COMPILEDIR', '' );|define( 'CIVICRM_TEMPLATE_COMPILEDIR', '"$DESTINATION"/sites/default/files/civicrm/templates_c' );|" civicrm.settings.php
sed "s|define( 'CIVICRM_UF_BASEURL'      , '' );|define( 'CIVICRM_UF_BASEURL'      , '"$DESTINATION_URL"' );|" files/civicrm.settings.php
cp -f files/civicrm.settings.php civicrm.settings.php
sudo chmod -R 777 files
sudo chmod -R 755 civicrm.settings.php
rm -f files/civicrm.settings.php
rm -f files/settings.php
rm -f civicrm.settings.php.dist
rm -f settings.php.dist
/*************************************************************/

Copy the settings.php & civicrm settings.php files in the drupal/site/default/ folder of the drupal whose replication to be create.

Run the script file on the terminal as sh filename.sh (for ex. sh drupal-rep.sh )
You will get the replication of the drupal.
If Civicrm Not work in the new drupal then rebuild menus or disable the clean url .

If u have any query please inform me to ravimane23@gmail.com.

To know more about replication of drupal Click Here

Comments

Popular posts from this blog

Create Hooks in Civicrm in Joomla 1.5

  Create Hooks in Civicrm in Joomla 1.5 Create folder in any directory like /Joomla/media/civicrm_hook . Create file civicrmHooks.php in this directory. Go to Administer CiviCRM > Global Settings > Directories Set the path for custom php here. Use the civicrm hooks with Joomla_civicrm_hookName format. Ex. function Joomla_civicrm_buildForm( ){ // Write your code here. }

New Services to the world

Different government services & Online Services GST Registration Company Registration ITR PAN Card Aadhar Card E-way Bill Registration Food License Accounting Service Website designing Website development Website Hosting Website Domain Website Testing (Manual) Website SCO Optimization Lead Generation Add Creation and many more...