Tuesday, June 26, 2012

Configure SPF with RBS(Remote Blob Storage)/Store file externally

Configure your First Web Application for RBS

By Default SharePoint 2010 Foundation/Server store attachment files within the database call Blob type unlike WSS3.0, which it store file external automatically. But Luckly, there are solution from Microsoft that can have the blob type to be a remote blob, means the file can be store external from your physical HDD like WSS3.0.
This article describe by assuming you had all your SP/SPF2010 installed properly or even in a production environment.

bellow are the steps:
This is about how to configure your SPF to store files/Attachment external other than inside Database
1. go to Server installed with SQL/SQL Express.
2. launch SQL Server Configuration Manager.
3. Go the database instance, right click and choose Properties.
4. Go to Filestream Tab and check all the check box, apply and closed.



Some article mentioned that there are user who face problem of installing RBS, to solve it, simply enable pipe line from SQL Server Network Configuration.












5. Now Access to SQL Server Management Studio, access the script bellow by creating a new query:

EXEC sp_configure filestream_access_level, 2
RECONFIGURE

6. Now, choose your database. Then run the script shows bellow:

use [WSS_TEST]
if not exists 
(select * from sys.symmetric_keys 
where name = N'##MS_DatabaseMasterKey##')
create master key encryption by password = N'Admin Key Password !2#4'

where WSS_Content is your SPF Database(when you create a new SPF web application).
In my case, i use WSS_TEST.
Note: The password i rather use default as given from microsoft technet article:
http://technet.microsoft.com/en-us/library/ee748631.aspx


7. After the script above successfully execute, go to your SPF web application database and run the following script:

use [WSS_Content]
if not exists 
(select groupname from sysfilegroups 
where groupname=N'RBSFilestreamProvider')
alter database [WSS_Content]
add filegroup RBSFilestreamProvider contains filestream

Just like before, rename WSS_Content to SPF web application database.

8. Then execute the last script from bellow:

use [WSS_Content] 
alter database [WSS_Content]
 add file (name = RBSFilestreamFile, filename = 
'c:\Blobstore') 
to filegroup RBSFilestreamProvider

The default external storage location was define at C:\Blobstore folder. This folder must not physically exist otherwise the script will cause error.
You can allocate it to a different storage. For my case, i rather use different folder for different web application. here i choose D:\WSS_TEST_Blobstore
Note: In case any changes to blostore location, you can reprovision by remove, then apply the script above.
to remove use sql query:


ALTER DATABASE databasename REMOVE FILE RBSFilestreamFile


where databasename is the name of the web application.


9. Download RBS client installer from:
 http://go.microsoft.com/fwlink/?LinkID=188395&clcid=0x409.
OR
Microsoft SQL Server 2008 R2 Feture Pack: 
http://www.microsoft.com/en-us/download/details.aspx?id=16978


Open command prompt with administrator rights, navigate to rbs client installer download folder. for example C:\temp, install with command as bellow:

msiexec /qn /lvx* rbs_install_log.txt /i RBS.msi TRUSTSERVERCERTIFICATE=true FILEGROUP=PRIMARY DBNAME="WSS_Content" DBINSTANCE="DBInstanceName" FILESTREAMFILEGROUP=RBSFilestreamProvider FILESTREAMSTORENAME=FilestreamProvider_1


where DBNAME is the database of the SPF web application, my case is WSS_TEST, DBINSTANCE is the instance name of SQL Server. my case is "PORTAL\SQLEXPRESS". So the result would look like this:

Note: Many articles mention  DBInstanceName is the name of the sql server instance, which is either SQLSERVER or SQLEXPRESS or any name cared by the user. Infact after tested, the DBInstanceName is "ComputerName\SqlServerInstance"  as shown above.  Link bellow shows a screen cap of rbs client installation steps which also shows how the instance name to be use:
http://netindonesia.net/blogs/andriyadi/archive/2010/07/27/configure-sharepoint-2010-to-store-files-blob-to-the-file-system.aspx

msiexec /qn /lvx* rbs_install_log.txt /i RBS.msi TRUSTSERVERCERTIFICATE=true FILEGROUP=PRIMARY DBNAME="WSS_TEST" DBINSTANCE="PORTAL\SQLEXPRESS" FILESTREAMFILEGROUP=RBSFilestreamProvider FILESTREAMSTORENAME=FilestreamProvider_1


For the rest of the web and application server if available,  install with command bellow to the additional web server:

siexec /qn /lvx* rbs_install_log.txt /i RBS.msi DBNAME="WSS_Content" DBINSTANCE="DBInstanceName" ADDLOCAL=Client,Docs,Maintainer,ServerScript,FilestreamClient,FilestreamServer

Like before, replace WSS_Content to your web application database, replace DBInstanceName to sql instance name ("PORTAL\SQLEXPRESS").

Notice that a log file will generate and the size of the log file is about 1.38Mb. Open it and search with the text "completed successfully". Note that if your file size is less than 1Mb, then you may have not install correctly.

10. Finally go back to SQL Server Management Studio, explore your web application database, you should see some new table generated label with "mssqlrbs_"
Note: you can perform sql query with 
select * from dbo.sysobjects where name like 'rbs%'



















10. run SPF PowerShell with admin right and execute bellow:

$cdb = Get-SPContentDatabase ContentDatabaseName
$rbss = $cdb.RemoteBlobStorageSettings
$rbss.Installed()
$rbss.Enable()
$rbss.SetActiveProviderName($rbss.GetProviderNames()[0])
$rbss

where ContentDatabaseName is web application database name (WSS_TEST).
Note: To find out what ContentDatabaseName is, you can access to SPF Central Administration,  Application Management, Manage Content databases. Choose the desire web application.



Additional RBS for other Web Application
My sharing above only apply when you first configure your SPF for the first web application. Subsequently,  you are only require to configure your database to rbs enable with steps bellow:
1. Repeat steps 6 to 8 above to configure other web application with SQL Server Management Studio.

2. Run rbs client installer with command bellow:

msiexec /qn /i rbs.msi REMOTEBLOBENABLE=1 FILESTREAMPROVIDERENABLE=1 DBNAME="ContentDbName" FILESTREAMSTORENAME=FilestreamProvider_1 ADDLOCAL=EnableRBS,FilestreamRunScript DBINSTANCE="DBInstanceName"

Where ContentDbName is your web application database name, DBInstanceName is your SQL Instance name as i describe before, "ComputerName\SQLServerInstance"

Migrate from existing Documents/Files to RBS
1. Run SharePoint 2010 Management Shell with admin rights, execute command as bellow:

$cdb=Get-SPContentDatabase ContentDbName
$rbs=$cdb.RemoteBlobStorageSettings

Where ContentDbName is the database name of the web application

2. To List all the RBS Provider, execute:
$rbs.GetProviderNames()
 3. To set first provider to be active, execute:
$rbss.SetActiveProviderName($rbss.GetProviderNames()[0]) 
3. To migrate, execute:
 $rbs.Migrate()
4. Send a query at with "Select * from AllDocstreams where RBSID IS NOT NULL" to verify if there are records return after migrate. if none return, means files are remain at database.


Final Words
My sharing above may found similarity to other tutorial but what i describe here are those steps that really confuse me. I personally tried out and found error, try again and again until i finally made it.
all sharing above can be found from link as bellow:
http://technet.microsoft.com/en-us/library/ee748592
http://blogs.technet.com/b/pramodbalusu/archive/2011/07/09/rbs-and-sharepoint-2010.aspx