Backup server-side SQL Server database to local directory

Source: Internet
Author: User
Tags sql backup
server| Backup | server | data | database

/* data stored in storage process * *
/**//* support from the data from the service device to the local machine
--
CREATE PROCEDURE Up_dbbackup
(
@backup_db_name VARCHAR (128),
@filename VARCHAR (128),/**//* backup path + filename * *
@flag VARCHAR () OUTPUT
)
As
SET NOCOUNT on
DECLARE @sql NVARCHAR (4000), @par NVARCHAR (1000)
IF not EXISTS (
SELECT * FROM Master. sysdatabases
WHERE name= @backup_db_name
)
BEGIN
SELECT @flag = ' data library ' + @backup_db_name + ' does not exist! '
Return
End
ELSE
BEGIN
IF Right (@filename, 1) <> ' and CHARINDEX (' \ ', @filename) <>0
BEGIN
/**//* definition of the logo
DECLARE @lFlag INT
EXECUTE @lFlag =master. xp_cmdshell ' DIR Z: '
IF @lFlag <>0
BEGIN
/**//* a fully shared catalogue of DB on the client 192.168.2.45, specifying a username and password. Win98 user name and password not required
EXECUTE @lFlag =master. xp_cmdshell ' NET use Z: \\192.168.2.45\db$ test/user:ca.atc\test '
IF @lFlag <>0
BEGIN
SELECT @flag = ' Service creators fail! '
Return
End
End
SELECT @par = ' @filename VARCHAR (1000) '
SELECT @sql = ' BACKUP DATABASE ' + @backup_db_name + ' to disk= @filename with INIT '
EXECUTE sp_executesql @sql, @par, @filename
EXECUTE Master.. xp_cmdshell ' NET use Z:/delete '
SELECT @flag = ' data library ' + @backup_db_name + ' backup success! '
Return
End
ELSE
BEGIN
SELECT @flag = ' data is in the library's path wrong! '
Return
End
End


* * The above process is tested under SQL Server



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.