Wednesday, February 1, 2012

Backup and Restore a SharePoint Site Collection 

Software development industry which develop projects based on SharePoint 2010, now trying to move into new approach what we called "Backup and Restore" rather than stick with the traditional approach where you create all the list site and other stuff with in the SharePoint project (VS project). specially when you are in a mid scale project time is a crucial factor and your client always expect to see something alive in daily basis.
When I join to the Navantis, my first project client wanted to finished it with in 4 weeks. Then, Navantis has decided to take Back up & Restore approach (which they haven tried before here in Sri Lanka).

In this approach, you are always asked to use, Out of the Box features (OOB). When you create list with in the site collection, when you create pages with in the site collection, master pages styles, almost everything including Data view web parts (by using SharePoint Designer). but if you are using some custom web parts, then you have to deploy them separately.    

How to take a backup of a site collection.

Open the Central Administrator (you should have privileged to CA). Start > All Programs > Microsoft SharePoint 2010 Products> SharePoint 2010 Central Administration


then you can see the Central Administration panel
Using SharePoint 2010 Central Administration Web site, under Backup and Restore, click perform a site collection backup



Then You get a Backup panel which has two main fields, which mandatory to be filled.
1) Site Collection path.
2) Backup path (where to save the Backup file)
and there is a option to select whether we are going to overwrite the existing file or not.
through the upper coner drop down you can choose the site collection path which need to be Backup. then choose the site collection path (even if it's in the manage path). 

After that you need to enter the Site collection backup file path. Eg: C:\SharepointBackup\port80.bak, then click ok. But there are some concerns on this path.
1) The folder (in here SharepointBackup) should have Write privileged. (other wise you'll get an Error when the service is started.)  
2) Backup File name should have .bak extension.
3) If a Backup File already exist on the current lactation with a same name then you need to check the "Overwrite existing file" option.

then you can see the backup service is starting.
Initially there are two options refresh and delete the job. if something going wrong with the backup or you accidentally click ok button then you can delete the backup service job.

but when the service got started. then you have to wait. and by clicking refresh button you can see whether service job finished or not.

when it get finished. then you can go to the location, where your file should be saved then you can see you backup file has been created.
This is how you can take entire site collection back up, which contain all the files and settings, but as I mentioned earlier, If you got any custom Web parts in your site collection. then you need WSP file also for restoring process . 

How to RESTORE a site collection using Backup File.

Restoring is also a easy process like the backup process. but you need to concentrate many factors when you are going to restore the backup file in to a new environment.

The following SharePoint Server Configuration should be exist on the server.
1)SharePoint farm version number should be equal or above, Means that sharePoint version number of the restoring server environment should be equal of higher than Backup server environment. 
NOTE :
Using PowerShell - (get-spfarm).BuildVersion command then we can get the version number 

PS C:\Users\thilinak> (get-spfarm).BuildVersion
Major Minor Build Revision
-----  -----  -----  --------
14     0      4762   1000

Version number:  14.0.4762.1000

2)SharePoint should run the Profile Synchronization Service Application and User Profile Service.
3)Other features (Eg: Language Packs), if Required need to be installed in the Restoring environment. 

NOTE:
Using SharePoint 2010 Central Administration Web site, under Upgrade and Migration, click Check product and patch installation status 


Once you are done with the initial configuration. we need to create a web application. on restore SharePoint environment. Or if you are going to restore it into the same application then you need to creat a Manage path . but make sure that, the path which you are going to restore should be empty (No site collection Existed ).
NOTE:
Create Managed path in the Production web application (if it is not already exist or created)
Using SharePoint 2010 Central Administration Web site, under Application Managment, click Create Site Collections. 
Then Go-to the Define Manage paths to create one. Give a name to the path “eg : Main” select type as Explicit inclusion , the added it and click ok.

Restore Back up file in to the manage path or Root path.
Using PowerShell – 
restore-spsite -identity http://sharepointqa.example.com/main/ -path C:\ExampleIntranetBackup\  ExampleIntranetUATProductionRLS01\ ExampleIntranetBackup.bak
Then you will get the message asking the restore options. Give A for that (yes to all)
 (replace “http:// ExampleIntranet.camoplastsolideal.com/main/ “ with valid production URL and replace “C:\ ExampleIntranetBackup\  ExampleIntranettUATProductionRLS01” with production back up file location)
Confirm
Are you sure you want to perform this action?
Performing operation "Restore-SPSite" on Target
" http://sharepointqa.example.com/main/ ".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help
(default is "Y"):A

Wait till the restoring process is finished (if the process is successful it will display root path without given any red warnings)

If there is a site collection already exist in the given manage path then, we need to do the restoring process with overwrite command. (-Force)
[Warning: This will overwrite content and everything. You might lose any existing content. Which not include in the back up file. ]

Using PowerShell – 
restore-spsite -identity http://sharepointqa.example.com/main/ -path C:\ExampleIntranetBackup\  ExampleIntranetUATProductionRLS01\ ExampleIntranetBackup.bak -Force
Then you will get the same message asking the restore options. Give A for that (yes to all)
Confirm
Are you sure you want to perform this action?
Performing operation "Restore-SPSite" on Target
" http://sharepointqa.example.com/main/ ".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help
(default is "Y"):A


When you got any wsp (which contain custom web parts and other required dlls), then you should deploy it into the application. 

WSP Deployment.

Add the required wsp (Internet.SharePoint.wsp) into the system using PowerShell – 

add-spsolution -literalpath 'C:\Backup\ UATProductionRLS01\Internet.SharePoint.wsp'  
(C:\Backup\ UATProductionRLS01\Internet.SharePoint.wsp is the wsp path)
Then using SharePoint 2010 Central Administration Web site, under System Settings, click Manage farm solutions. Verify that wsp was added. 
Deploy Required WSPs on production application. 
SharePoint 2010 Central Administration Web site, under System Settings, clicks Manage farm solutions. Then click on WSP which need to deploy. Clicks Deploy Solution


Select application which you need to deploy (eg: http://sharepointqa.example.com) clicks ok
Now you are done with the restoring process. but event you are done you might not be able to access the site,Backup file which extract form development environment might include development users (who exist in different domain) as site collection administrators. So we need to replace them with production administrators.

SharePoint 2010 Central Administration Web site, under Application Management, clicks Change site collection administrators.  Then select the site collection. And change the Administrators.

 Then you can access the site with admin account.

ok That's It ... 
HAPPY CODING

No comments:

Post a Comment