5. SharePoint 2010 RBS Storage
RBS stands for Remote Blob Storage. In SharePoint,
any document that you upload into any SharePoint site, all the metadata
and the actual blob are both stored in SQL Server, specifically in the
content database. As I mentioned earlier, there are many situations in
which you might want to change this behavior, and allow a SharePoint
installation to store its binary blobs outside of the SharePoint server
database:
You may want to separate out large blobs, say video files, and store them on a non-database file store for performance reasons.
SQL storage is generally expensive when compared with simple file stores.
Larger blobs also mean longer backup and recovery times for the SharePoint content databases.
Blobs
generally hold files that are sometimes very critical. They may need to
be "shredded" when they are deleted, or maybe (depending upon the need
they need to be immutable) only new versions can be created. Shredding
individual files as they are stored in the databases is not an easy
thing to do, but is more manageable on a file store.
Databases
store blobs using varbinary(max) column types. This means that the
maximum file size is limited to 2GB. Blob stores have no such
limitation.
All these problems are solved by RBS. In order to
use RBS, you will have to use SQL Server 2008 R2 or better with
SharePoint 2010. With SharePoint 2010, you have the ability to make the
BLOB store externalizable at a per-content database level. By
specifying a SQL RBS provider, you choose to redirect the actual blobs
to some external storage, but the metadata continues to live in the
content database. Thus, the SharePoint object model doesn't know the
difference between whether your content database is storing the blobs
within itself or redirecting the blobs to an external blob store.
As the third-party marketplace develops, there will
be many third-party RBS providers. From Microsoft, however, RBS for SQL
Server 2008 R2 is a downloadable stand-alone component. You can
download this provider from http://go.microsoft.com/fwlink/?LinkId=177388.
Go ahead and download this provider. Before you can
install it, however, you need to configure your SQL Server installation
to work under Filestream. If you did not enable Filestream on your SQL
Server installation during setup, you can still do so by going to SQL
Server configuration tools, finding the service running your SQL
Server, choosing right click\properties on the service, and going to
the FILESTREAM tab. Configure to run Filestream as shown in Figure 4.
Then, in SQL Server Management Studio, execute the following command:
EXEC sp_configure filestream_access_level, 2
RECONFIGURE
Next, execute the TSQL script shown in Listing 2
in SQL Server Management Studio to create a master encryption key and
to set up the blobstore file group in the WSS_Content database.
Example 2. TSQL Script for Configuring Filestream support on WSS_Content
use WSS_Content
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'
if not exists (select groupname from sysfilegroups where groupname=N'RBSFilestreamProvider')alter database WSS_Content add filegroup RBSFilestreamProvider contains filestream
alter database [WSS_Content] add file (name = RBSFilestreamFile, filename = 'c:\Blobstore') to filegroup RBSFilestreamProvider
|
You may verify at this point that a directory called
c:\Blobstore has been created for you, and an RBSFilestreamProvider
Filegroup has been created for you under the WSS_Content database. This
can be seen as shown in Figure 5.
You are now ready to install and configure your RBS
provider. Once the provider is downloaded, go ahead and install it by
executing the following command from DOS Prompt, in the same directory
where the RBS blob provider you downloaded earlier is saved:
msiexec /qn /lvx* rbs_install_log.txt /i RBS_X64.msi TRUSTSERVERCERTIFICATE=true
FILEGROUP=PRIMARY DBNAME="WSS_Content" DBINSTANCE="SP2010"
FILESTREAMFILEGROUP=RBSFilestreamProvider FILESTREAMFILEGROUP=RBSFilestreamProvider
FILESTREAMSTORENAME=FilestreamProvider_1
Give the previous command about a minute to run. It
should produce an output in a file called rbs_install_log.txt. Open
that file, and look for the following line toward the end of the log
file.
Product: SQL Remote Blob Storage -- Installation completed successfully.
This line indicates that the RBS provider was
successfully installed. At this point, changes have been made to the
content database. You should verify that by opening the content
database, and looking for numerous tables that start with "mssqlrbs".
If you are doing this in a production environment,
it will need to be installed on all web servers and application
servers; install the RBS Provider on each web front end. You can do so
using this command:
msiexec /qn /lvx* rbs_install_log.txt /i RBS_X64.msi DBNAME="WSS_Content" DBINSTANCE="SP2010"
ADDLOCAL="Client,Docs,Maintainer,ServerScript,FilestreamClient,FilestreamServer"
Next, you need to enable and test RBS. In order to
do so, launch the SharePoint 2010 management shell (which is a
customized power shell for SharePoint and can be found under
Programs\Microsoft SharePoint 2010 products\SharePoint 2010 management
shell). In that shell, execute the following script:
$cdb = Get-SPContentDatabase -WebApplication http://sp2010
$rbss = $cdb.RemoteBlobStorageSettings
$rbss.Installed()
$rbss.Enable()
$rbss.SetActiveProviderName($rbss.GetProviderNames()[0])
$rbss
Next, visit your SharePoint site and create a new
document library there. In this document library, go ahead and upload a
file. It would be rather nice if you can upload an image file instead.
I have included a sampleimage.jpg with the source code for this
purpose. Note that the image file gets uploaded into the document
library as you expected SharePoint to do.
Now things get interesting. Visit the C:\Blobstore
directory and sort by Date Modified. Look forthe GUID looking directory
that was modified last. Inside it you will find another directory that
looks like a GUID. Strangely enough, these GUIDs correspond to the Site
Collection GUID and the Document library GUID. Keep drilling down until
you see a file sitting on the file system (see Figure 6).
Drag and drop that file into Internet Explorer. What
do you see? You should see the same image you had uploaded load up
Internet Explorer (see Figure 7).
Thus as you can see, the RBS storage
mechanism redirected the blob to the filestream. The SharePoint object
model is blissfully ignorant of this redirection, so your applications
continue to function as-is.