Copy codeThe 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.