The Way to Programming
The Way to Programming
I have this script to take a full backup, but what I need is a script to allow the same filename of the back up to be in running order without the 1st backup being deleted or written over with a timestamp for date and time.
USE AdventureWorks2012 GO -- declare the backup filename (with path) without the file extension DECLARE @DestFile varchar(255) = 'C:\FJM\btw '; -- get the current date as a nice and sortable string DECLARE @CurrentDate varchar(64) = ''; SET @CurrentDate = replace(convert(varchar(10), getdate(), 105), '/', ''); SET @DestFile += @CurrentDate + '.bak'; -- defines backup file extension name BACKUP DATABASE AdventureWorks2012 to disk = @DestFile;
You can use WITH NOFORMAT it’ll make sure whenever you hit the script new backup file will get created. Give it a try
Sign in to your account