Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Adding date and time to backup file???

Author  Topic 

parallon
Starting Member

25 Posts

Posted - 2006-10-30 : 15:54:48
Hello all. I was just wondering how I could add the current date and time to the name of the .bak file. I perform a full backup daily and would like to keep a weeks worth of backups, but everytime I run the job, it just overites the previous one.

The command in the wizzard is:

BACKUP DATABASE [snl] TO  DISK = N'C:\Backups_for_FTP\SNL_Full.bak' WITH  NOINIT ,  NOUNLOAD ,  NAME = N'snl backup',  SKIP ,  STATS = 10,  DESCRIPTION = N'SNL Backup',  NOFORMAT


Thanks,

Parallon

robvolk
Most Valuable Yak

15732 Posts

Posted - 2006-10-30 : 15:58:13
DECLARE @filename nvarchar(128)
SET @filename=N'C:\Backups_for_FTP\SNL_Full' + convert(varchar(8), getdate(), 112) + '_' + replace(convert(varchar(8), getdate(), 108), ':', '') + '.bak'
BACKUP DATABASE [snl] TO DISK = @filename WITH NOINIT , NOUNLOAD , NAME = N'snl backup', SKIP , STATS = 10, DESCRIPTION = N'SNL Backup', NOFORMAT
Go to Top of Page

parallon
Starting Member

25 Posts

Posted - 2006-10-30 : 17:22:55
Thank you so much. That worked perfectly...

Parallon
Go to Top of Page
   

- Advertisement -