Skip to content

Instantly share code, notes, and snippets.

@jiimaho
Last active March 15, 2017 07:58
Show Gist options
  • Save jiimaho/3aa25944b576edab097ce9bdf223729e to your computer and use it in GitHub Desktop.
Save jiimaho/3aa25944b576edab097ce9bdf223729e to your computer and use it in GitHub Desktop.
SQL Server restore database from network drive to external disk
-- allow changes to advanced options
EXEC sp_configure 'show advanced options', 1
GO
-- Update currently configured values for advanced options.
RECONFIGURE
GO
-- To enable xp_cmdshell
EXEC sp_configure 'xp_cmdshell', 1
GO
-- Update currently configured values for advanced options.
RECONFIGURE
GO
EXEC xp_cmdshell 'NET USE G: \\network\path password /USER:domain\usrname'
USE [master]
RESTORE DATABASE [Name] FROM DISK = N'G:\name.bak' WITH FILE = 1, MOVE N'Name_Data' TO N'D:\Folder\Name.MDF', MOVE N'Name_Log' TO N'D:\Folder\Name_log.LDF', NORECOVERY, NOUNLOAD, STATS = 5
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment