March 7, 2005 at 2:26 pm
We are writing queries to determine if a transaction log was truncated since the last backup. We have found a way to do this with the first and last lsn's.
BUT!! Does anyone know if an entry is created in any database acknowledging that the transaction log was backed up with a TRUNCATE_ONLY command?
Thanks Everyone!!
"Keep Your Stick On the Ice" ..Red Green
March 8, 2005 at 1:11 am
I guess not. Maybe it only comes available if the log is rolledover
I've tested this small sample, and the restore to the new db workd without a warning
So If there were any registration, the last log-restore should fail !
--
create database DTEST
go
BACKUP DATABASE DTEST
TO disk='c:\dtestfull.bak'
WITH INIT
go
use dtest
go
create table dbo.tttt(col1 int not null)
go
insert into dbo.tttt values(1)
go
backup log DTEST
TO disk='c:\dtestLog.bak'
WITH INIT
insert into dbo.tttt
select max(col1) + 1 from dbo.tttt
go
insert into dbo.tttt
select max(col1) + 1 from dbo.tttt
go
insert into dbo.tttt
select max(col1) + 1 from dbo.tttt
go
backup log DTEST
TO disk='c:\dtestLog.bak'
WITH NOINIT
-- --
-- -- The CREATE DATABASE process is allocating 0.63 MB on disk 'DTEST'.
-- -- The CREATE DATABASE process is allocating 0.49 MB on disk 'DTEST_log'.
-- -- Processed 80 pages for database 'DTEST', file 'DTEST' on file 1.
-- -- Processed 1 pages for database 'DTEST', file 'DTEST_log' on file 1.
-- -- BACKUP DATABASE successfully processed 81 pages in 0.057 seconds (11.515 MB/sec).
-- --
-- -- (1 row(s) affected)
-- --
-- -- Processed 1 pages for database 'DTEST', file 'DTEST_log' on file 1.
-- -- BACKUP LOG successfully processed 1 pages in 0.030 seconds (0.221 MB/sec).
-- --
-- -- (1 row(s) affected)
-- --
-- --
-- -- (1 row(s) affected)
-- --
-- --
-- -- (1 row(s) affected)
-- --
-- -- Processed 1 pages for database 'DTEST', file 'DTEST_log' on file 2.
-- -- BACKUP LOG successfully processed 1 pages in 0.030 seconds (0.051 MB/sec).
insert into dbo.tttt
select max(col1) + 1 from dbo.tttt
go
insert into dbo.tttt
select max(col1) + 1 from dbo.tttt
go
insert into dbo.tttt
select max(col1) + 1 from dbo.tttt
go
BACKUP LOG ddbastatistics WITH truncate_only
go
insert into dbo.tttt
select max(col1) + 1 from dbo.tttt
go
insert into dbo.tttt
select max(col1) + 1 from dbo.tttt
go
insert into dbo.tttt
select max(col1) + 1 from dbo.tttt
go
backup log DTEST
TO disk='c:\dtestLog.bak'
WITH NOINIT
go
select max(col1) as max_col1, count(*) as No_Rows from dbo.tttt
use master
go
declare @Logbackup_Filename varchar(500)
declare @Restore_New_DBname varchar(128)
select @Logbackup_Filename = 'c:\dtestLog.bak'
, @Restore_New_DBname = 'DTEST1'
declare @RestoreDb_stmt varchar(5000)
select @RestoreDb_stmt = 'restore database ' + @Restore_New_DBname + '
FROM DISK = ''c:\dtestfull.bak''
WITH MOVE N''DTEST'' TO N''U:\yourpath\Data\' + @Restore_New_DBname + '.mdf''
, MOVE N''DTEST_log'' TO N''S:\yourpath\Log\' + @Restore_New_DBname + '_log.LDF''
, replace
, NoRecovery '
exec (@RestoreDb_stmt)
if (select isnull( object_id(N'tempdb.[dbo].[#Tmp_BackupHeaders]'), 0)) <> 0
begin
DROP table #Tmp_BackupHeaders
end
-- versie SQL2K sp3a
create table #Tmp_BackupHeaders (
BackupName nvarchar(128)
,BackupDescription nvarchar(255)
,BackupType smallint
,ExpirationDate datetime
,Compressed tinyint
,Position smallint
,DeviceType tinyint
,UserName nvarchar(128)
,ServerName nvarchar(128)
,DatabaseName nvarchar(128)
,DatabaseVersion int
,DatabaseCreationDate datetime
,BackupSize numeric(20,0)
,FirstLSN numeric(25,0)
,LastLSN numeric(25,0)
,CheckpointLSN numeric(25,0)
,DatabaseBackupLSN numeric(25,0)
,BackupStartDate datetime
,BackupFinishDate datetime
,SortOrder smallint
,CodePage smallint
,UnicodeLocaleId int
, UnicodeComparisonStyle int
, CompatibilityLevel tinyint
, SoftwareVendorId int
,SoftwareVersionMajor int
,SoftwareVersionMinor int
,SoftwareVersionBuild int
,MachineName nvarchar(128)
,Flags int
,BindingID uniqueidentifier
,RecoveryForkID uniqueidentifier
,Collation nvarchar(128)
)
declare @sql varchar(5000)
set @sql = 'RESTORE HEADERONLY FROM DISK = ''' + @Logbackup_Filename + ''' '
insert into #Tmp_BackupHeaders
exec (@SQL)
declare csrRestoreLog cursor for
select 'print ''-- db [' + convert(varchar(128),DatabaseName) + '] -- ' + convert(varchar(15), Position)
+ ' -- LSN ' + convert(varchar(128), FirstLSN ) + ' <-> ' + convert(varchar(128), LastLSN )
+ ' -- BackupDate ' + convert(varchar(25), BackupStartDate, 121) + ' <--> ' + convert(varchar(25), BackupFinishDate, 121)
+ ' ''' + char(13)
+ 'Restore Log ' + @Restore_New_DBname + '
FROM DISK = ''' + @Logbackup_Filename + '''
WITH FILE = ' + convert(varchar(15),Position) + char(13)
+ case Position when M.MAX_Position then ' , Recovery '
else ' , NoRecovery '
end
-- + char(13) + 'GO'
from #Tmp_BackupHeaders
, (select max(Position) as MAX_Position from #Tmp_BackupHeaders ) M
order by Position
declare @RestoreLog_stmt varchar(5000)
open csrRestoreLog
FETCH NEXT FROM csrRestoreLog
INTO @RestoreLog_stmt
WHILE @@FETCH_STATUS = 0
BEGIN
exec (@RestoreLog_stmt)
-- Volgende rij inlezen
FETCH NEXT FROM csrRestoreLog
INTO @RestoreLog_stmt
END
-- Cursor afsluiten
CLOSE csrRestoreLog
DEALLOCATE csrRestoreLog
go
select max(col1) as max_col1, count(*) as No_Rows from DTEST1.dbo.tttt
go
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
March 8, 2005 at 7:58 am
Not what I expected. Very interesting to say the least. I wonder if throwing a CHECKPOINT at the database before the truncate would have effected the restore..Something doesn't seem right
Looks like I am going to play (test) today too. Now my curiousity is going!!
"Keep Your Stick On the Ice" ..Red Green
March 8, 2005 at 11:06 am
Alert 18278 fires when log gets truncated. You can configure this.
May 16, 2005 at 11:17 am
Hi everybody,
I found this thread kind of late, but is only now that I've got the problem! I configured an alert on 18278 to net send a message when the transaction log is truncated for <mydb>. The alerts is active, the operator to be notified is OK (receives notifications from other alerts and the test is sending the message).
Then I issued:
backup log mydb with truncate_only
I was expecting to see the pop-up window sent when the alert was fired, but nothing happened. I can see in SS2K error log that the log for that database was truncated but the alert didn't fire (Count shows 0 in the EM).
Can anybody help with an explanation?
Thanks,
Gabriela
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply