Tail backup time stamp

  • Hi,

    I'm taking the Tail backup using the below script and the .trn file is creating with Mydb_tail.trn. But I want the date-time stamp for .trn file. Could you please tell me what change I need to do or Is there any good script to take tail backp?

    BACKUP LOG [Mydb] TO DISK = N'C:\Taillog_backup\Mydb_Tail.trn'

    WITH NO_TRUNCATE , NOFORMAT, NOINIT, NAME = N'Mydb-Transaction Log Backup',

    SKIP, NOREWIND, NOUNLOAD, NORECOVERY , STATS = 10

    GO

    declare @backupSetId as int

    select @backupSetId = position from msdb..backupset where database_name=N'Mydb'

    and backup_set_id=(select max(backup_set_id) from msdb..backupset where database_name=N'Mydb' )

    if @backupSetId is null begin raiserror(N'Verify failed. Backup information for database ''Mydb'' not found.', 16, 1) end

    RESTORE VERIFYONLY FROM DISK = N'C:\Taillog_backup\Mydb_Tail.trn'

    WITH FILE = @backupSetId, NOUNLOAD, NOREWIND

    GO

    thanks

  • I'm not sure what you are asking. Do you want to find the time you took the tail log backup or do you want to add a timestamp to the name of the tail log backup?

  • thanks,

    I'm not sure what you are asking. Do you want to find the time you took the tail log backup or do you want to add a timestamp to the name of the tail log backup?

    I want to add a timestamp to the name of the tail log backup so that I know at what time the tail backup is done.

    thanks so much

  • You need to do something like:

    DECLARE @path NVARCHAR(MAX),

    @filename NVARCHAR(MAX);

    SET @path = N'C:\Taillog_backup\'

    Set @filename = N'Mydb_Tail_' + REPLACE(REPLACE(REPLACE((CONVERT(nvarchar, GETDATE(), 120)), '-', ''), ' ', '_'), ':', '') + N'.trn'

    SET @path = @path + @filename

    BACKUP LOG [Mydb] TO DISK = @path

    WITH NO_TRUNCATE , NOFORMAT, NOINIT, NAME = N'Mydb-Transaction Log Backup',

    SKIP, NOREWIND, NOUNLOAD, NORECOVERY , STATS = 10

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply