drupalfun.com
Clone / duplicate Drupal installation
This week I cloned one of my Drupal installs. Very usefull and a great timesaver.
Here is how I did it:
Step 1
Copy all of the files to your other webspace using ftp
Step 2
Dump your existing database in an .sql file. I used the following php script:
$db="xxx";
$name="xxx";
$user="xxx";
$pw="xxx";
mysql_connect($db,$user,$pw);
@mysql_select_db($name) or die ("Kon geen connectie maken met de database!");
$filename = "db_backup_" . date("n-j-y");
header("Content-Disposition: filename=$filename.sql");
header("Content-Type: application/force-download");
exec("mysqldump --add-drop-table -h $db $name -u $name -p$pw", $sql);
for($i = 0; $i < count($sql); $i++) {
echo $sql[$i] . "\r\n";
}
This nifty little script asks you for the filename you want to give your .sql and automatically even suggest one including the current date. I just love it.
Step 3
Make some adjustements to your .sql file using Notepad ++ or Kate:
- Change the table extension for xxxx_ to newxxx_ by replacing all instances
- Next you will want to search for oldurl.org and change it to newurl.org everywhere
Step 4
Now it is time to upload your new database. I used a great free script called bigdump. Great for uploading big files. If your file is not very big, you don't really need it and you can just execute the queries in the dump file.
Step 5
If you take a look at your site now, it probably looks ok. That's because it still points to the old database file!! Change your /sites/default/settings.php file with the correct base url and appropriate new database settings.
Step 6
If you take a peak again, things most likely will look terrible! Oh no... no need to panic however. Truncate (or empty) your menu_cache table and...
Voilà ... your new site is up and running!

