An example of network backup in SQLServer

Source: Internet
Author: User
An example of network backup in SQLServer

An example of network backup in SQL Server

The Code is as follows: use master

Declare @ dir varchar (256), @ dir_db varchar (256 ),
@ Verb varchar (256), @ cmd varchar (256 ),
@ Backup_name varchar (256), @ dynamic_name varchar (10 ),
@ Disk_name varchar (256)

-- Establish a network connection
Exec xp_cmdshell 'net use K:/delete'
Exec xp_cmdshell 'net use K: \ Lant \ backup/user: Lant \ backup'


-- Set the name
Set @ dynamic_name = convert (varchar (10), getdate (), 120)

Set @ dir = 'K: \ '+ @ dynamic_name
Set @ dir_db = @ dir + 'ibm'
Set @ verb = 'mkdir'


-- Create a directory

-- Set @ cmd = @ verb + @ dir
-- Exec xp_cmdshell @ cmd

Set @ cmd = @ verb + @ dir_db
Exec xp_cmdshell @ cmd

-- Wap ec_wap
Set @ backup_name = 'lifengoa _ '+ @ dynamic_name
Set @ disk_name = @ dir_db + '\' + @ backup_name

EXEC sp_addumpdevice 'disk', @ backup_name, @ disk_name
Backup database ec_wap TO @ backup_name
Exec sp_dropdevice @ backup_name

-- Ec_tech
Set @ backup_name = 'document _ '+ @ dynamic_name
Set @ disk_name = @ dir_db + '\' + @ backup_name


EXEC sp_addumpdevice 'disk', @ backup_name, @ disk_name
Backup database ec_tech TO @ backup_name
Exec sp_dropdevice @ backup_name


-- Bo Ba ec_blog
Set @ backup_name = 'blog _ '+ @ dynamic_name
Set @ disk_name = @ dir_db + '\' + @ backup_name

EXEC sp_addumpdevice 'disk', @ backup_name, @ disk_name
Backup database ec_blog TO @ backup_name
Exec sp_dropdevice @ backup_name

Exec xp_cmdshell 'net use K:/delete'


After a Task is created, SQL Server backs up the data to the specified network address \ Lant \ bakcup.

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.