zoukankan      html  css  js  c++  java
  • 数据库 备份 压缩

    --打开XP_CMDShell命令
    -- To allow updates.
    EXEC sp_configure 'allow updates', 0
    GO
    -- To allow advanced options to be changed.
    EXEC sp_configure 'show advanced options', 1
    GO
    -- To update the currently configured value for advanced options.
    RECONFIGURE
    GO
    -- To enable the feature.
    EXEC sp_configure 'xp_cmdshell', 1
    GO
    -- To update the currently configured value for this feature.
    RECONFIGURE
    GO
    
    declare @database_name varchar(100)
    declare @bakname varchar(100)
    declare @bakfile varchar(100)
    declare @rarfile varchar(100)
    declare @rarcmd varchar(256)
    
    declare dbname cursor for select name from sys.databases where database_id > 4--游标取所有数据库名  
    open dbname  
    FETCH NEXT FROM dbname INTO @database_name  
      
    WHILE (@@FETCH_STATUS = 0)  
    begin  
    	set @bakfile = 'F:\backup\'
    	set @rarfile = 'F:\backup\'
    	set @bakname = @database_name+cast(Year(GetDate()) as varchar(4))+cast(Month(GetDate()) as varchar(2))+cast(Day(GetDate()) as varchar(2))
    	set @bakfile = @bakfile + @bakname + '.bak' 
    	set @rarfile = @rarfile + @bakname + '.rar' 
    	BACKUP DataBASE @database_name TO DISK = @bakfile WITH INIT , NOUNLOAD , NAME = @bakname, NOSKIP , STATS = 10, NOFORMAT 
    
    	set @rarcmd ='C:\Progra~1\WinRAR\WinRAR.exe a -sv- -v4481m'+@rarfile+' '+@bakfile //分卷压缩
    	exec master..xp_cmdshell @rarcmd
    
    	FETCH NEXT FROM dbname INTO @database_name  
    end  
      
    CLOSE dbname  
    DEALLOCATE dbname  
    
    
    --关闭XP_CMDShell命令
    -- To allow advanced options to be changed.
    EXEC sp_configure 'show advanced options', 1
    GO
    -- To update the currently configured value for advanced options.
    RECONFIGURE
    GO
    -- To enable the feature.
    EXEC sp_configure 'xp_cmdshell', 0
    GO
    -- To update the currently configured value for this feature.
    RECONFIGURE
    GO
    

      

  • 相关阅读:
    创建无线网命令行
    网站推荐(多用于IT)
    企业级快速开发平台
    用代码截图去理解MVC原理
    .Net 下开发使用JSON
    EF实体框架数据操作基类
    EF实体框架数据操作接口
    开启GZIP
    EF快速开发定义数据接口类
    仿造w3school的试一试功能,实现左侧编辑框,右侧效果页面
  • 原文地址:https://www.cnblogs.com/jonhson/p/2234874.html
Copyright © 2011-2022 走看看