Microsoft SQL Server 2008
Administration Best Practices

How to backup database with datetimestamp in file name?

 

Execute the following script to demonstrate the backup of AdventureWorks2008 database with the datetimestamp in the backup file name.

USE master;

 

DECLARE @FileName NVARCHAR(1024)

SET @FileName = 'F:\data\AdventureWorks2008\backup\AW2008'+REPLACE(REPLACE(CONVERT(varchar(100), GETDATE(), 100),':','_'),' ','_')+'.BAK'

SET @FileName = REPLACE(@FileName,'__','_')

PRINT @FileName

BACKUP DATABASE AdventureWorks2008 TO  DISK = @FileName WITH NOFORMAT, INIT,  NAME = N'AdventureWorks2008-Full Database Backup'

GO

 

 

The Best SQL Server Training in the World
 
 
SQLUSA.com Home Page