-- Full backup -- Note: Everything starts from full backup. Declare @ Path varchar (1000 ), @ Filename varchar (1000 ), @ Weekday varchar (20)
Set @ weekday = case datepart (weekday, getdate ()) When 1 then 'sunday' When 2 then 'monday' When 3 then 'tues' When 4 then 'weday' When 5 then 'thursday' When 6 then 'Friday' When 7 then 'satur' endset @ Path = 'd: \ backdata \' Set @ filename = @ path + @ weekday + 'full backup. Bak'
Backup database [testdb] To disk = @ filename with init , Nounload , Name = n' testdb full backup' , Noskip , Stats = 10 , Noformat -- Differential backup -- Note: Before performing differential backup, you must perform a successful full backup of the database. Declare @ Path varchar (1000 ), @ Weekday varchar (20 ), @ Filename varchar (1000 ), @ Hour varchar (4)
Set @ weekday = case datepart (weekday, getdate ()) When 1 then 'sunday' When 2 then 'monday' When 3 then 'tues' When 4 then 'weday' When 5 then 'thursday' When 6 then 'Friday' When 7 then 'satur' end
Set @ Path = 'd: \ backdata \' Set @ hour = convert (varchar (2), datepart (hour, getdate () + 'point' Set @ filename = @ path + @ weekday + @ hour + 'differential backup. Bak'
Backup database [testdb] To disk = @ filename with init , Nounload , Differential , Name = n' testdb differential backup' , Noskip , Stats = 10 , Noformat -- log backup -- Note: a successful full database backup must be performed before log backup. Declare @ Path varchar (1000 ), @ Weekday varchar (20 ), @ Filename varchar (1000 ), @ Hour varchar (4)
Set @ weekday = case datepart (weekday, getdate ()) When 1 then 'sunday' When 2 then 'monday' When 3 then 'tues' When 4 then 'weday' When 5 then 'thursday' When 6 then 'Friday' When 7 then 'satur' end
Set @ Path = 'd: \ backdata \' Set @ hour = convert (varchar (2), datepart (hour, getdate () + 'point' Set @ filename = @ path + @ weekday + @ hour + 'Log backup. Bak'
Backup log [testdb] To disk = @ filename with init , Nounload , Name = n' testdb log backup' , Noskip , Stats = 10 , Noformat |