Dynamic Backup File in SQL

insert into TableMaster values(1,cast(getdate() as char(10)))

select * from TableMaster

USE MASTER;
DECLARE  @FileName NVARCHAR(1024)
SET @FileName = 'C:\backups\fullTest_' + REPLACE(REPLACE(CONVERT(VARCHAR(100),GETDATE(),111),'/','_'), ' ','_') + '.BAK'

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

BACKUP DATABASE demostart TO  DISK = @FileName WITH NOFORMAT,
INIT

--Differential backup
USE MASTER;
DECLARE  @FileName NVARCHAR(1024)
SET @FileName = 'C:\backups\fullTest_' + REPLACE(REPLACE(CONVERT(VARCHAR(100),GETDATE(),121),'-','_'), ' ','_') + '.BAK'

SET @FileName = REPLACE(@FileName,'__','_')
--print @FileNAme
BACKUP DATABASE demostart TO  DISK = @FileName WITH NOFORMAT,
INIT
Dynamic Backup File in SQL Reviewed by Rupesh on 21:11 Rating: 5

No comments:

All Rights Reserved by Technology from Developers Eye © 2014 - 2015
Powered By Blogger, Designed by Aadics
Disclaimers:: The information provided within this blogsite is for general informational purposes only. While we try to keep the information up-to-date and correct, there are no representations or warranties, express or implied, about the completeness, accuracy, reliability, suitability or availability with respect to the information, products, services, or related graphics contained in this blogsite for any purpose.The author does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause.

Contact Form

Name

Email *

Message *

Powered by Blogger.