Paip. Improve development efficiency-Automatic Database SQL backup

Source: Internet
Author: User
Tags management studio microsoft sql server management studio sql server management sql server management studio

Paip. Improve development efficiency ---- automatic Database SQL backup

Because we constantly change the database SQL structure, we hope to import the exported SQL statement to the project every night, and then perform Incremental backup ..

Enterprise Edition SQL has automatic tasks, and you can set Automatic Export SQL ..

And my sql2008 Express .. There is no way to export automatically. Only manual operations can be performed ..

After some effort, I finally found a method .. That is to say, you can create an EXE by pressing the wizard 9.0 to automatically operate the SQL server and then call it in batch processing.

Start to write the wizard script:

// Run sql2008 Manager
Runapp "C: \ Program Files \ Microsoft SQL Server \ 100 \ tools \ binn \ vsshell \ common7 \ ide \ ssms.exe"
// Latency, prepare for the following window handle. If there is no delay, the window handle may not be found
Delay2000

// Find the window class name (0) or title, and return the found handle hwnd .. This is a logon window.
Hwnd = plugin. Window. Find (0, "connect to server ")
// Activation window
Call plugin. Window. Active (hwnd)

// Pressing Alt + C is equivalent to clicking the "Connect" button on the interface to connect to the SQL server.
Keydown 18, 1
Keypress 67, 1
Keyup 18, 1

// Wait until the logon window disappears.
Delay2000

// Go to the main window
Hwndmax = plugin. Window. Find (0, "Microsoft SQL Server Management Studio ")
// Maximize the window to facilitate mouse recording and positioning.
Call plugin. Window. Max (hwndmax)

 

// The Unregistered version will be compiled into EXE and an advertisement window will appear in the lower right corner. Find this window and hide it ..
Hwndad = plugin. Window. Find ("afxframeorview42 ","")
 
Call plugin. Window. Hide (hwndad)

// ---------- The following are a series of mouse recording operations. Expand the tree node on the left, find the database to export SQL, and generate a script
Delay754
VPC: moveTo 807,469
Delay 7
VPC: moveTo 825,470
* *** A few hundred rows are omitted here ..

// The "generate script" window is opened.

Delay1000

Hwnd8 = plugin. Window. Find (0, "script wizard-hope \ sqlexpress ")
Call plugin. Window. Active (hwnd8)
Delay500
// Maximize the window
Call plugin. Window. Max (hwnd8)

// A series of mouse recording operations to export SQL .. And close the process...
'========== The following is the content recorded by the press Key genie ==========
Delay754
VPC: moveTo 807,469
Delay 7
VPC: moveTo 825,470
Delay 41
* *** A few hundred rows are omitted here ..

// ------------------------------------ End of script -----------------------

In this example, a script file is compiled into baksql.exe... and then a batch file is compiled for automatic calling.

// If the process exists, wait until baksql completes the SQL export operation ..
Set taskname = "C: \ Users \ Administrator \ Desktop \ cbgl \ baksql.exe"
 
% Taskname %

Set tasknameshort = "baksql.exe"
: Start
Tasklist/fi "imagename EQ % tasknameshort %" | find/I "% tasknameshort %"
If % errorlevel % equ 0 Goto: Start
: End

// Copy to the project directory
Copy/y "C: \ Users \ Administrator \ Documents ents \ script. SQL" C: \ Users \ Administrator \ Desktop \ cbgl \ script. SQL"

// Use WinRAR Incremental Backup
"C: \ Program Files \ WinRAR \ rar.exe" a-EP1-M1-r-N *. TXT-N *. doc-N *. CS-N *. csproj-N *. SLN-N *. resx-N *. SQL-N *. config-N *. XSD-N *. settings-ta2012-07-20-01: 01: 01% zipname % "C: \ Users \ Administrator \ Desktop \ cbgl"
Pause

 

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.