Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
backup database northwind to disk='\\backupsql\BackupFolder\northwind.bak'
go
restore database northwind from disk='d:\BackupFolder\northwind.bak' WITH STANDBY='d:\MSSQL\MSSQL\Backup\Northwind.sby'
go
backup log Northwind to disk='\\backupsql\BackupFolder\northwind.log' with NOINIT, NOSKIP, NOFORMAT
go
osql -S BackupSQL -E -Q "msdb.dbo.sp_start_job 'Restore Northwind Log'"
[color red]This code is for SQL Server 2000[/color]
[blue]This is Step 1, it's type should be T/SQL[/blue]
/*This first part of the code ensures that no one is using the database that we are about to restore. If we don't do this then the restore will fail.*/
declare @spid as varchar(10)
declare @CMD as varchar(1000)
declare cur CURSOR for select spid from master.dbo.sysprocesses where dbid =
(select dbid from sysdatabases where name = 'Northwind')
open cur
fetch next from cur into @spid
while @@FETCH_STATUS = 0
BEGIN
set @CMD = 'kill ' + @spid
exec (@CMD)
fetch next from cur into @spid
END
close cur
deallocate cur
go
[blue]This is Step 2, it's type should be Operating System Command[/blue]
del d:\RestoreFolder\Northwind.2.log
REM /*This removed the last file we processed.*/
[blue]This is Step 3, it's type should be Operating System Command[/blue]
move d:\RestoreFolder\Northwind.log d:\RestoreFolder\Northwind.2.log
REM /*This moves the current file into place for processing.*/
[blue]This is Step 4, it's type should be T/SQL[/blue]
declare @i int
declare @j int
set @j = 1
set @i = 0
restore headeronly from disk='d:\RestoreFolder\Northwind.2.log' /*This tells us how many transaction log backups there are in the file that we need to restore.*/
set @i = @@ROWCOUNT
while @i+1 > (@j) /*This loop runs us through the file restoring the logs in order.*/
BEGIN
restore log Northwind from disk='d:\RestoreFolder\Northwind.2.log'
WITH FILE = @j,
STANDBY = 'F:\MSSQL\Backup\RMDBArchive.sby' /*This keeps the database in standby mode ready for more restores.*/
set @j = @j + 1
END
[color red]This is the restore job for SQL 7[/color]
/*Before Creating the job, create this stored procedure in the master database.*/
create procedure sp_GetRestoreCount
@FileName as varchar(1000)
as
restore headeronly from disk=@FileName
go
[blue]This is Step 1, it's type should be T/SQL[/blue]
/*From here down is the code for the restore job.*/
declare @spid as varchar(10)
declare @CMD as varchar(1000)
declare cur CURSOR for select spid from master.dbo.sysprocesses where dbid =
(select dbid from sysdatabases where name = 'Northwind')
open cur
fetch next from cur into @spid
while @@FETCH_STATUS = 0
BEGIN
set @CMD = 'kill ' + @spid
exec (@CMD)
fetch next from cur into @spid
END
close cur
deallocate cur
go
[blue]This is Step 2, it's type should be Operating System Command[/blue]
del d:\RestoreFolder\Northwind.2.log
REM /*This removed the last file we processed.*/
[blue]This is Step 3, it's type should be Operating System Command[/blue]
move d:\RestoreFolder\Northwind.log d:\RestoreFolder\Northwind.2.log
REM /*This moves the current file into place for processing.*/
[blue]This is Step 4, it's type should be T/SQL[/blue]
declare @i int
declare @j int
set @j = 1
set @i = 0
create table #HeaderTable
(BackupName varchar(255), BackupDescription varchar(255), BackupType int, ExpirationDate datetime, Compressed int,
Position int, DeviceType int, UserName VarChar(255), ServerName varchar(255), DatabaseName varchar(255),
DatabaseVersion int, DatabaseCreationDate datetime, BackupSize numeric(24,0), FirstLsn numeric(24,0),
LastLsn numeric(24,0), CheckpointLsn numeric(24,0), DatabaseBackupLsn numeric(24,0), BackupStartDate datetime,
BackupFinishDate datetime, SortOrder int, CodePage int, UnicodeLocaleID int, UnicodeComparisonStyle int,
CompatibilityLevel int, SoftwareVendorID int, SoftwareVersionMajor int, SoftwareVersionMinor int,
SoftwareVersionBuild int, MachineName varchar(255))
insert into #HeaderTable
exec sp_GetRestoreCount 'd:\RestoreFolder\Northwind.2.log'
set @i = (select count(*) from #HeaderTable)
drop table #HeaderTable
select @i
while @i+1 > (@j) /*This loop runs us through the file restoring the logs in order.*/
BEGIN
restore log Northwind from disk='d:\RestoreFolder\Northwind.2.log'
WITH FILE = @j,
STANDBY = 'F:\MSSQL\Backup\RMDBArchive.sby' /*This keeps the database in standby mode ready for more restores.*/
set @j = @j + 1
END
declare @j int
set @i = 0
restore headeronly from disk='d:\RestoreFolder\Northwind.2.log' /*This tells us how many transaction log backups there are in the file that we need to restore.*/
set @i = @@ROWCOUNT
restore log Northwind from disk='d:\RestoreFolder\Northwind.2.log'
WITH FILE = @i