SQL Backup differential

Source: Internet
Author: User

 

1 SET NOCOUNT ON
2 DECLARE @ t table (id int IDENTITY, n sysname)
3 DECLARE @ I int
4 DECLARE @ n sysname
5 DECLARE @ SQL Nvarchar (4000)
6 DECLARE @ cmd varchar (8000)
7
8 insert into @ t (n)
9 SELECT name FROM dbo. sysdatabases
10 WHERE name not in ('master', 'model', 'msdb', 'northwind ', 'pubs', 'tempdb', 'tmp ')
11
12 SET @ cmd = 'del E: \ backup \ SQL _data \ CompressPack \ backupdiff.rar'
13 EXEC master .. xp_mongoshell @ cmd
14
15 WHILE (select count (*) FROM @ t)> 0
16 BEGIN
17 select top 1 @ I = id FROM @ t
18 SELECT @ n = n FROM @ t WHERE @ I = id
19
20 SET @ SQL =''
21 SET @ SQL = @ SQL + N' DECLARE @ filename varchar (8000 );'
22 SET @ SQL = @ SQL + N' DECLARE @ rar_path varchar (8000 );'
23 SET @ SQL = @ SQL + N' SET @ rar_Path = ''c: \ Progra ~ 1 \ WinRAR \'';'
24 SET @ SQL = @ SQL + N' DECLARE @ cmd varchar (8000 );'
25 SET @ SQL = @ SQL + N' EXEC www_ednchina_com.dbo.usp_backup_database '+ @ N +', 'diff', @ filename output ;'
26 SET @ SQL = @ SQL + N' SET @ cmd = @ rar_Path + ''rar a E: \ backup \ SQL _data \ CompressPack \ backupdiff.rar E: \ backup \ SQL _data \ '+ @ n +' \ ''+ @ filename ;'
27 SET @ SQL = @ SQL + N' EXEC master .. xp_mongoshell @ cmd ';
28
29 EXEC sp_executesql @ SQL
30
31 delete from @ t WHERE @ I = id
32END

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.