• SQL 2012 backup script help

    Abhey Member

    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;
    
  • SapnaVishwas Member

    You can use WITH NOFORMAT it’ll make sure whenever you hit the script new backup file will get created. Give it a try

Viewing 1 reply thread
  • You must be logged in to reply to this topic.
en_USEnglish