Author |
Topic |
AdrenalineSeed
Starting Member
16 Posts |
Posted - 2008-05-29 : 16:58:59
|
So I have all these transaction log backups appended to a .bak file. I want to restore the database to its last log backup time but it is only allowing me to restore one at a time. I am not able to check all of them. Also each time it restores one it closes the window and all of my settings.I can't do this a thousand times for each log backup appended... I need to be able to restore all the log files in the .bak file in order with one click. What am I missing?  |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-05-29 : 17:08:37
|
In Enterprise Manager in the restore wizard screen, just select the full backup from the first backup to restore dropdown, it'll have all of the tlog backups checked.And yes once it is done restoring whatever you've selected, it'll close the window. There's no way to avoid that.It would be fairly easy to script this though if you hadn't appended the files and instead backed up to individual files with the timestamp in the file names.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx |
 |
|
AdrenalineSeed
Starting Member
16 Posts |
Posted - 2008-05-29 : 17:13:11
|
Hi tkizer,That drop down is blank. I am not working with the original database, it is up-to-date.I am trying to update my copy of the database restored from a backup made in the past. It has a different name, resides on a different server. |
 |
|
Haywood
Posting Yak Master
221 Posts |
Posted - 2008-05-29 : 17:13:30
|
quote: Originally posted by tkizerIt would be fairly easy to script this though if you hadn't appended the files and instead backed up to individual files with the timestamp in the file names.
It's still fairly easy to iterate through the single file using the "Position" value in an incremental loop... |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-05-29 : 17:16:29
|
quote: Originally posted by AdrenalineSeed Hi tkizer,That drop down is blank. I am not working with the original database, it is up-to-date.I am trying to update my copy of the database restored from a backup made in the past. It has a different name, resides on a different server.
You'll need to script it then. How many backups are in the appended file?Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-05-29 : 17:17:14
|
quote: Originally posted by Haywood
quote: Originally posted by tkizerIt would be fairly easy to script this though if you hadn't appended the files and instead backed up to individual files with the timestamp in the file names.
It's still fairly easy to iterate through the single file using the "Position" value in an incremental loop...
Yep but I don't have a handy script for that since I don't append backups ever.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx |
 |
|
AdrenalineSeed
Starting Member
16 Posts |
Posted - 2008-05-29 : 17:19:29
|
Well I have over 100 databases I am trying to do this with, and it depends on the number of days since the last full backup was taken. So it can be alot! But I have a test one here with just 4 appended backups I can practice with.quote: Originally posted by tkizer
quote: Originally posted by AdrenalineSeed Hi tkizer,That drop down is blank. I am not working with the original database, it is up-to-date.I am trying to update my copy of the database restored from a backup made in the past. It has a different name, resides on a different server.
You'll need to script it then. How many backups are in the appended file?Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
|
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-05-29 : 17:23:42
|
Are the backups in the correct order in the appended file, meaning the full backup is first, the first log backup is second, the second log backup is third, ...?Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx |
 |
|
Haywood
Posting Yak Master
221 Posts |
Posted - 2008-05-29 : 17:24:38
|
quote: Originally posted by tkizer
quote: Originally posted by Haywood
quote: Originally posted by tkizerIt would be fairly easy to script this though if you hadn't appended the files and instead backed up to individual files with the timestamp in the file names.
It's still fairly easy to iterate through the single file using the "Position" value in an incremental loop...
Yep but I don't have a handy script for that since I don't append backups ever.
I might have something handy...give me a minute to dig it up... |
 |
|
AdrenalineSeed
Starting Member
16 Posts |
Posted - 2008-05-29 : 17:28:19
|
Oh... The Full backup of the database was made in its own .bak file, then the log files were put into a log.bak file and appended from there on out.quote: Originally posted by tkizer Are the backups in the correct order in the appended file, meaning the full backup is first, the first log backup is second, the second log backup is third, ...?Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
|
 |
