zoukankan      html  css  js  c++  java
  • 备份DB

    alter procedure dbo.usp_backup_database
      @p_dbname varchar(50),        -- 备份数据库名称
      @p_type varchar(50)          -- 备份类型,full or log
    as
      declare @sql varchar(1000)
      declare @role tinyint
      select 
        @role = dhar.role
      from master.sys.availability_replicas as ar
      left join master.sys.dm_hadr_availability_replica_states as dhar on ar.replica_id = dhar.replica_id
      where exists
      (
        select * from master.sys.availability_groups
        where name='ag_crm_db'
        and ar.group_id = group_id
      )and ar.replica_server_name = SERVERPROPERTY('MachineName') 
    
      if @role != 1
      begin
        return
      end
    
      if @p_type = 'full'
      begin
          set @sql = 'backup database [' + @p_dbname + '] to disk = ''D:\backup\' + @p_dbname + '.full.bak'' with format, COMPRESSION'
      end
    
      if @p_type = 'diff'
      begin
          set @sql = 'backup database [' + @p_dbname + '] to disk = ''D:\backup\' + @p_dbname + '.'+ CAST(DATEPART(weekday,getdate()) as char(1))+'.diff'' with DIFFERENTIAL, format, COMPRESSION'
      end
    
      if @p_type = 'log'
      begin
          set @sql = 'backup log  [' + @p_dbname + '] to disk = ''D:\backup\' + @p_dbname + '.'+ CAST(DATEPART(hour,getdate()) as varchar(2))+'.log'' with format, COMPRESSION'
      end
    
      execute(@sql)
  • 相关阅读:
    ZOJ 3490 String Successor
    ZOJ 3465 The Hive
    ZOJ 3077 Move to Baggage Office
    ZOJ 2836 Number Puzzle
    POJ 2115 C Looooops
    ZOJ 3605 Find the Marble
    扩展欧几里德
    搭配飞行员(网络流)
    最小费用流
    最大流
  • 原文地址:https://www.cnblogs.com/goodspeed/p/120437.html
Copyright © 2011-2022 走看看