Import/Export and New Content Databases
Earlier this evening, there was a discussion on an internal discussion list about the best way to cut a subsite out of a site collection and make it into a separate site collection in a separate database. We went back and forth and I finally suggested an option using STSADM from the command line. Now you need to understand that while this seems to work like a charm in WSSv3 (and for the purposes of this blog I will not be talking about WSSv2 or SPS 2003), there are some pitfalls to doing this in MOSS. The main one being that this has been known to break some webs that utilize the collaboration portal or publishing portal templates (or templates created from them). But for your regular run-of-the-mill team sites and such, this should work like a charm.
Your first step is to have a subsite. We will say that we have a subsite located at http://server/mysubsite that we want to make into a site collection located at http://server/mynewcollection in a separate database. We would start by exporting out the site collection to a file as such:
stsadm.exe –o export –url http://server/mysubsite -filename mysubsite.bak –includeusersecurity
Now why would we want to create a site collection in a new database? Well…it seems that Microsoft recommends that you try to keep your content databases under 25GB if possible. We recommend this for various reasons to include ease of backup and being able to maintain separate SLAs (service level agreements) for differing site collections (say HR or marketing). Do we want hundreds of separate content databases? No…of course not. But if possible, group like collections into separate databases (say IT collections or HR collections) for ease of maintenance later.
Since we don’t want to use the normal convention of http://server/sites/sitecollection, we are going to need to add a managed path. We can do that through the GUI or via command line as such:
stsadm.exe –o addpath –url http://servername/mynewcollection -type explicitinclusion
We make this an explicit inclusion because we want to put the new collection directly at this point. If we created it as a wildcard inclusion, then it would be like the /sites/ that we normally use. So you could optionally create a wildcard inclusion for IT and the URLs would stem off as in http://server/IT/sitename.
Now we have to create the new site collection in the new database. We do this to make a placeholder. If we didn’t, then there would be nothing to import to in the final step. At this point, we really don’t need to add a lot of fluff. Just do the basics.
stsadm.exe –o createsiteinnewdb –url http://server/mynewcollection -owneremail portal@server.com –ownerlogin DOMAIN\username
This gets us most of the way there. If you wanted to get fancy, you can always look at the syntax of the createsiteinnewdb option and notice that you could specify the database server, username and even the database name. This could come in handy if you are a bit anal about your naming conventions like I am. I like to see all of my content databases named as Content_xxx so they are grouped together for easy maintenance.
Our container is ready and all we have to do in import our backed up subsite into the new site collection.
stsadm.exe –o import –url http://server/mynewcollection -filename mysubsite.bak –includeusersecurity
Once this has been complete, you should be able to browse out to the new site collection. This could also be converted into a batch file or a VBScript in a pinch. For some of the syntax and an example of how to write a parameterized script, please see my last blog post. There is a zip file at the end that has a lot of batch files and a script that will get you on your way. And if that seems too difficult, you can always send me a note and I will try and help out as best as I can.
If you are trying to get the collaboration portal or publishing portal templates to export/import correctly, you should look at a post located at http://stsadm.blogspot.com/2007/09/convert-sub-site-to-site-collection.html to see how he did it. One word of caution though. The way he does it actually touches the database. This particular method is not recommended by Microsoft and may put you in an unsupportable state. I refer you to this post to see possible ways of doing something similar for education purposes only.