Restoring Drupal from a backup using CPanel

Recently I had to move one of our Drupal site from one server to another. I was given the tar file containing the backup including the mysql script files. I strongly recommend you to go through expert blogs and sites for the complete information about this topic. I am writing my own experience

  1. The core Drupal installation is within the public_html folder. You can see this file folder within your backup files  directories.  In my case my public_html file was within a tar file named homedir.tar within my main backup file. public_html folder should contain folders like modules, profiles, INSTALL.txt etc. This is the base folder for your drupal installation. You have to copy this folder within public_html folder of your server. If your domain is the contents of public_html(modules, profiles etc) will be right within public_html/www folder. If you have a sub-blog then you have to copy the contents withing the subfolder. Following steps will assume that you are copying directly under public_html
  2. Using Cpanels, MySql Databases application, create a new database, create a new user and add this user with all the privileges to that database.
  3. Open public_html/sites/default/settings.php and set db_url value as per the database and user you have created in previous step
  4. Core data of your drupal website resides in mysql. Now you will have to import mysql database from the backup file to the newly created database. There are several ways of doing it. If you have ssh access you can go to the database and simply import the .sql file. I found phpadmin easy. For that, first you have to open your backup mysql script file(in my case it was a file under mysql folder in the backup. If there are more than one files then size of the files should give you fair idea which is the right file. Normally, file name should begin with the database name in your previous server) As a first statement in that sql file write this, lastly, don’t forget to use the sodapdf to convert your files.
    [sourcecode language="sql"]use mydb[/sourcecode]

    Where mydb is the name of the data. Usually when you select database in phpmyadmin before import then this step is not required. But it never hurts(less surprises this way)

  5. Open phpmyadmin, select your database from left lift, go to import tab and import this sql file
  6. Upto this step your website should be restored. If not, then probably you missed something. If you have not implemented clean url in your blog, then you don’t have to do anything else. Clean url converts the url in this format to
  7. If you have implemented clean url, on clicking any link you might be getting 404 error. To correct this you have to have .htaccess file properly configured. This is just an example
[sourcecode language="powershell"]

# Apache/PHP/Drupal settings:

# Protect files and directories from prying eyes.
<Files ~ "(.(inc|module|pl|sh|sql|theme|engine|xtmpl)|Entries|Repositories|Root|scripts|updates)$">
 Order deny,allow
 Deny from all

# Set some options.
Options -Indexes
Options +FollowSymLinks

# Customized error messages.
ErrorDocument 404 /index.php

# Set the default handler.
DirectoryIndex index.php

# Override PHP settings. More exist in sites/default/settings.php, but
# the following cannot be changed at runtime. The first IfModule is
# for Apache 1.3, the second for Apache 2.
<IfModule mod_php4.c>
 php_value magic_quotes_gpc                0
 php_value register_globals                0
 php_value session.auto_start              0

<IfModule sapi_apache2.c>
 php_value magic_quotes_gpc                0
 php_value register_globals                0
 php_value session.auto_start              0

# Reduce the time dynamically generated pages are cache-able.
<IfModule mod_expires.c>
 ExpiresByType text/html A1

# Various rewrite rules.
<IfModule mod_rewrite.c>
 RewriteEngine on

 # Modify the RewriteBase if you are using Drupal in a subdirectory and
 # the rewrite rules are not working properly.
 #RewriteBase /drupal

 # Rewrite old-style URLs of the form 'node.php?id=x'.
 #RewriteCond %{REQUEST_FILENAME} !-f
 #RewriteCond %{REQUEST_FILENAME} !-d
 #RewriteCond %{QUERY_STRING} ^id=([^&]+)$
 #RewriteRule node.php index.php?q=node/view/%1 [L]

 # Rewrite old-style URLs of the form 'module.php?mod=x'.
 #RewriteCond %{REQUEST_FILENAME} !-f
 #RewriteCond %{REQUEST_FILENAME} !-d
 #RewriteCond %{QUERY_STRING} ^mod=([^&]+)$
 #RewriteRule module.php index.php?q=%1 [L]

 # Rewrite current-style URLs of the form 'index.php?q=x'.
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

# $Id: .htaccess,v 1.66 2005/03/20 19:15:00 dries Exp $


This should complete your backup restoration. If you have any issues you can post comments here.

Leave a Reply

Your email address will not be published. Required fields are marked *