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
    

      

  • 相关阅读:
    Python实战之SocketServer模块
    CentOS出错You don't have permission to access on this server
    系统瓶颈分析
    loadrunner支持https协议的操作方法-经验总结
    Loadrunner上传与下载文件脚本
    Loadrunner之HTTP接口测试脚本实例
    Android界面性能调优手册
    Loadrunner11.0 录制手机App脚本的方法
    资源监控工具--spotlight
    Jmeter常见问题
  • 原文地址:https://www.cnblogs.com/jonhson/p/2234874.html
Copyright © 2011-2022 走看看