SQL script to backup and restore SharePoint 2010 databases

Here's a finished version of my SQL script to backup and restore SharePoint 2010 databases.

I discuss the idea in detail here:
http://www.sharepoint.name/2014/04/make-sql-server-write-its-own-scripts.html

But this is the more finished version
This script is one simple query that generates a column containing each command.


SELECT
'BACKUP DATABASE ['+ name +'] TO DISK = ''\\SERVER102\B$\SQL\FULL\'+ NAME +'.BAK '' WITH STATS=10' AS FullBackup,
'BACKUP DATABASE ['+ name +'] TO DISK = ''\\SERVER102\B$\SQL\DIFF\'+ NAME +'.BAK '' WITH DIFFERENTIAL, STATS=10' AS DiffBackup ,
'RESTORE DATABASE ['+ name +'] FROM DISK = ''\\SERVER102\B$\SQL\FULL\'+ NAME +'.BAK '' WITH NORECOVERY, REPLACE' AS FullRestore ,
'RESTORE DATABASE ['+ name +'] FROM DISK = ''\\SERVER102\B$\SQL\DIFF\'+ NAME +'.BAK '' WITH RECOVERY' AS DiffRestore from sys.databases
WHERE name not in('master', 'model', 'msdb', 'tempdb')



  1. Execute the FullBackup column on the old or current SQL server.
  2. Execute FullRestore on new SQL server.
  3. Start downtime and turn off all web front end servers.
  4. Execute DiffBackup on old SQL
  5. Execute DiffRestore on new SQL server.
  6. Turn off old SQL server.
  7. Turn on WebFrontEnd Servers
  8. Set up a SQL Alias on all servers in the farm
    See: (http://www.sharepoint.name/2014/04/how-to-set-up-sql-alias-for-ms-sql.html)
And that's all it takes to move SQL from one box to another.
 

Comments

Popular posts from this blog

Setting SharePoint announcements to auto delete after expiration

Updating a single field in a SharePoint List using Power Automate Flows

SharePoint driven rich text dashboard using jqueryui. (JQuery file)