SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Transaction Log backup filename help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

dbaman
Starting Member

USA
46 Posts

Posted - 01/28/2010 :  08:49:45  Show Profile  Reply with Quote
I am running this T-SQL to take Transaction log backup...

BACKUP LOG [PUBN] TO DISK = N'M:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\PUBN_DAILY_TRAN.bak' WITH NOFORMAT, INIT, NAME = N'PUBN-Transaction Log Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO
declare @backupSetId as int
select @backupSetId = position from msdb..backupset where database_name=N'PUBN' and backup_set_id=(select max(backup_set_id) from msdb..backupset where database_name=N'PUBN' )
if @backupSetId is null begin raiserror(N'Verify failed. Backup information for database ''PUBN'' not found.', 16, 1) end
RESTORE VERIFYONLY FROM DISK = N'M:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\PUBN_DAILY_TRAN.bak' WITH FILE = @backupSetId, NOUNLOAD, NOREWIND
GO

My question is instead of "PUBN_DAILY_TRAN.bak" as filename for the backup how can I make it Todaydate_PUBN_DAILY_TRAN.bak so everyday I get PUBN_DAILY_TRAN.bak appended with todaysdate?

For example when I run today I should get file name: 01282010_PUBN_DAILY_TRAN.bak

Thanks

R

Kristen
Test

United Kingdom
22431 Posts

Posted - 01/28/2010 :  09:06:17  Show Profile  Reply with Quote
This is what I use

DECLARE @strFileName varchar(4000)
SELECT	@strFileName = 'M:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\'
		+ db_name()
		+ '_'
		+ CONVERT(varchar(8), GetDate(), 112)	-- yyyymmdd
		+ '_'
		+ REPLACE(LEFT(CONVERT(varchar(8), GetDate(), 108), 5), ':', '')	-- hh:mm:ss
		+ '_'
		+ 'Tran'	-- Type - TLog, Full, Diff etc.
		+ '.BAK' 

BACKUP LOG [PUBN] 
	TO DISK = @strFileName
	WITH
		NAME = N'PUBN-Transaction Log Backup',
		STATS = 10

Don't think you need any other options. You could change NAME to use an @Parameter too, and include the Date/Time alongside the description.

"... so everyday I get ..."

You ought to be taking a TLog backup much more frequently than once a day - every 15 minutes would be a good interval ...
Go to Top of Page

dbaman
Starting Member

USA
46 Posts

Posted - 01/28/2010 :  15:21:30  Show Profile  Reply with Quote
Thanks Kristen. That's what I am looking for.

R
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000