Wednesday, 1 July 2015

TSQL copy backup & restore

EXECUTE xp_cmdshell 'copy "\\SRV-BKP2\mydb Backup\dailybackup.bak" \\SRV-SQL01\Databases\mydb'
GO


RESTORE FILELISTONLY
FROM DISK = 'D:\Databases\mydb\dailybackup.bak'
GO
ALTER DATABASE mydb
SET SINGLE_USER WITH
ROLLBACK IMMEDIATE
GO
RESTORE DATABASE mydb
FROM DISK = 'D:\Databases\mydb\dailybackup.bak'
GO

ALTER DATABASE mydb SET MULTI_USER