Drupal

##Drush is your friend

I had used Drush previously so I knew it can be a real time saver. For anyone reading this who is not familiar with Drush, it is a command line tool used to manage a Drupal installation and run all kinds of Drupal commands. Such as: run cron, clear caches, make backups, install modules etc. If you do Drupal development and are not using Drush, you really should. It saves you time and makes working with Drupal more enjoyable by not having to click around the Drupal admin interface that much. Drush is your friend.

In a multisite installation you have to tell Drush which site you want to run the command on (or if you don’t, by default the command will be run on the default site). Luckily there is also a @sites keyword that executes the command on all sites of a multisite installation. It will list all the sites and ask for a confirmation before executing, so you always know when you are running a command on multiple sites.

The Drupal update process

According to Drupal Core update instructions the update process involves more or less the following steps:

-Make a backup

-Put site in maintenance mode

-Update core files

-Run update script to update database

-Disable maintenance mode

Also, it is always best to do a trial run of the complete update process on a test server before updating production environment. There are some Drush commands that can be used to sync a Drupal database to a remote server that help you in managing a mirrored testing server, but those are out of the scope of this post.

I will now describe the Drush commands I used to accomplish the above steps and update my multisite Drupal. Please note that the commands listed here are for Drupal 7 and Drush 5, so the commands may vary for different versions. Most Drush commands also have a shorthand version but I will be using the full commands in this post to better illustrate what each command is doing. Feel free to explore the Drush help/documentation to learn about the shorthands and all options available for each command.

1. Make a backup

To completely backup a Drupal installation, you need to backup the files and the database. Drush has two different commands for backup purposes; archive-dump and sql-dump. The former backs up everything including files and database as the latter only dumps the database. Since the archive-dump command wraps everything in a single file, including Drupal core and all the files, I did not want to run it on all of the 62 sites (and thus getting 62 tarballs with the same Drupal core code base). So I decided to use the sql-dump command in Drush and create one tar file of the whole Drupal root manually.

Here is the command I used to backup all the databases:

drush @sites sql-dump --result-file --gzip

This command will dump all the different databases used by the sites into individual files. The –result-file switch tells Drush to save the dump into a file (using date based filename under ~/drush-backups directory when no filename is specified) and the –gzip switch obviously makes it gzip compressed.

Just for the sake of completeness, here is the command I used to create a tar archive of the Drupal installation:

tar -czvf drupal-backup.tar.gz drupal-root/

2. Put site in maintenance mode

The Drupal maintenance mode (or offline mode as it was called in previous Drupal versions) is saved as a Drupal variable in the database as are any other Drupal options that can be set using the admin interface. To change variable values using Drush we can use the variable-set command. You also need to clear caches for the maintenance mode to take effect, so we also need to use the Drush command cache-clear. Also make sure you are logged in to the sites (at least one that you can use to test) before putting the site into maintenance mode. As a logged in admin user you can see the site normally instead of only the maintenance mode notification so you can verify everything is working correctly after the update.

Here are the commands used to put all the sites into maintenance mode:

drush @sites variable-set maintenance_mode 1
drush @sites cache-clear all

3. Update core files (and modules)

To update Drupal core and also all installed contrib modules (/sites/all/modules), the pm-update command can be used. It downloads the latest version from drupal.org and installs the updated versions. A list of modules to update can also be passed on as argument to this command (and drupal can be used as the module name to update only Drupal core). Since I was feeling a little bit adventurous, I decided to update all contrib modules also at the same time.

Because we only have the core and module files in one place in the filesystem even though they are used by all of the sites, we only need to run this command on one site and not all. Thus we use the default keyword instead of @sites with this command.The pm-update command also runs the database update script, but since we have to run it for all of the sites, we could have also used the pm-updatecode command, which is similar to pm-update except it does not run the database update script.

Here is the command to install the updates:

drush default pm-update

or

drush pm-update

4. Run update script to update database

Now we have the updated versions of Drupal core and contrib modules. Drupal has a system for migrating database changes when updating. Normally when you update a module this is run automatically when you visit the modules page in the admin interface. But when using Drush to install the updates, we have to run it manually on all the sites since they all have separate database. This can be accomplished using the updatedb command as follows:

drush @sites updatedb

And now the update is done, time to test everything is working correctly. Now is the time to revert in case something went wrong. And I mean seriously, test EVERYTHING. It’s not that uncommon to run into issues, especially when using lots of contrib modules. I will outline some issues we ran into in the last chapter.

5. Disable maintenance mode

Ok, so everything seems to be working like a charm (or you have been busy debugging, googling, fixing, pulling out hair and cursing and finally got it working). Time to open the doors to the public again. This is almost identical to step 2, only set the variable value to 0 to disable the maintenance mode. And also remember to clear the cache.

Here are the commands used to disable maintenance mode on all the sites:

drush @sites variable-set maintenance_mode 0
drush @sites cache-clear all

All done!

Congratulations, if you have been following this guide to update a real Drupal installation and got this far, you should now have your Drupal multisite installation running a shiny new version of Drupal and also the latest and greatest of contrib modules.

Thanks

Add new comment

Other Articles

Drupal site maintenance not affecting front page

function HOOK_preprocess_page(&$vars) { global $user;

Easy Way to use tooltip with HTML tags

The easiest way to use tooltip on any tags of HTML 1. Span Tag

Changing the year range in the form's date element drupal form api

Drupal form api ap usually used to build the custom form to extended the functionality of drupal according to your need.

How to Manually Disable a WordPress Plugin

 Manually Disable a WordPress Plugin in Just 4 Steps :

How to Install Civicrm into Drupal 7

There is a direct guide available on CiviCRM Website, Here we follow faster steps to do the same.

Check the size of folder, files and directories using SSH

Following commands(In Bold) used for different purpose  1. Use df -h For check out the used space, free space and total space From all the partitions.

Getting permission error when installing CiviCRM under Drupal with Xampp

If you are getting permission error while installing CiviCRM on xampp then, its is default CiviCRM user permission error,

Uncaught TypeError: CKEDITOR.tools.object.keys is not a function

Intergation of code snippet with ckeditor, cause this error "Uncaught TypeError: CKEDITOR.tools.object.keys is not a function".

List of Most of File Type extension for drupal File field

List of Most of File Type extension for drupal File field : 

Install JAVA 8 on Ubuntu 18.04/16.04

Install java on Ubuntu 1)Install Oracle Java 8 

Print array or object in watchdog drupal 8

Similar to drupal 7, Drupal 8 also provide the logging functionality but little different to use it because the drupal 8 is symphony base architecture, so can use the logger service of drupal 8 to

Render a drupal node d8 twig template

Render a Drupal node in drupal 8 twig template and module PHP code is a bit different from Drupal 7 because Drupal 8 uses Symfony and twig format, follow the step and you will available to render a

Import Database using xampp mysql command prompt windows

As we all know the xampp is most popular tool at machine level programming work, but sometime we need to deal with the bigger databases to import into mysql of xampp that provide and we import that

Center the div vertically and horizontally using css

hey, below you can find the simple example of centering a div vertically and horizontally using css

Drupal 7 content type template

Open the template.php file in your theme for editing. Look for a function called yourthemename_preprocess_page (replace the yourthemename with your theme’s name).

How to render block in Drupal 8 theme template

Similar to Drupal 7, Drupal 8 also gives the customization using theme template, If you want to place a block using programmatically you have following options : 

Menu template in drupal 8 for specific customization

Drupal 8 gives the flexibility to make menu template and design the menu with our need, to do this --

Get average number with PHP

<?php //put all integer in array $array = array(9,18,9,5,6,45); //Calculate the average. $average = array_sum($array) / count($array);

Embed Google maps on website (Static address )

Here using this website  we can get the embed the static map on our website.

How you can get Mailchimp API KEY

By Follow steps below, you can find the api key or create the api key at mailchimp and use it to your website to connected the site with mailchimp to collect the subscribe in fastest way.

How To Install Webmin on Ubuntu 18.04

Webmin is open source control panel for linux machine, it is mainly use for server as file transfer, email configuration and other servers configuration using modern user interface.

List of all countries

Here is the GitHub Link that helps me to get the list of countries at once May it helps to you also 

Recent Posts

Create a Flag link programmatically and render flag link in twig template drupal 8

This article is refer to generate the flag link programmatically and render in drupal 8 twig template, before in drupal 7 its was quiet easy to render or generate flag link in just a single line of

Jquery prevent enter to submit form

If you want to prevent the form submit using jquery, then this page helps you to doing this.

Code:

Play Pause HTML5 Video using Jquery

HTML5 video playing on any web page is very easy, in this tutorial we can show you how to add video on html and make it play and pause without using html controls.

Import and Export Drupal 8 Views, Or Import and Export any configuration Drupal 8

Import and Export configuration is the basic protocol to staging the website or production website deployment, In Drupal 7, we need the extra modules to import and export or we can use features mod

How to override different version of Jquery in Drupal 8 using theme

Drupal 8 use its own jquery version by default and if you want to use the other version of jQuery instead of default than this tutorials steps is for you, sometimes we need different version to oth

Subscribe to Mailchimp programmatically via api with PHP

In this tutorial we can see how to subscribe to the mailchimp subscribe list using php programmatically via api,

For this you need a mailchimp account, api key and list id 

How you can get Mailchimp API KEY

By Follow steps below, you can find the api key or create the api key at mailchimp and use it to your website to connected the site with mailchimp to collect the subscribe in fastest way.

How to get your MailChimp LIST ID

Mailchimp is marketing automation platform and is provide email for marketing your product or business whatever you like, today its most trusted service providing all over the globe.

Drupal 8 add custom menu classes to using menu.html.twig

In Drupal 8 Twig templates give extra power to drupal to add dynamic content in twig style, In this tutorial we can see how we can add the custom menu classes to menu ul li using menu.html.twig.

How to create the directories and sub directories in one command linux

Many times we are want to create multiple directories and sub-directories under it and usually we do cd and mkdir one by one, it is very time consuming and it sometimes slow down our workflow.

Create Node drupal 8 programmatically with image upload using custom module

As we know drupal 8 use symphony, so module structure of drupal 8 is change and workflow functionality of doing thing also change.