Add updated SqlAgent folder

This commit is contained in:
Neeraj Kumar
2025-11-02 14:50:48 -05:00
parent 2c94b89801
commit 8fca292a50
141 changed files with 6723 additions and 0 deletions

View File

@ -0,0 +1,31 @@
USE master;
GO
DECLARE @SrcDB NVARCHAR(128) = 'DevlDUTASJobSchedule'; -- original database
DECLARE @NewDB NVARCHAR(128) = 'DevlDUTASJobSchedule'; -- database name to restore as
DECLARE @BackupPath NVARCHAR(260) = '\\DOES-RAINVM-TST\E$\Neeraj\SqlAgent\Backup\' + @SrcDB + '.bak';
DECLARE @SQL NVARCHAR(MAX);
-- Optional: check logical file names inside backup
-- RESTORE FILELISTONLY FROM DISK = @BackupPath;
-- Dynamic SQL for restore
SET @SQL = '
-- Optional: disconnect active connections
ALTER DATABASE [' + @NewDB + '] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
RESTORE DATABASE [' + @NewDB + ']
FROM DISK = N''' + @BackupPath + '''
WITH MOVE N''' + @SrcDB + ''' TO N''\\DOES-RAINVM-TST\E$\SQLData\' + @NewDB + '.mdf'',
MOVE N''' + @SrcDB + '_log'' TO N''\\DOES-RAINVM-TST\E$\SQLLogs\' + @NewDB + '_log.ldf'',
REPLACE, STATS = 10;
-- Set database back to multi-user
ALTER DATABASE [' + @NewDB + '] SET MULTI_USER;
';
-- Execute restore
EXEC(@SQL);
PRINT 'Database restored successfully as ' + @NewDB;
GO