Friday, July 6, 2012

Sharepoint Disaster Recovery - Extract File from SQL Database

There are a few cases raised by clients that they accidently deleted files from Sharepoint site and they don't have Sharepoint backup agents installed in prodcution environment. This VB script becomes really handy to export files from restored Sharepoint database without too much efforts.

Revovery steps:
1. Restore the backup database to SQL server;
2. Run this script against recoverd SQL database;
Dim contentDatabase
Dim leaf
Dim outputPath
server = "[SERVERNAME]" 'Replace with SQL server name
contentDatabase = "[CONTENTDATABASE]" 'Replace with database name
leaf = "[LEAFNODE]" 'Replace with file name
outputPath = "[OUTPUTPATH]" 'Replace with output file name with path

ExtractDoc server, contentDatabase, leaf, outputPath

Sub ExtractDoc(server, contentDatabase, leaf, outputPath)

Dim conStr, selectStr

conStr = "Provider=SQLOLEDB;data Source=" + server + ";Initial Catalog=" + contentDatabase + ";Trusted_Connection=yes" 'SQL connection string

selectStr = "SELECT dbo.AllDocStreams.Content FROM dbo.AllDocs "
selectStr = selectStr + "INNER JOIN dbo.AllDocStreams "
selectStr = selectStr + " ON dbo.AllDocs.ID= dbo.AllDocStreams.ID "
selectStr = selectStr + " AND dbo.AllDocs.Level = dbo.AllDocStreams.Level "
selectStr = selectStr + " where LeafName='" + leaf +"' AND IsCurrentVersion=1"

Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
cn.Open conStr
Set rs = cn.Execute(selectStr)
Set mstream = CreateObject("ADODB.Stream")
mstream.Type = 1
mstream.Open
mstream.Write rs.Fields("Content").Value
mstream.SaveToFile outputPath, 2
rs.Close
cn.Close
End Sub


4 comments:

  1. I would recommend you recover, open, extract sql database owing to following software repair database sql coming back databases since Microsoft SQL Server 2000

    ReplyDelete
  2. When your SharePoint database files are corrupt and we need to use access data from them, then we used of helpful tool as well known Kernel for SharePoint Server Recovery tool to effectively repair damaged, orphaned MDF files database files and do repair data instantly. Get info, visit here: http://www.en.sharepointserverrecovery.net

    ReplyDelete
  3. Restore your sharepoint database instantly and recover all data from your corrupt SharePoint database. The software is much capable of restoring all MDF file items from corrupt SharePoint database.User can get more information about this tool, visit here: - http://www.undeletepcfiles.com/sharepoint-database-recovery.html/

    ReplyDelete
  4. So Go through this advance utility to repair corrupt corrupt or inaccessible SharePoint Database, it is now available as a Free Trial version, in Free version you are eligible to repair SharePoint Database.

    Click---- http://www.filesrecoverytool.com/sharepoint-database-repair.html/

    ReplyDelete