HowTo: Duplicate a Drupal 7 Website for Testing and Development


In this HowTo I will describe how I quickly duplicate Nutshell.nu so that I do further testing or development without affecting the live website.

This HowTo is based on Drupal 7 alpha 5. I don't see any reason for it not to work with both Drupal 6 and newer versions of Drupal 7 as well.

Requirements

You will need to install and configure the Backup and Migrate module on the website you want to duplicate. That is the only requirement needed there.

You will also need to either have a local server or create a separate webserver on your hosting account.

Once that is done you can begin the duplication process.

Backup Live Website Database

This is the easy part. Simply do the following the first time you back up the database:

  1. Go to Structure / Backup and Migrate.
  2. Click the Advance Backup tab.
    1. Select GZip in Compression.
    2. Check the Database Options. No table should be selected in the Exclude list, but a bunch of tables should be in the Exclude the data list. This is just fine as you don't need any cached data.
    3. Check the "Lock tables during backup". Note: First make sure that your database user can do that!
    4. Open the Advanced Options and check the "Take site offline" option. Your website will automatically be put online as soon as Backup and Migrate is done.
    5. Make sure Download is selected in Backup Destination.
    6. Check the "Save these settings" option.
    7. Select if you want to overwrite the default or create a new profile.
    8. Change the Profile name if needed.
  3. Click Backup now
  4. Save the backup on your local computer when prompted.

Depending on how much data there is it will take a few seconds or longer before you are see the download requester.

That was the easy part. Now I will show you how to get the duplicate website running.

 

Getting the Duplicate Website Up

I am using WampServer 2 as my local installation, but its not very different for other server environments. If you are going to use WampServer, I recommend that you download v2.0h since v2.0i has PHP5.3 and that will give you loads of warnings when using it with Drupal, especially for Drupal 6.

Important! It is very important that you make sure you use the exact same versions of Drupal and contributed modules. If you don't it is very likely that you will run into problems. This is especially true if there are database differences between the versions on the live website and the copy you are creating. You can always update Drupal and modules after.

Follow these steps to get the testing or development site up:

  1. Create a new database to use for the new installation.
  2. Copy the same Drupal 7 version into the folder where it will run from.
  3. Preparing Drupal 7:
    1. Copy and rename default.settings.php to settings.php in the sites/default folder.
    2. Point you browser the website.
    3. Follow the installation instruction on the screen. Use the Minimal profile, there is no need to use the standard since it is going to be overwritten by the backup.
  4. Copy all the modules, themes, libraries etc. from the sites/all folder on the live website to the same folder in the new.
  5. Copy the entire sites/default/files folder from the live website to the new.
  6. Go to Modules and enable Backup and Migrate.
  7. Go to Structure / Backup and Migrate.
  8. Click the Restore tab.
  9. Upload the database backup file and click Restore now
  10. Go to Performance and click Clear all caches.
  11. Done

Now you have an as near 100% copy of the live site as possible to play with.

My Theme Looks Screwed Up?

I am using a slightly customised version of Jen Simmons Bartik theme on Nutshell. Due to the way it works I have to go to the theme settings and re-save its settings. If I don't the logo for example wont show up. That is the only thing I have noticed that is needed after restoring the backup.

Once I have saved the settings, without any changes, everything looks cool again.

Recommended Changes to the Test / Development website

There are a few tings you probably want to change on your test/development installation to make working on it easier.

Here is a list of things I am doing before I start  working with it:

  • Turn off all performance caching.
  • Change the key for Google Analytics, and other modules, to my dev keys.
  • Turn of a few blocks that isn't needed on it.

Neither of them are really needed to do, but you will avoid things such as your dev server ending up in your statistics as well as not having to clear the caches all the time if you do.

Hope this will useful for you. Please leave a comment if you have any questions or find any errors in it.

Comments

Re: HowTo: Duplicate a Drupal 7 Website for Testing and ...

Nice howto.

I like to do the last step you mention (changing settings on your dev environment) with the conf array in settings.php. That way the settings won't be overwritten every time you pull a new database dump from live. Just add this to the bottom of settings.php on your local dev:

$conf['error_level'] = 1;
$conf['preprocess_css'] = 1;
$conf['preprocess_js'] = 1;
$conf['cache'] = 0;
$conf['block_cache'] = 0;
$conf['googleanalytics_account'] = '';

Re: HowTo: Duplicate a Drupal 7 Website for Testing and ...

Hi Ronan,

Glad you like it.

Brilliant tip about adding those to settings.php. I will incorporate in the more detailed HowTo I plan to write shortly.

/thomas

Re: HowTo: Duplicate a Drupal 7 Website for Testing and ...

If only I knew how to program this...

If possible, a statement like "If this website is hosted at 127.0.0.1 then:" could be placed just before the array of settings, the settings.php could be identical on live and local...

Would you know how to do this?

Re: HowTo: Duplicate a Drupal 7 Website for Testing and ...

I want to copy a development drupal 7 database in Ubuntu 10.10 to Fedora 14 on another hard driveon the same pc.
The backup and migrate seems to require FTP, there are no other options available.
Is there any other way to back up the database.
Thanks

Re: HowTo: Duplicate a Drupal 7 Website for Testing and ...

a Very nice procedure and fail safe. it is working nice and smoothly at hostgator.com on drupal 7.0 . I did my a set up with a domain and a dev sub domain.

I sync my files with synctoys and netdrive for the moment until I have time to do a bourn script to tar untar these files.

Re: HowTo: Duplicate a Drupal 7 Website for Testing and ...

Glad you found this useful. I am working on an updated howto about this that will be posted on Drupal Mill as soon as I have got some other stuff ready first.

Re: HowTo: Duplicate a Drupal 7 Website for Testing and ...

Hi Thomas, found your instructions on how to move a drupal site. And it worked perfectly. Thanks for the great tutorial.

Re: HowTo: Duplicate a Drupal 7 Website for Testing and ...

I think this is nice idea. A Very nice procedure and fail safe, it is working nice and smoothly. Thank you.

Re: HowTo: Duplicate a Drupal 7 Website for Testing and ...

after step 9 (in Getting the Duplicate Website Up), all i get is the server config page and have tried all alternatives.

Somehow all links change to the local server wamp homepage.

i am usig same matching versions of drupal 7.8 on the webserver locally as well as on the live site

Re: HowTo: Duplicate a Drupal 7 Website for Testing and ...

What if you don't have FTP access? :(