CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Upgrading CiviCRM (Moderator: Deepak Srivastava) »
  • how i upgraded from 3.4.6 to 4.1 and upgraded drupal with bash and drush
Pages: [1]

Author Topic: how i upgraded from 3.4.6 to 4.1 and upgraded drupal with bash and drush  (Read 761 times)

Erich Schulz

  • I post frequently
  • ***
  • Posts: 142
  • Karma: 5
    • When no-one understands what you are going on about its time to start a blog
  • CiviCRM version: 4.4
  • CMS version: Drupal 7
  • MySQL version: 5.somthing
  • PHP version: 5.3.3
how i upgraded from 3.4.6 to 4.1 and upgraded drupal with bash and drush
December 01, 2012, 06:02:39 pm
hi all,

I seem to finally ticked this off for slightly impatient spouse this morning.

I found this pretty torturous to be honest, so posting my script in case it helps others - this is most definitely not a push button solution but contains some handy sed snippets and other goodies

and for heavens sake take a back up - this kind of stuff can fry your entire site in the blink of an eye!

the approach i took was to set up several sandbox domains  copya, copyb, copyc, copyd - this meant I could play and let the tester (aka dearly beloved) evaluate both at the same time, and could also play with the drupal 7 upgrading...

this had the benefit of leaving the main site intact, and meant I could keep tinkering for a few weeks till i got it right, once it was right I could just push go.

i wanted a push button script so I could do it repeatedly from beginning to end reproducibly.

this domain is on a cheap host running bsd and i didn't have root access and some problems with civicrm making files i couldn't delete as a shell user! but once i figured out a workaround I was ok - i blame my host company not civicrm

Prequisites:

  • drush installed and aliases configure - you really do want to do this if you havent already
  • mysql configured with .my.cnf file so you can pipe sql into mysql, and use mysqldump
  • empty database(s) created

good luck!!

Code: [Select]
#!/usr/bin/env /usr/local/bin/bash

echo " ========================= initialising"
cd ~
export base=yourdomain.org.au
export box=copy$1
export domain=$box.$base
export t=`pwd`/$domain
export prod=`pwd`/$base
export m=$t/sites/all/modules
export c=$m/civicrm
export db=sandbdb$box
echo "path to civicrm $c"

function main () {
  PATH=$PATH:/hsphere/local/home/yourdomain/bin
  drush status
  if [[ $? -ne 0 ]]; then
    echo "no drush!"
    exit 1
  fi
  copyprodtocopy
  copycopytoprod
}

function copycopytoprod() {
  read -p "Do you want to proceed?
    1. source: $t
    2. target: $prod
    [y/N] ? " -n 1 -r
  echo
  if [[ $REPLY =~ ^[Yy]$ ]]
  then
    echo "moving $prod  to hakbak.`date +"%Y%m%d-%H%M"`"
    mv $prod  hakbak.`date +"%Y%m%d-%H%M"`
    echo "moving $t to $prod"
    mv $t $prod
    echo 'cleaning out template directory: '
    rmminusrf $prod/sites/default/files/civicrm/templates_c
    echo '- done';
    echo 'updating settings files:'
    sed -i '' "s/\/$domain/\/$base/g" $prod/sites/default/civicrm.settings.php
    sed -i '' "s/www.$domain/$base/g" $prod/sites/default/civicrm.settings.php
    echo 'job done please test and put back online';
  fi
}

function settleintod7() {
  drush dl admin_menu
  drush -y en admin_menu
}


function copyprodtocopy() {
  read -p "Do you want to:
    1. Delete all files in $t,
    2. Empty $db, and
    3. Briefly take production site off-line to copy it to $box? " -n 1 -r
  echo
  if [[ $REPLY =~ ^[Yy]$ ]]
  then
    empty_database $db
    rmminusrf $t
    copy_files_and_db_from_production
  fi

  #drush sa
  drush use @$box
  # show drush status with:
  # drush st
  echo taking $box offline
  drush --yes --exact vset site_offline 1
  updatesettings
  updatecore
  fixowner
  fixperms
  drush --yes updb
  drush --yes cron
  echo "Please log in a verify site is fuctional
    Go to http://$domain/user
    then: http://$domain/admin/reports/status

    then press enter
    "
  read

  updatecivcrm
  setcivicrmtod6
  fixowner
  fixperms
  # todo : run from this script?
  # drush civicrm-upgrade-db
  echo "Now you need to run the upgrade script

   at http://$domain/civicrm/upgrade?reset=1

    You should see the message 'Upgrade successful' when the upgrade completes.
    When you have done all this you can press enter here"
  read
  drush cache-clear all
  # drush --yes crm clear
  echo put site online
  drush --yes --exact vset site_offline 0
}



