Thursday 26 April 2012

SharePoint Backup and Restore


If  you are moving your site from Testing(Staging) to Production, site backup and restore (using STSADM command line tool)  is the way to go. Other ways include SQL Server, Sharepoint Designer, DPM etc. However, site backup and restore using STSADM is probably the easiest and fastest one.


Backup the site using the following STSADM Command:Stsadm –o backup –url http://<server name>:<port> -filename <path\name to be used for the backup file>
Example:
Stsadm –o backup –url http://pola shivainfo:4545–filename "e:\backup4545.bak"

After the backup has been completed, “Operation Completed Successfully” message should be displayed.



Create a new Web Application for restoring the site:Go to Central Administration -> Application Management -> under SharePoint Web Application Management -> click Create or Extend Web Application. Fill in the required information, click Ok and wait until the progress continues.
Once the new web application is created, run the following STSADM command and restore the site using the backup file created above.

Stsadm –o restore –url http://<server>:<port> -filename <path\name of the backup file>
Stsadm –o restore –url  http://polashivainfo:5454  –filename "e:\backup4545.bak"

Restored site should be up and running.
If it is not (and you are receiving weird errors in your browser), keep reading:
Now it could be the case that you have customized your site. So, we must deploy those customizations properly for the site to work as expected. This is typically a scenario while moving your site from Testing to Production environment. First you have to add the solutions (if any created) to the farm.
Add a Solution to the SharePoint Farm:Add the solution package to the farm by running the following commands. Make sure full path of WSP file is supplied.
 
stsadm –o addsolution –filename <path to mysolution.internet.test.wsp>

Deploy the Solution to the restored site:
Now we need to deploy the newly added solution to our restored site. Click the solution name and select ‘Deploy’ button from top. Select the appropriate web application in the deployment settings and click OK. This will take several minutes to deploy mysolution.internet.test.wspresources (list templates, features, assemblies, master pages, styles). Once the solution has been deployed, reset IIS to ensure all deployed changes are picked up by the web application.
You can also deploy the solution from the command line with the following SharePoint admin command.

stsadm -o deploysolution -name mysolution.internet.test.wsp -url <site> -immediate -allowgacdeployment –allowcaspolicies

Make sure all your assemblies (DLLs) are available in Global Assembly Cache (GAC) usually placed at c:\windows\assembly.  
 Activate features installed by mysolution.internet.test.wsp solution package:Go to the newly restored site, click Site Actions, click Site Settings, click Site Collection Features. Click Activate button to activate any Site Collection Feature.
Go to the newly restored site, click Site Actions, Site Settings, Site Features.
Click Activate button to activate any Site Features.
Update Web.Config file:It will be usually a case that your solution package will deploy a few DLLs with it. So we need to add all those Safe Control entries, Assembly Bindings, Keys and any other web.config changes to our newly restored sites’s web.config. Weird browser errors that I mentioned above usually appear due to these missing entries in web.config, specially when you are restoring on the same machine/server…….As assemblies will already be there in the GAC if the restore operation was performed on the same machine….you just need to make web.config entries to the restored site…..adding and deploying of the solution could be skipped. So lets do the copy paste operation from the old web.config to the new web.config. Just compare the two web configs and copy/paste the missing entries into the new. 
Web.config file could be found at the following path:
<drive letter>:\Inetpub\wwwroot\wss\VirtualDirectories\<port number>\web.config
 

Example:C:\Inetpub\wwwroot\wss\VirtualDirectories\5454\web.config 
 

Usually these changes will include Safe Controls, AssemblyBindings, PageParserPaths and Keys etc. After making these changes your site should be ready in Production.
If you are worried about the bad habit of Moss saving absolute URLs for the page layout in the properties of a publishing page, then relax, solution is already in the market:

No comments:

Post a Comment