Extracting SharePoint 2007 document libraries from SQL databases - no installation required

To cut a long story short a client recently ran into difficulties attempting to restore a document library. The following code was developed for a specific scenario where a document library had disappeared from a specific site and not showing in the recycle bin (Recycle bin worked fine on testing). I’m not sure as to how this document library has disappeared without being captured but it has!

I was against installing a full blown trial install on the SharePoint servers just to recover a single document and in this specific case there was only one environment available and time was of short supply. Appreciating a dev and test environment is the best way to work unfortunately this was unavailable and the data could not be removed from site (for obvious security reasons) to another farm to explore.

Before I supply the code I need to thank Neil Hodgkinson (Microsoft) and James Orton (Tesl) for their assistance in creating this script.

All my tests carried out have been run on a SQL VM ( see disclaimer below) however in theory you should be able to run this remotely from a desktop pc assuming the logged on user has the relevant rights to access SQL and firewall permits.

Download the script. You will need to edit the code to rename a few properties.

Server = "server" - enter the name and instance of the SQL server
database = "Moss_Content" - enter the name of the database you wish to recover the document library from (You can use SharePoint Central Admin to determine which content databases are assigned to which Web App)
location = "documents" – enter the name of the document library you wish to recover so for example this document library is called documents at the root of the site collection e.g. http://sharepoint /documents
outputPath = "c:\docs\" – This folder needs to be created prior to running the script otherwise it will fail!

Feel free to develop the code further but please do share and leave me a comment on this blog post if you do.

Further development suggestions:

  • Add a menu to navigate options
  • Output a list of all document libraries available to extract data from
  • Following on from the previous suggestion list all documents in a document library
  • Extract individual documents option (assuming the location and name of the document is known)

I hope this is of some use to you, although I would hope if you are reading this you a revisiting your backup strategy!

Disclaimer: The code provided in this blog is in no way supported by Microsoft or myself and should not be performed on production SharePoint SQL Databases. This operation should be carried out as a last resort and a backup and recovery strategy should be your method to restore data. Ensure this is performed on a test environment by using a copy of your data and discarding of the database after carrying out this operation.


Anonymous said...

Thanks very much for the script! You just saved me a ton of time in restoring a large document library that got deleted.

Post a Comment