SQL Server中网络备份一例
时间:2020-10-31 14:15 作者:admin610456
复制代码 代码如下:usemaster
declare@dirvarchar(256),@dir_dbvarchar(256),
@verbvarchar(256),@cmdvarchar(256),
@backup_namevarchar(256),@dynamic_namevarchar(10),
@disk_namevarchar(256)
--建立网络连接
execxp_cmdshell'netuseK:/delete'
execxp_cmdshell'netuseK:\\Lant\backupbackup/user:Lant\backup'
--设定名字
set@dynamic_name=convert(varchar(10),getdate(),120)
set@dir='K:\'+@dynamic_name
set@dir_db=@dir+'ibm'
set@verb='mkdir'
--建立目录
--set@cmd=@verb+@dir
--execxp_cmdshell@cmd
set@cmd=@verb+@dir_db
execxp_cmdshell@cmd
--wapec_wap
set@backup_name='lifengOA_'+@dynamic_name
set@disk_name=@dir_db+'\'+@backup_name
EXECsp_addumpdevice'disk',@backup_name,@disk_name
BACKUPDATABASEec_wapTO@backup_name
execsp_dropdevice@backup_name
--文档ec_tech
set@backup_name='文档_'+@dynamic_name
set@disk_name=@dir_db+'\'+@backup_name
EXECsp_addumpdevice'disk',@backup_name,@disk_name
BACKUPDATABASEec_techTO@backup_name
execsp_dropdevice@backup_name
--博吧ec_blog
set@backup_name='博吧_'+@dynamic_name
set@disk_name=@dir_db+'\'+@backup_name
EXECsp_addumpdevice'disk',@backup_name,@disk_name
BACKUPDATABASEec_blogTO@backup_name
execsp_dropdevice@backup_name
execxp_cmdshell'netuseK:/delete'
然后做一个Task,那么,SQLServer就会备份到指定的网络地址\\Lant\bakcup下
(责任编辑:admin)