SQL Server Backup script:
Script Wednesday full backup, other time differential backup.
declare @device varchar (;d eclare @filename varchar;d eclare @datetime varchar;d eclare @weekname varchar (;d eclare @weeknametmp varchar (4);d eclare @ weekday int;set @weekname =datename (Weekday,getdate ());set @datetime = convert ( varchar (), GETDATE (),;set @device = ' Rapoooa ' + @datetime;set @filename = ' d:\ Sqlbackup\rapoooa ' [email protected]+ '. Bak ';set @weeknametmp =substring (@weekname, 3,1);if (@ weeknametmp= ' one ') set @ weekday=1;else if (@weeknametmp = ' two ') set @weekday =2;else if (@weeknametmp = ' three ') set @weekday =3;else if (@ weeknametmp= ' four ') set @weekday =4;else if ( @weeknametmp = ' five ') set @weekday =5;else if (@weeknametmp = ' six ') set @weekday =6;else if (@weeknametmp = ' Day ') set @weekday = 0; set @datetime = convert (varchar), GETDATE () [email protected],112];set @device = ' Rapoooa ' + @datetime;set @filename = ' D:\SQLBackup\RapooOA ' [email protected]+ '. Bak ' if (@weekname = ' Wednesday ') begin execute sp_addumpdevice ' disk ', @device, @filename; backup database rapoooa to @device endelse begin backup database RapooOA to @device with differential End
Save the file in. sql format, and use scheduled tasks to execute on time.
If the following error occurs: Just exec sp_dropdevice RapooOA20160117 can be removed and then rerun.
Msg 15026, Level 16, State 1, procedure sp_addumpdevice, line 74th
Logical device ' RapooOA20160117 ' already exists.
Reference:
http://zhanjianhua.iteye.com/blog/1002860
http://bbs.csdn.net/topics/300066983
This article is from the "Mama Sister" blog, please make sure to keep this source http://smallc.blog.51cto.com/926344/1736917
SQL Server Automatic backup script