Tuesday, 27 May 2008

Recover a deleted site collection from SQL Backup

Solution from Mauro Cardarelli's blog: http://blogs.officezealot.com/mauro/archive/2007/12/12/20674.aspx

In this scenario, let's assume that you have NOT been doing site collection backups but you do have SQL backups. You notice that last night's content database backup is considerably smaller than the night before (yes, you have been saving multiple days of backups). Phew! Your data is all there; we just need to reconnect it. Here's how:
1. Create a new database and restore (through SQL Server) the last good database into it
2. At the command prompt, use stsadm command to add the content database to your site
stsadm.exe -o addcontentdb -url -databasename -databaseserver
3. Run an IISRESET
4. Go to Central Administration and look at the list of content databases for your web application (under Application Management). There should be two (the old one - with zero sites - and the new one just attached). Delete the old database.
5. Done! Go to your URL... all should be good again.