Migrate or Duplicate a Drupal Site
Last month we wrote this tutorial showing you how to create backups using the Backup and Migrate module. Now we need to learn how to use it to either migrate or duplicate a site.
If you have an existing site, and need to make some changes or add modules, it’s best to create a test environment that is identical to the production site. Do all your experimentation there and then it’s a snap to migrate the changes.
This tutorial shows you how to migrate or duplicate your site using the Backup and Migrate module.
Step 1. Backup, backup backup
Got to Configuration > Backup and Migrate. For complete installation and setup instructions, follow the directions in our tutorial.
Save the backup to your local computer. You can do a Quick Backup or choose Advanced.
Step 2. Backup the database and download
Choose the Default Database > Choose Download > Backup now.
You can choose the Manual Backups Directory and restore from there when you’ve moved your site files. Any other destinations you created on the Destination tab when you set it up will also be visible.
TIP: I suggest the first time you try this that you also download a copy, and don’t rely totally on the Manual Backups Directory. I found that trying to restore the first time from the Manual Backups DIrectory was less reliable. Files get corrupted in transfer occasionally and it’s good practice to have a duplicate.
Step 3. Copy your entire Drupal site to your destination
Copy the entire site, or alternatively, you can download it to your local computer with FTP. There are several ways to move or copy all the files in a directory. Use a method you know you will work for you.
Step 4. Rename your settings.php file
On your test site, go to /sites/default and find your settings.php file and rename it. (You could delete it as well, but you will need to refer to the original later on). Do this on your local computer before FTP upload.
If this file is missing or renamed, Drupal will create a new settings.php file for you. When you visit the site for the first time you will go through the normal installation process. If you do it this way, all the paths and base urls will be correct for this installation.
You may have trouble renaming this file in an installed drupal site. In a normal Drupal installation, the permissions are set so this file can’t be changed. If you haven’t run setup yet, or you do it before you upload, you shouldn’t have a problem.
Step 5. Create a database for this new installation
Use the control panel of the server, or phpMyAdmin to create a database for this site. If you are on a completely different server, you might want to create a database with the same name. If you are on the same server or in a sub directory of your main site, you need to create a new database name.
Step 6. Get the information on the database for your original site
Open the backup of the settings.php file you made, or look in the settings.php file on your original site. It’s located in the /sites/default/ folder. Open it with an editor and look for the information. .
If you have created a new database, you will have all the required information except the database prefix. You will need that to make the content show, so be sure to record it after looking at the settings.php file.
Step 7. Visit the site and get ready for a standard installation
When you visit the site you will see the standard installation screen. Click Save and continue.
NOTE: You need to have created a database for this before you started.
Step 8. Enter the new database information
Enter the Database name, username and password. Click Advanced options and add the Table prefix.
Follow through the rest of the installation and visit your new site. Then enable all your modules.
Step 9. Activate the modules
Go to Modules, scroll down and put a check mark in the box next to the Backup and Migrate module. Activate Pathauto and Token, these are needed to run Backup and Migrate. You can also go through the entire list at this time and enable all necessary modules.
Click Save Configuration.
If you made a complete copy of the original site, all the modules should be here and installed ready to activate. If you are doing this in a new installation, upload everything in the old sites folder (except the original settings.php).
Step 10. Access Backup and Migrate
Click to Configuration > Backup and Migrate.
Step 11. Restore from your backup
On the Restore tab, browse to the backup file you saved on your computer, click Restore now.
Visit the site to see if everything is correct. If you see a duplicate of your original site, you’ve succeded!
I have a duplicate site up and running using this tutorial.
Just want to clarify that when we restore the original site’s database on new(duplicate site) then all the changes i do will be made to new database ?
Crystal clear, to the point and … it actually works 🙂
One thing to add. I was trying to mirror my amazon web site. The process was an all day event. I tried relentlessly to follow a process similar to your tutorial keeping in mind I’ve done this before. The file size was an issue. After reading in drupal forums about post_max_size settings in the php.ini file I set it to a higher amount because the site was 36MB, where as the default limits are 8M.
File upload setting can also be set on both php.ini at least in a turnkey virtual box image.
You’ll need to set the file permissions for the settings.php file create a private file setting in configuration before importing the restore file.
I created the database but as an aside for people who don’t know phpAdmin if it is a preconfigured Turnkey drupal drop the database and set the users privledges.
Wonderful! It works like a charm! Using Drupal 7.17 with many modules installed
Thank you for your clear instructions! I was going crazy trying to restore before following your guide.
I’ve run through this a few times and the best I can do is to get the content without any of the styling. I get this error:
failed to open stream: “DrupalTemporaryStreamWrapper::stream_open” call failed in file_unmanaged_save_data()
Wow. I cannot tell you how much trouble this just saved me. I’d add three things here:
1. if you’re using clean urls on your site, make sure you get the right .htaccess rewrite rules in place before you restore your db from the back up of your live site. ([url=http://drupal.org/node/15365)]http://drupal.org/node/15365)[/url]
2. i had to replace the full url of my live site in the database back up to the full url of my qa site before i did the back up. literally, in the insert statements, the full url of my live site was present, so i just did a global search and replace in ViM on it.
3. do NOT forget to put the prefix of your tablenames in the set up of drupal. critical piece of info.
All that said, THANK YOU!!!
Except that the prefix in my settings.php is blank:
I have some other D7 working sites (on localhost), and their prefix terms are all blank. Do you have any ideas? Thank you for taking the time posting all the details.
Followed every step very clear but every time i do this i get to the home pags all looking good but the links to other pages give an erroe of page not found 404.
Please are you able to help or do you think my live site is corrupt? using D7.22
You are the best – I was able to upload my site after 4 days. I am so happy its up now. Site address: [url=http://www.thepulp.co.in]www.thepulp.co.in[/url]
I found that making backup with “zip” compression is more reliable than “gzip” format when come to restoration. I failed several times to restore a gzip copy which seems corrupted but zip file is always working. I set my compression as zip since then.
This worked ok in the end, but there were several confusing areas or steps left out. I only do stuff like this once a year, so I don’t necessarily remember what may seem like basic info to others.
For the settings.php file, the file was missing. I ended up getting a copy of default.settings.php from an unpacked version of Drupal. I put that in sites/default. Then I renamed that file as settings.php. I set the permissions for default and settings.php to 777. (I think 775 would also work.) The installer automatically changed the permissions back to 555 or whatever when it was done, so I didn’t have to do that manually.
My site did not have a data base prefix. It was listed as $db prefix = ‘ ‘ ;
I ended up manually editing the settings.php file with the new database info.
$db url = ‘mysql://db_user_name:password@localhost/new_database_name
I didn’t need to do anything with the database prefix either manually in the settings file or in the installer.
Visiting the site – I made a subdirectory called new_test_site in public_html. My site was located at the URL of my old site slash the name of the subdirectory. ([url=http://www.example.com/new_test_site)]www.example.com/new_test_site)[/url].
The database restore kept cycling and cycling and apparently didn’t work. After a couple of hours I closed browser and went to bed. When I checked the next day, it had actually worked. I had a 9MB site and the message on the home page of the new site gave the number of millseconds which ended up being 13.5 minutes. So if it gets stuck in a cycling mode and it’s been awhile, just go to your site’s address to see if it worked.
Hope this helps someone (or myself if I have to do this again a year from now 🙂
This is awesome! Only issue I have is that any images that I have on the pages refer to the original URL. The images were copied over though. How can this be resolved? Do have to go into the source code of every page & change them?
in the live site i have path module for change url, but now, on my local server i can’t do anythings because all links bring me to a 404 error..
I had faced the same problem and i found this https://groups.drupal.org/node/105954 after a short googling on it.
It is so easy to solve it. Just find a .htaccess file from a drupal 7 installation and upload it to your root folder of Drupal in your server.