function copy_files_and_db_from_production() {
  # refresh files
    cp -r yourdomain.org.au $t
    # tidy up some relics:
    rm -rf $t/sites/all/modules/*gz
    echo 'cleaning out template directory: '
    rmminusrf $t/sites/default/files/civicrm/templates_c
    echo '- done';
  # refresh db
    empty_database $db
    echo "copying databases - main site offline:"
    #drush @prod --yes --exact vset site_offline 1
    drush @prod --yes --exact vset maintenance_mode 1
    mysqldump db_civicrm | mysql $db
    mysqldump db_drupal| mysql $db
    #drush @prod --yes --exact vset site_offline 0
    drush @prod --yes --exact vset maintenance_mode 0
    echo "main site back oline:"
}

function db_name() {
  echo "db_copy$1"
}

function copy_database() {
  SOURCE=`db_name $1`
  TARGET=`db_name $2`
  echo "do your really want to copy $SOURCE to $TARGET"
  read -p "y to confirm" -n 1 -r
  if [[ $REPLY =~ ^[Yy]$ ]]
  then
    echo "emptyint $TARGET"
    empty_database $TARGET
    echo "copying $SOURCE to $TARGET"
    mysqldump $SOURCE | mysql $TARGET
  fi
}

# param $1 = database name eg 'copya'
function empty_database() {
  db=$1
  echo "removing all tables from $db"
  echo "SET FOREIGN_KEY_CHECKS = 0;" > temp.sql
  echo "SELECT concat('DROP TABLE IF EXISTS ', table_schema, '.', table_name, ' cascade;') AS \`#sql\`
  FROM information_schema.tables
  WHERE table_schema = '$db'; " | mysql >> temp.sql
  echo "SET FOREIGN_KEY_CHECKS = 1;" >> temp.sql
  cat temp.sql | mysql
  rm temp.sql
  echo "done"
}

function updatesettings() {
  # upddate settings to point to new domain and db:
  sed -i '' "s/YOURDRUPALDBNAME/sandbdb$box/g" $t/sites/default/settings.php
  sed -i '' "s/YOURCIVICRMDBNAME/sandbdb$box/g" $t/sites/default/civicrm.settings.php
  sed -i '' "s/\/$base/\/$domain/g" $t/sites/default/civicrm.settings.php
  sed -i '' "s/www.$base/$domain/g" $t/sites/default/civicrm.settings.php
  find $t/sites/default -type d -exec chmod a+rwx \{\} \+
  # echo "UPDATE civicrm_domain SET config_backend=NULL" | mysql $db
}


function fixperms() {
  find $t -type d -exec chmod a+rwx {} \;
  chmod 2755 $t/sites/default
  drush cc all
  tf=index1.php
  echo "<?php
    
echo 'removing templates file';
    echo 
system('rm -rf $t/sites/default/files/civicrm/templates_c');
    
"> $t/$tf
  echo "
running $t/$tf:"
  cat 
$t/$tf
  echo "
===========:"
  curl 
$domain/$tf
  echo "
  
===========:"
  rm 
$t/$tf
  rm -rf 
$t/sites/default/files/civicrm/templates_c
  chmod 777 
$t/sites/default/files/civicrm/templates_c/en_US/
  chmod 777 
$t/sites/default/files/civicrm/templates_c
  chmod 444 
$t/sites/default/settings.php
}

function fixowner() {
  tf=index1.php
  echo "
<?php echo 'changing owner';
    echo 
system('chgrp -R yourdomain $t');
    echo 
' - done';" > $t/$tf
  echo "
running $t/$tf:"
  cat 
$t/$tf
  echo "
===========:"
  curl 
$domain/$tf
  echo "
  
===========:"
  rm 
$t/$tf
}


function updatecore() {
  #udpdate core
  drush upc --yes
  # update ckeditor
  drush ckeditor-download --yes
}

# needs testing but should be close
function updatecivcrm() {
  v=4.1.6
  civicrmfile=civicrm-
$v-drupal6.tar.gz
  civicrmbase=http://downloads.sourceforge.net/projects/civicrm/files/civicrm-stable
  rm -rf 
$m/civicrm
  if [ ! -f 
$civicrmfile ]; then
   wget -P ~ 
$civicrmbase/$v/$civicrmfile
  fi
  tar -xf 
$civicrmfile -C $m
  echo "
note you should 'rm ~/$civicrmfile'"
  echo 7. run upgrade script
  echo Go to http://
$domain/civicrm/upgrade?reset=1
  # todo hard: run from this script?
  echo You should see the message Upgrade successful when the upgrade completes.
  echo
}

function setcivicrmtod6() {
  # swap CIVICRM_UF Drupal to Drupal6
  # to make 
$s = \s*
  s='[  ]*'
  r="
s/^\(${s}define($s'CIVICRM_UF'$s,$s'\)Drupal\('$s);$s\)/\1Drupal6\2/g"
  sed -i '' "
$r" $t/sites/default/civicrm.settings.php
}

# hack to do a 'rm -rf $1'
# only required because of bizzare hosting permissions
function rmminusrf() {
  target=$1
  file=
$domain/index_temp.php
  # delete all files in target
  echo "
<?php
    
echo 'deleting all files from $target';
    
system('rm -rf $target');
    echo 
'- done';
     
" > $file
  curl 
$file
  rm -rf 
$target
  rm 
$file
  #mv 
$target tmp/`date +"%Y%m%d-%H%M"`/
}

main



Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Upgrading CiviCRM (Moderator: Deepak Srivastava) »
  • how i upgraded from 3.4.6 to 4.1 and upgraded drupal with bash and drush

This forum was archived on 2017-11-26.