So I had a task to move multiple SharePoint site collections/Farms to sub sites within one site collection so that the company could condense their hardware into one farm/site collection among other reasons.
Although this is fairly simple I have learnt a few tips from this exercise which is why I will cover it entirely in this blog;
Let’s assume that the farm you are exporting from has no custom solutions installed as things then get trickier, all solutions must be the same on both farms. This is a good reason to always keep copies of anything you install on a SharePoint farm, I have seen companies before who have purchased third party solutions then a few years later that company goes out of business or is brought out and it’s almost impossible to get the original install/WSP files, then when they want to upgrade or migrate they face custom solution issues.
From a front end server on the farm you are exporting out you have two options, export using either STSADM or PowerShell. If you are running 2007 then you only have one option and that is STSADM.
As I have been using SharePoint for a long time I will usually go down the STSADM route without thinking, but we all know that PowerShell is a lot more powerful for most commands so it’s usually best to go down the PowerShell route. However in this case Importing and Exporting in STSADM and PowerShell run almost the same processes to its really personal choice.
If you are going down the STSADM route then open CMD as an administrator and cd to the Hive 12/14 bin folder. Once there set your STSADM command, set the Operation as export, specify the URL of the site collection or Subside you want to export and set the filename and location of where you want to the exported file to go (remember to make sure that the drive has enough space). I have just described the basic switches which you are required to make an export run but there are more to specify and constraints you may have. For example by default the export compresses all of the files into a compressed file, unless space is an issue I do not like to do this so I run the switch –nofilecompression on the end, this then exports the files to a directory.I won’t go over all of the switches as that’s what the TechNet articles are for.
Here is a sample of how it should look “STSADM –O Export –URL http://mysite/subsite -Filename c:\backupdir\backup.cmp –nofilecompression”
If you wanted to instead use PowerShell you would open the sharepoint management shell and use “Export-SPWeb http://mysite/subsite -Path c:\backupdir\backup.cmp –NoFileCompression”. Notice that in powershell we do not have to specify the –URL switch and the –Filename switch now becomes –Path. Powershell is also case sensitive so we need to make sure capital letters are used in the correct place, again TechNet will give you the correct operations.
Here is a good place to mention the difference between SPSite and SPWeb, in SharePoint a “Site” is a site collection and a “Web” is a subsite. In PowerShell if you want to import or export a “Site” then you need to specify it by its ID not its URL.
Once you have typed your script into cmd or PowerShell then press enter and it will create the export file/directory. This could take some time if there is allot of data on the site.
Once you have your file then more that to your destination farm, onto a front end server if possible.
*If you have export from 2007 you cannot then import into 2010, exporting and migration are two completely different things. If you need to upgrade the data then do a farm upgrade before exporting or if that isn’t possible build a temp farm, import into there, upgrade the farm, do an export and then you have a 2010 export file*
On the front end server of your destination farm, choose your import method, again either STSADM or PowerShell, as a general rule I would keep with whatever I used to export. 2010 does support STSADM but it will be discontinued in the 2013 version of share point.
If you are using PowerShell then you need to first manually go to the site you wish to import the file into as a subsite and create a subsite using the same site template which was used for the original.
If you are using STSADM you can simply specify the URL where you want the site to be created and STSADM will create the site for you, this means that you do not need to work out which site template as used and pre create the site. This is why I personally prefer to Import with STSADM.
Now to type the commands to import the file;
STSADM. “STSADM –O Import –URL Http://mysite/newsubsite -Filename c:/backup.cmp –NoFileCompression”. If you used “nofilecompression” on the export you must use it on the import too.
PowerShell.”Import-SPWeb http://mysite/newsubsite –Path c:backup.cmp –NoFileCompression”.
Again there are a few other switches you can use to run the import which you will find in TechNet.
Once you have typed in the commands and pressed enter it will now begin importing and soon you will have your data moved from one farm to another.