I need to create a clone of one of my website. It will be the same (modules, views, content types, template etc...) I've already done once by coping everything and then deleting the contents and the users. Is there the right way? I will need to do 3-4 copies of the website. Is there any module that can help me(a part from backup and migrate) to do these copies? Should I create an kind of "distribution" enabling modules and creating content type, similar to the master one, from the scratch and then export the database?

If I do as I always did (clone and delete contents and users), how can I reset the content id?

Thanks in advance

  • To reset the auto increment for a table: ALTER TABLE mytable AUTO_INCREMENT = 1
    – Clive
    Jul 11 '12 at 14:39
  • If i need to keep basic pages like "about us" , should I delete it and then recreate it? Jul 11 '12 at 14:44
  • 2
    If you're going down the path of clearing out the content and resetting auto increments etc then yes you'll need to recreate any content you want to keep. I know it's no help at this point but you ideally need to plan out how you're going to make sites portable as you're building them. Then you make decisions like creating features modules, build yourself a custom workflow to handle migration, etc. I don't think you'll find a pre-built solution because there are just too many variables, too many 'what-ifs' for a generic bit of code to handle this
    – Clive
    Jul 11 '12 at 14:53
  • Exactly, I'm going to create a basic website (content type, views, modules) with the same configuration but without contents, so i would be able to get a basic installation for all of the website. I will need just to update the modules when it's required. Jul 11 '12 at 14:59

I guess what your looking for is the features module http://drupal.org/project/features. When creating clones of websites, obviously all the code/themes/modules is easy to copy but the only way to get all your node types, fields, views etc... is in the database.

Features exports all this information as a module as you can just copy this to a new site along with all your other modules, enable it, and voila all your views content types etc.. In the features you can list modules as dependencies so when enabling your feature all the contrib/core modules you need are enabled aswell (they will ofcourse need to exist on your new area).

It intergrates fully with most the big contrib modules and from what I understand is exactly what your after. It can be daunting at first but dont worry its really very easy to use. The following video is for drupal 6 but the features interface is identical (as far as I remember) http://mustardseedmedia.com/podcast/episode43

There are other more complex ways to do what your after aswell using drush and creating build scripts, you can ever combine drush, build scripts and features. However I believe just normal features will do you fine.

  • I had a consideration of this module and I will use it in the future. I already start to create a copy of the website recreating the content types and cloning the views. I don't have time now to learn Feature, i need this new website in a couple of our. There are few content types to copy and I can clone the veiws. I can do extra configuration of the modules during the development. Next week i will start to learn Feature. Thanks for the video! Jul 11 '12 at 15:23
  • 1
    No worries, features is much easier than it first looks. Good luck !
    – cconolly
    Jul 11 '12 at 15:27
  • ah ah, I know, but I've already started to create a kind of "profile" and I've almost finished. Once I finish I will try with Feature. I know Feature will be the better way but I cannot do it now, trust me! Thanks a lot! Jul 11 '12 at 15:31
  • 1
    Thats really down to you. If its a fairly simple site which you just want to clone you can add everything into one package. I've done this on a few cases. However for bigger sites you may want to brake them down into multiple "features". So each feature provides a different section to the site, or a different piece of functionality across the site. There's no right answer there, it just depends on scale. You dont want your features to get too big or else they can time out when you use them to rebuild .. this is not something you want to happen, its very annoying .. trust me :)
    – cconolly
    Jul 11 '12 at 16:10
  • 1
    When you save it it will download immediately. Treat it like any normal module, put it in sites/all/modules folder (convention normaly says create a features folder like _features. Or to have your modules folder set into 3 sections: contrib, custom, features) It doesnt matter. As long as its in the module folder somewhere you will be able to enable it just like a normal module.
    – cconolly
    Jul 11 '12 at 16:16

This isn't going to answer your question fully but it might help a bit; some code to clear out all users and nodes in the system, then reset the auto-increments on the tables:

$uids = db_query('SELECT uid FROM {users} WHERE uid > 1')->fetchCol();
db_query('ALTER TABLE {users} AUTO_INCREMENT = 2');

$nids = db_query('SELECT nid FROM {node}')->fetchCol();
db_query('ALTER TABLE {node} AUTO_INCREMENT = 1');

You'll need to use caution running the above as it's likely to take a long time and you'll probably exceed the max execution time. You could look at splitting it into batches though (probably worth another question if you decide to go down this route).

The benefit of doing things this way is that all modules (at least those that behave themselves properly) will clear up any lingering field/custom data when the entities are deleted, so you won't have stagnant data in your db.

  • Is this going to delete the content of the extra field added to a content type? Jul 11 '12 at 15:02
  • 1
    To reinforce the last paragraph, It is possible that the ALTER TABLE may cause problems because of modules that don't properly implement hook_XXX_delete and clean up custom tables. Personally, I would just live with the nid/uid not being reset.
    – mpdonadio
    Jul 11 '12 at 15:04
  • @MPD Yeah you're right, safer to just leave it as-is
    – Clive
    Jul 11 '12 at 15:08

Couldn't you just clone the site in its entirety and then delete all the content through the content interface?

If you're going to be doing this multiple times, it might be worth your while to create an install profile.

  • Hi Beth, Yes, this is what I'm always doing, but I was asking if there were other ways to do it or how to reset the content and user id. Jul 11 '12 at 14:40
  • Would pathauto aliasing solve those problems?
    – beth
    Jul 11 '12 at 14:45
  • Yes, a profile installation would be a solution... but this means I need to configure the website from the scratch which i already started to do it in the meantime. Jul 11 '12 at 14:50
  • .............yep.
    – beth
    Jul 11 '12 at 14:57

After copying files and the DB, you can clean up the node and the users Table.

Dont forget to keep the admin user in the table.

  • 5
    Unless you also clean up every other table that JOINs on {node} and {users} (eg, {node_revisions}, the {field_data_} tables, the {field_revision_} tables, {taxonomy_term_data}, {user_roles}, and countless others), then this is a recipe for disaster.
    – mpdonadio
    Jul 11 '12 at 14:44
  • 2
    Very bad idea, all related table data will be kept so you end up with a corrupt DB.
    – JurgenR
    Jul 11 '12 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.