SQL Server Performance Forum – Threads Archive
backup script w/ variableDoes anyone have a backup script that uses the date/time in the file name? I’m looking for something that uses something like getdate() as a variable so that the file name of the backup always has the date and time the backup occurred and is unique.
I’ve come up with this. But, there may be a simpler way than this. declare @sqlstring varchar(1024)
declare @date varchar(50) set @date = replace(replace(replace(replace(replace(convert(varchar(50),getdate(),21),’-‘,”),’-‘,”),’:’,”),’.’,”),’ ‘,”) set @sqlstring = (‘backup database dbname to disk = ”d: empdbname’[email protected]+’.bak”’) exec (@sqlstring)
[email protected] When life gives you a lemon, fire the DBA.