Monday, July 15, 2013

Backup File Format

DECLARE @Date VARCHAR(20)
DECLARE @Name VARCHAR(256)
DECLARE @File varchar(256)
DECLARE @Test varchar(256)

SET @Date = GETDATE()
SET @Name = 'FullBackup'
set @Test = 'D:\'
SELECT @Date = CONVERT(VARCHAR(20),GETDATE(),112)+ '_'+
      REPLACE(CONVERT(VARCHAR(20),GETDATE(),108),':','')
SET  @File = @Test + DB_NAME() + '_'+ @Name + '_'+ @Date + '.BAK'

BACKUP DATABASE Testing TO DISK = @File WITH STATS, COMPRESSION, CHECKSUM;


No comments: