You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
--This example will restore the latest differential backup, and stop transaction logs at the specified date time. It will also only print the commands.
@HeadersSQL ASNVARCHAR(4000) =N'', --Dynamic insert into #Headers table (deals with varying results from RESTORE FILELISTONLY across different versions)
195
-
@MoveOption ASNVARCHAR(MAX)=N'', --If you need to move restored files to a different directory
206
+
@MoveOption ASNVARCHAR(MAX) =N'', --If you need to move restored files to a different directory
207
+
@LogRecoveryOption ASNVARCHAR(MAX) =N'', --Holds the option to cause logs to be restored in standby mode or with no recovery
196
208
@DatabaseLastLSN NUMERIC(25, 0), --redo_start_lsn of the current database
197
209
@i TINYINT=1, --Maintains loop to continue logs
198
210
@LogFirstLSN NUMERIC(25, 0), --Holds first LSN in log backup headers
@@ -327,29 +339,25 @@ IF (SELECT RIGHT(@BackupPathLog, 1)) <> '\' --Has to end in a '\'
327
339
END;
328
340
329
341
/*Move Data File*/
330
-
IFNULLIF(@MoveDataDrive, '') ISNULL
331
-
BEGIN
332
-
RAISERROR('Getting default data drive for @MoveDataDrive', 0, 1) WITHNOWAIT;
333
-
SET @MoveDataDrive =CAST(SERVERPROPERTY('InstanceDefaultDataPath') ASnvarchar(260));
334
-
END;
335
342
IF (SELECTRIGHT(@MoveDataDrive, 1)) <>'\'--Has to end in a '\'
336
343
BEGIN
337
344
RAISERROR('Fixing @MoveDataDrive to add a "\"', 0, 1) WITHNOWAIT;
338
345
SET @MoveDataDrive +=N'\';
339
346
END;
340
347
341
348
/*Move Log File*/
342
-
IFNULLIF(@MoveLogDrive, '') ISNULL
343
-
BEGIN
344
-
RAISERROR('Getting default log drive for @@MoveLogDrive', 0, 1) WITHNOWAIT;
345
-
SET @MoveLogDrive =CAST(SERVERPROPERTY('InstanceDefaultLogPath') ASnvarchar(260));
346
-
END;
347
349
IF (SELECTRIGHT(@MoveLogDrive, 1)) <>'\'--Has to end in a '\'
348
350
BEGIN
349
351
RAISERROR('Fixing @MoveDataDrive to add a "\"', 0, 1) WITHNOWAIT;
350
352
SET @MoveLogDrive +=N'\';
351
353
END;
352
354
355
+
/*Standby Undo File*/
356
+
IF (SELECTRIGHT(@StandbyUndoPath, 1)) <>'\'--Has to end in a '\'
357
+
BEGIN
358
+
RAISERROR('Fixing @StandbyUndoPath to add a "\"', 0, 1) WITHNOWAIT;
RAISERROR('@ContinueLogs set to 0', 0, 1) WITHNOWAIT;
537
531
538
532
SET @sql =N'RESTORE DATABASE '+ @RestoreDatabaseName +N' FROM DISK = '''+ @BackupPathFull + @LastFullBackup +N''' WITH NORECOVERY, REPLACE'+ @MoveOption +NCHAR(13);
539
-
533
+
540
534
IF @Debug =1
541
535
BEGIN
542
536
IF @sql ISNULLPRINT'@sql is NULL for RESTORE DATABASE: @BackupPathFull, @LastFullBackup, @MoveOption';
0 commit comments