SQL Server Automatic backup script

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.