|
Haywood
Posting Yak Master
221 Posts |
Posted - 2008-05-29 : 17:30:08
|
Restore your database first with NORECOVERY and then use the following as a template for restoring your logs...---- G. Rayburn ---- 6/14/2004-------- 1: Restore DB from backup WITH NORECOVERY-- 2: Restore t-logs from @iMin & @iMax File # (Internal backup sequence)------ RESTORE HEADERONLY FROM <Database Log Device> -- You want the Position values for the first & last logs to restore.--DECLARE @szDBName VARCHAR(50), @szDBLogDevice VARCHAR(50), @iCnt INT, @iMinPosition INT, @iMaxPosition INTSELECT @szDBName = 'YourDBName', @szDBLogDevice = 'YourDB_Log_Backup_Device', @iCnt = @iMinPosition, @iMinPosition = X, -- 1 @iMaxPosition = XX -- 999WHILE @iCnt < @iMaxPosition BEGIN PRINT '' PRINT 'Restoring t-log file #' + CONVERT(CHAR(3),@iCnt) + 'at ' + CONVERT(VARCHAR(26),GETDATE(),109) + '.' PRINT '' RESTORE LOG @szDBName FROM @szDBLogDevice WITH FILE = @iCnt, NORECOVERY SET @iCnt = @iCnt + 1 IF @iCnt = @iMaxPosition BEGIN PRINT '' PRINT 'Restoring last file and bringing database online at ' + CONVERT(VARCHAR(26),GETDATE(),109) + '.' PRINT '' RESTORE LOG @szDBName FROM @szDBLogDevice WITH FILE = @iMaxPosition, RECOVERY BREAK END ELSE CONTINUE END |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-05-29 : 17:31:23
|
Here's what I wrote up real quick. I wrote this for SQL Server 2005. If it doesn't work for 2000, then you'll need to change the #filelistonly structure to match the output of RESTORE FILELISTONLY in 2000. SQL Server Books Online would have the details.create table #filelistonly(logicalname nvarchar(128), physicalname nvarchar(260), type char(1), filegroupname nvarchar(128),size numeric(20,0), maxsize numeric(20,0), fileid bigint, createlsn numeric(25,0), droplsn numeric(25,0), uniqueid uniqueidentifier, readonlylsn numeric(25,0), readwritelsn numeric(25,0), backupsizeinbytes bigint, sourceblocksize int, filegroupid int, loggroupguid uniqueidentifier,differentialbaselsn numeric(25,0), differentialbaseguid uniqueidentifier, isreadonly bit, ispresent bit)insert into #filelistonlyexec ('restore filelistonly from disk =''E:\AppendFile.bak''')select 'restore database blah from disk = ''E:\blah.bak'' with norecovery'union allselect 'restore log blah from disk = ''E:\AppendFile.bak''' + ' with norecovery, file = ' + convert(varchar(20), fileid)from #filelistonlyorder by fileiddrop table #filelistonly Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx |
 |
|
AdrenalineSeed
Starting Member
16 Posts |
Posted - 2008-05-29 : 17:39:26
|
quote: Originally posted by tkizer Here's what I wrote up real quick. I wrote this for SQL Server 2005. If it doesn't work for 2000, then you'll need to change the #filelistonly structure to match the output of RESTORE FILELISTONLY in 2000. SQL Server Books Online would have the details.create table #filelistonly(logicalname nvarchar(128), physicalname nvarchar(260), type char(1), filegroupname nvarchar(128),size numeric(20,0), maxsize numeric(20,0), fileid bigint, createlsn numeric(25,0), droplsn numeric(25,0), uniqueid uniqueidentifier, readonlylsn numeric(25,0), readwritelsn numeric(25,0), backupsizeinbytes bigint, sourceblocksize int, filegroupid int, loggroupguid uniqueidentifier,differentialbaselsn numeric(25,0), differentialbaseguid uniqueidentifier, isreadonly bit, ispresent bit)insert into #filelistonlyexec ('restore filelistonly from disk =''E:\AppendFile.bak''')select 'restore database blah from disk = ''E:\blah.bak'' with norecovery'union allselect 'restore log blah from disk = ''E:\AppendFile.bak''' + ' with norecovery, file = ' + convert(varchar(20), fileid)from #filelistonlydrop table #filelistonly Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Great! I am familiar with the different filelistonly fields in 2000 and 2005 and can change that. Will this restore all the appended log backups without the need to know the starting and ending postition?? |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-05-29 : 17:41:45
|
It will just script out the commands that you'll need to run. In the last restore command, make sure to switch to with recovery. I could have coded for that, but it is easy enough to manually change. There should probably be a "order by fileid" added to the code to assure you get them in the correct order. I'm going to modify my post to reflect that.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx |
 |
