SQLSERVER using extended stored procedures for remote backup and restore [Author: Anonymous Copy from: Site author Hits: 442 Update Time: 2004-5-14 article entry: admin]
I recently made data management modules for the company's framework program (with data-oriented applications). The demand for this module is relatively simple: backup, recovery, and cleanup logs. Our company's software is basically architecture with C / S, so two major functions in the data management module 'backup and recovery' may also be stored in the client, backup and recovery 'files in Client. End, thus this data management module must be able to implement remote backup and recovery databases. The premise of the article is explained, so I should talk about how to implement it. In fact, it is very simple. I want to write a test instance for remote backup to everyone, I can clearly describe it! Example: Environment: Win2k SQLServer 2K Query Analyzer SQLServer Service Instance Name: MainServer Requires Backup Database Name: MSDB Local Machine Name (Client End): David Local User: ZF Password: 123 Local Name: Domain provides backup requirements Folder: E: / TEST first step: Establish a shared folder in program code (or CMD window) NET Share test = E: / test or brief description with NetShareAdd this: NET Share: It is a network command inside Windows . Role: Establish a local shared resource to display the shared resource information of the current computer. Syntax: See NET Share /? Step 2: Establish a Shared Credit Relationship Master "NET Use // David / Test 123 / User: Domain / ZF 'Brief Description: 1: XP_cmdshell: is the extended stored procedure for SQL Server. Role, execute a given command string in the manner of the operating system command line interpreter, and returns any output in a text line mode. Syntax: See SQL Server Online Help 2: Net Use: It is the network command inside Windows. Role, connect your computer with a shared resource or disconnect, or display information about your computer connection. This command also controls a persistent network connection. Syntax: See NET USE /? Step 3: Backup Database Backup Database MSDB to Disk = '// David / Test / MSDB.Bak' does not need to be explained, syntax See SQLServer online help fourth step: Delete shared folder Call (or CMD Window) NET Share Test / Delete or Use NetSharedel This API Result: Procedure 1376, these pages belong to the database 'msdb' file 'msdbdata' (on file 1).