欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

--ERP Database Network Backup  

程序员文章站 2022-07-15 11:23:54
...

--ERP Database Network Backup
exec master..xp_cmdshell 'net use X: /delete /y'
exec master..xp_cmdshell 'net use X: \\192.168.1.188\myback  asdf;lkj1qaz /user:\ERP_backup' 

declare @NetPath  varchar(100)
declare @DBName   varchar(100)
declare @FileName varchar(100)

------------- DB_01 -------------------------------------------
set @NetPath='\\192.168.1.188\myback\'
set @DBName='DB_01'
set @FileName=@NetPath+@DBName+'_'+convert(varchar,getdate(),112)+'.bak'

exec master..sp_addumpdevice 'disk',@DBName,@FileName
backup database @DBName to @DBName with init,nounload,noskip,stats=10,noformat
exec master..sp_dropdevice @DBName

 --delete old backup
set @FileName='del '+@NetPath+@DBName+'_'+convert(varchar,getdate()-2,112)+'.bak'
exec master..xp_cmdshell @FileName

 

 

------------- SPC -------------------------------------------
set @NetPath='\\192.168.1.188\myback\'
set @DBName='SPC'
set @FileName=@NetPath+@DBName+'_'+convert(varchar,getdate(),112)+'.bak'

exec master..sp_addumpdevice 'disk',@DBName,@FileName
backup database @DBName to @DBName with init,nounload,noskip,stats=10,noformat
exec master..sp_dropdevice @DBName

 --delete old backup
set @FileName='del '+@NetPath+@DBName+'_'+convert(varchar,getdate()-2,112)+'.bak'
exec master..xp_cmdshell @FileName

 

------------- SunSystem -------------------------------------------
set @NetPath='\\192.168.1.188\myback\'
set @DBName='SunSystem'
set @FileName=@NetPath+@DBName+'_'+convert(varchar,getdate(),112)+'.bak'

exec master..sp_addumpdevice 'disk',@DBName,@FileName
backup database @DBName to @DBName with init,nounload,noskip,stats=10,noformat
exec master..sp_dropdevice @DBName

 --delete old backup
set @FileName='del '+@NetPath+@DBName+'_'+convert(varchar,getdate()-2,112)+'.bak'
exec master..xp_cmdshell @FileName

 

------------- OA -------------------------------------------
set @NetPath='\\192.168.1.188\myback\'
set @DBName='OA'
set @FileName=@NetPath+@DBName+'_'+convert(varchar,getdate(),112)+'.bak'

exec master..sp_addumpdevice 'disk',@DBName,@FileName
backup database @DBName to @DBName with init,nounload,noskip,stats=10,noformat
exec master..sp_dropdevice @DBName

 --delete old backup
set @FileName='del '+@NetPath+@DBName+'_'+convert(varchar,getdate()-2,112)+'.bak'
exec master..xp_cmdshell @FileName

 

 

 

 


------------- wsxPLM -------------------------------------------
set @NetPath='\\192.168.1.188\myback\'
set @DBName='wsxPLM'
set @FileName=@NetPath+@DBName+'_'+convert(varchar,getdate(),112)+'.bak'

exec master..sp_addumpdevice 'disk',@DBName,@FileName
backup database @DBName to @DBName with init,nounload,noskip,stats=10,noformat
exec master..sp_dropdevice @DBName

 --delete old backup
set @FileName='del '+@NetPath+@DBName+'_'+convert(varchar,getdate()-2,112)+'.bak'
exec master..xp_cmdshell @FileName


------------- DB_02 -------------------------------------------
set @NetPath='\\192.168.1.188\myback\'
set @DBName='DB_02'
set @FileName=@NetPath+@DBName+'_'+convert(varchar,getdate(),112)+'.bak'

exec master..sp_addumpdevice 'disk',@DBName,@FileName
backup database @DBName to @DBName with init,nounload,noskip,stats=10,noformat
exec master..sp_dropdevice @DBName

 --delete old backup
set @FileName='del '+@NetPath+@DBName+'_'+convert(varchar,getdate()-2,112)+'.bak'
exec master..xp_cmdshell @FileName


------------- DB_03 -------------------------------------------
set @NetPath='\\192.168.1.188\myback\'
set @DBName='DB_03'
set @FileName=@NetPath+@DBName+'_'+convert(varchar,getdate(),112)+'.bak'

exec master..sp_addumpdevice 'disk',@DBName,@FileName
backup database @DBName to @DBName with init,nounload,noskip,stats=10,noformat
exec master..sp_dropdevice @DBName

 --delete old backup
set @FileName='del '+@NetPath+@DBName+'_'+convert(varchar,getdate()-2,112)+'.bak'
exec master..xp_cmdshell @FileName