|
AdrenalineSeed
Starting Member
16 Posts |
Posted - 2008-05-29 : 17:48:11
|
I get the error Invalid column name 'fileid'.from the part (varchar(20), fileid) |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-05-29 : 17:52:28
|
Could you post what you tried so that I can see the temp table definition?Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx |
 |
|
AdrenalineSeed
Starting Member
16 Posts |
Posted - 2008-05-29 : 17:53:58
|
create table #filelistonly(logicalname nvarchar(128), physicalname nvarchar(260), type char(1), filegroupname nvarchar(128),size numeric(20,0), maxsize numeric(20,0))insert into #filelistonlyexec ('restore filelistonly from disk =''d:\test.bak''')select 'restore log blah from disk = ''d:\test.bak''' + ' with norecovery, file = ' + convert(varchar(20), fileid)from #filelistonlydrop table #filelistonly |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-05-29 : 17:57:28
|
Dang, the 2000 result set from RESTORE FILELISTONLY doesn't have fileid which I need to determine the order! Maybe this'll work with an identity column instead. Let me see if I can get a 2000 system to test on. In the meantime, does Haywood's solution work?Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx |
 |
|
AdrenalineSeed
Starting Member
16 Posts |
Posted - 2008-05-29 : 18:02:01
|
I don't understand how to get the Positions his script needs. I can install a sql2005 instance and use that for restoring these databases if it will work better.Also here is the script I use to restore full backups right now if it is of any help:CREATE TABLE ##Restore (LogicalName nvarchar(128), PhysicalName nvarchar(260), Type char(1), FileGroupName nvarchar(128), SizeB numeric(20, 0), MaxSizeB numeric(20, 0))INSERT INTO ##RestoreEXEC('RESTORE FILELISTONLY FROM DISK = ''%file%''')DECLARE @LogicalNameData nvarchar(128), @LogicalNameLog nvarchar(128)SELECT @LogicalNameData = LogicalNameFROM ##RestoreWHERE Type = 'D'SELECT @LogicalNameLog = LogicalNameFROM ##RestoreWHERE Type = 'L'DECLARE @SQL nvarchar(4000)SET @SQL = 'RESTORE DATABASE %name% FROM DISK = ''%file%'' WITH MOVE '''SET @SQL = @SQL + @LogicalNameData + ''' TO ''C:\Program Files\Microsoft SQL Server\MSSQL\DATA\%name%_Data.MDF'', MOVE ''' + @LogicalNameLog + ''' TO 'SET @SQL = @SQL + '''C:\Program Files\Microsoft SQL Server\MSSQL\DATA\%name%_Log.LDF'''EXEC(@SQL)DROP TABLE ##Restore |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-05-29 : 18:04:43
|
Nevermind the RESTORE FILELISTONLY doesn't contain what I need in 2000. We'll need to use RESTORE HEADERONLY, but I'm too lazy to write the create table statement. Use my code as a template for your script. You'll want to use the position column where I've got fileid. Haywood's solution might be easier to just use as is since it looks like it does what you need, although I'd prefer a script that generated the code rather than ran it since I like to have more control with restores.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx |
 |
|
Haywood
Posting Yak Master
221 Posts |
Posted - 2008-05-29 : 18:04:54
|
quote: Originally posted by AdrenalineSeed I don't understand how to get the Positions his script needs.
RESTORE HEADERONLY will return a resultset containing the backups. You want the first "Position" that has your log backup that occured after the full backup. You also want the last "Postion" that represents your last log you want to restore before bringing the database online.RESTORE HEADERONLY FROM DISK = 'C:\My_Log_Backup.BAK' |
 |
|
Next Page
|