sql 백업

--1、  xp_cmdshell
USE master
EXEC sp_configure 'show advanced options', 1
RECONFIGURE WITH OVERRIDE
EXEC sp_configure 'xp_cmdshell', 1
RECONFIGURE WITH OVERRIDE
EXEC sp_configure   'show advanced options', 0
RECONFIGURE WITH OVERRIDE
--2、        
declare @db sysname
declare @dbpath varchar(120)
set @db='shenyin'
--          +  YYYYMMDD+   
set @dbpath='D:\'+@db+convert(varchar(10),getdate(),112)+'.bak'

--3、 sql     
exec master..xp_cmdshell 'net use Y: \\192.168.0.156\DBBackup "jindou" /user:192.168.0.156\Administrator'
/*
   :
 Y:              
 192.168.0.156     IP
 DBBackup          
 Administrator        
 "jindou"  Administrator     
*/
--4、  (@db          )
Backup Database @db To disk=@dbpath
--5、COPY
declare @copypath varchar(200)
set @copypath = 'copy '+@dbpath+' Y:'
select @copypath
exec master..xp_cmdshell @copypath 
--6、  (      )
declare @deletepath varchar(200)
set @deletepath = 'del '+@dbpath
select @deletepath
exec master..xp_cmdshell @deletepath 
--7、       
exec master..xp_cmdshell 'net use Y: /delete'
--8、  xp_cmdshell
USE master 
EXEC sp_configure 'show advanced options', 1 
RECONFIGURE WITH OVERRIDE 
EXEC sp_configure 'xp_cmdshell', 0 
RECONFIGURE WITH OVERRIDE 
EXEC sp_configure   'show advanced options', 0
RECONFIGURE WITH OVERRIDE 

좋은 웹페이지 즐겨찾기