YourSQLDba版本升級總結

weixin_30639719發表於2020-04-05

    在使用YourSQLDba做資料庫備份、維護時,像其它軟體一樣,版本升級是不可避免的。因為YourSQLDba一直在不停更新版本、擴充套件功能。下面介紹一下升級YourSQLDba時的具體步驟和一些注意事項。下面案例,YourSQLDba原版本為YourSQLDba version: 5.0.2 2012-06-12,升級到YourSQLDba 6.2.5.1。

 

步驟1: 首先檢視伺服器對應YourSQLDba的版本資訊。因為不同版本的升級可能有所區別。要做的工作可能不一樣。

 

Exec YourSQLDba.Install.PrintVersionInfo
 
========================================
 
YourSQLDba version: 5.0.2 2012-06-12
 
========================================

 

步驟2:檢視YourSQLDba下的所有作業資訊。

 

    這個步驟,主要是因為我們在不同程度的擴充套件了YourSQLDba的一些功能。另外,有可能你對YourSQLDba_FullBackups_And_Maintenance等作業做了一些修改、變更。所以在升級前對變跟的地方有所瞭解,記錄整理,方便升級後做出對應的修改。 如果你沒有對YourSQLDba做任何修改、擴充套件,那麼可以忽略這個步驟。

    使用下面SQL將所有YourSQLDba的作業列出來,然後收集、整理是否有做變跟。是否需要在升級後,做出對應的調整、修改。

SELECT j.job_id                                       AS JOB_ID            
      ,j.name                                         AS JOB_NAME          
      ,CASE WHEN [enabled] =1 THEN 'Enabled'
                              ELSE 'Disabled' END     AS JOB_ENABLED       
      ,j.category_id                                  AS JOB_CATEGORY_ID
      ,c.name                                         AS JOB_CATEGORY_NAME
      ,[description]                                  AS JOB_DESCRIPTION   
      ,date_created                                   AS DATE_CREATED      
      ,date_modified                                  AS DATE_MODIFIED
FROM msdb.dbo.sysjobs j
INNER JOIN msdb.dbo.syscategories c ON j.category_id = c.category_id
WHERE   job_id IN( SELECT job_id
                  FROM    msdb.dbo.sysjobsteps
                  WHERE   database_name = 'YourSQLDba' )
 ORDER BY j.name

 

步驟3:執行YourSQLDba指令碼,如果你沒有做任何擴充套件。那麼直接執行指令碼即可,不需要修改任何指令碼。

如果你研究過了指令碼,那麼你們會發現,YourSQLDba是會保留原來的資料的,在程式碼裡面,你會看到在刪除YourSQLDba資料庫之前,指令碼會將先前YourSQLDba的資料儲存到臨時表。

If databasepropertyEx('YourSQLDba','status') IS NOT NULL -- db is there
Begin
  -- save data about some YourSqlDba tables
  If object_id('tempdb..##JobHistory') is not null Drop table ##JobHistory;
  If object_id('tempdb..##JobLastBkpLocations') is not null Drop table ##JobLastBkpLocations;
  If object_id('tempdb..##JobSeqCheckDb') is not null Drop table ##JobSeqCheckDb;
  If object_id('tempdb..##TargetServer') is not null Drop table ##TargetServer;
  If object_id('tempdb..##JobSeqUpdStat') is not null Drop table ##JobSeqUpdStat;
  If object_id('tempdb..##NetworkDrivesToSetOnStartup') is not null Drop table ##NetworkDrivesToSetOnStartup;
 
  -- If table exists in previous version save its content
  If Object_id('YourSqlDba.Maint.JobHistory') IS NOT NULL
    Select * Into ##JobHistory From YourSqlDba.Maint.JobHistory
 
  If Object_id('YourSqlDba.Maint.JobLastBkpLocations') IS NOT NULL
    Select * Into ##JobLastBkpLocations From YourSqlDba.Maint.JobLastBkpLocations
 
  If Object_id('YourSqlDba.Mirroring.TargetServer') IS NOT NULL
    Select * Into ##TargetServer From YourSqlDba.Mirroring.TargetServer
 
  If Object_id('YourSqlDba.Maint.JobSeqUpdStat') IS NOT NULL
    Select * Into ##JobSeqUpdStat From YourSqlDba.Maint.JobSeqUpdStat
 
  If Object_id('YourSqlDba.Maint.JobSeqCheckDb') IS NOT NULL
    Select * Into ##JobSeqCheckDb From YourSqlDba.Maint.JobSeqCheckDb
 
  If Object_id('YourSqlDba.Maint.NetworkDrivesToSetOnStartup') Is NOT NULL
    Select * Into ##NetworkDrivesToSetOnStartup From YourSqlDba.Maint.NetworkDrivesToSetOnStartup

然後在YourSQLDba建立成功後,將資料匯入到新建的表後,刪除臨時表。部分指令碼如下所示:

-- if the table doesn't exists create the latest version
If object_id('Maint.JobSeqCheckDb') is null 
Begin
  Declare @sql nvarchar(max)
  Set @sql =
  '
  Create table  Maint.JobSeqCheckDb
  (
    seq         int
  )
  Insert into Maint.JobSeqCheckDb values(0)
  '
  Exec (@sql)
 
  If Object_Id('tempdb..##JobSeqCheckDb') IS NOT NULL
    Exec
    (
    '
    Insert Into Maint.JobSeqCheckDb (seq) 
    Select Seq
    From ##JobSeqCheckDb
    Drop table ##JobSeqCheckDb
    '
    )
End
GO

 

如果你做過擴充套件,例如我按天、周、月監控資料庫的增長情況,那麼我要在YourSQLDba升級過程中保留這些歷史資料,那麼就必須修改這部分指令碼(這些涉及太多指令碼,不宜在此貼過多指令碼,在此不做過多探討)。YourSQLDba指令碼升級成功後,會有下面提示資訊

 

步驟4:更新YourSQLDba_FullBackups_And_Maintenance和YourSQLDba_LogBackups作業。

 

    首先,在YourSQLDba升級過程中,指令碼並不會更新這兩個作業。在前面的幾個版本中,都不需要重新新作業YourSQLDba_FullBackups_And_Maintenance等,因為即使版本不一樣,但是作業功能基本是一致的。但是像這樣兩個版本差別大的時候, 作業裡面執行的儲存過程的引數都不一樣了。例如5.0.2,裡面全備的執行的儲存過程為

exec Maint.YourSqlDba_DoMaint
  @oper = 'YourSQLDba_Operator'
, @MaintJobName = 'YourSQLDba: DoInteg,DoUpdateStats,DoReorg,Full backups'
, @DoInteg = 1
, @DoUpdStats = 1
, @DoReorg = 1
, @DoBackup = 'F'
, @FullBackupPath = 'M:\DB_BACKUP\FULL_BACKUP\' 
, @LogBackupPath = 'M:\DB_BACKUP\LOG_BACKUP\'  
-- Flush database backups older than the number of days
, @FullBkpRetDays = 1 
-- Flush log backups older than the number of days
, @LogBkpRetDays = 2
-- Spread Update Stats over 7 days 
, @SpreadUpdStatRun =1
-- Maximum number of consecutive days of failed full backups allowed
-- for a database before putting that database (Offline). 
, @ConsecutiveDaysOfFailedBackupsToPutDbOffline = 9999 
-- Each database inclusion filter must be on its own line between the following quote pair
, @IncDb = 
' 
-- Each database exclusion filter must be on its own line between the following quote pair
, @ExcDb = 
'
-- Each database exclusion filter must be on its own line between the following quote pair
, @ExcDbFromPolicy_CheckFullRecoveryModel = 
'

 

但是6.2.5.1裡面,執行的儲存過程如下所示,多了引數 @SpreadCheckDb,引數@ConsecutiveDaysOfFailedBackupsToPutDbOffline名字變了,如果不做修改,那麼作業就會報錯。

exec Maint.YourSqlDba_DoMaint
  @oper = 'YourSQLDba_Operator'
, @MaintJobName = 'YourSQLDba: DoInteg,DoUpdateStats,DoReorg,Full backups'
, @DoInteg = 1
, @DoUpdStats = 1
, @DoReorg = 1
, @DoBackup = 'F'
, @FullBackupPath = 'M:\DB_BACKUP\FULL_BACKUP\' 
, @LogBackupPath = 'M:\DB_BACKUP\LOG_BACKUP\'  
-- Flush database backups older than the number of days
, @FullBkpRetDays = 1
-- Flush log backups older than the number of days
, @LogBkpRetDays =2
-- Spread Update Stats over 7 days 
, @SpreadUpdStatRun = 1
-- Spread Check DB without 'PHYSICAL_ONLY' over 7 days
, @SpreadCheckDb = 7
-- Maximum number of consecutive days of failed full backups allowed
-- for a database before putting that database (Offline). 
, @ConsecutiveDaysOfFailedBackupsToPutDbOffline = 0 
-- Each database inclusion filter must be on its own line between the following quote pair
, @IncDb = 
' 
-- Each database exclusion filter must be on its own line between the following quote pair
, @ExcDb = 
'
-- Each database exclusion filter must be on its own line between the following quote pair
, @ExcDbFromPolicy_CheckFullRecoveryModel = 
'

 

而升級指令碼並不會重建或更新作業,所以我們執行初始化指令碼YourSQLDba.[Install].[InitialSetupOfYourSqlDba]更新作業。注意,執行該指令碼後,你原來的配置引數都會使用初始化引數,例如(@FullBkpRetDays,@LogBkpRetDays…..等),另外,像YourSQLDba_LogBackups作業的Schedule變為15分鐘做一次事務日誌備份,在執行指令碼前,最好記錄原來的引數,以免影響原來的備份策略。

EXEC YourSQLDba.[Install].[InitialSetupOfYourSqlDba]  
  @FullBackupPath = 'M:\DB_BACKUP\FULL_BACKUP\' -- full backup path destination 
 ,@LogBackupPath = 'M:\DB_BACKUP\LOG_BACKUP\'   -- log backup path destination 
 ,@email = 'xxx@xxxx.com'                  -- Email recipients (or distribution list)
 ,@SmtpMailServer = 'xxx.xxx.xxx.xxx'             -- Mail server that accept SMTP mail 
 ,@ConsecutiveDaysOfFailedBackupsToPutDbOffline = 9999 

另外,如果我們擴充套件了YourSQLdba的指令碼,此時就必須新增相應儲存過程,作業倒不必新建(因為YourSQLDba升級不會刪除作業,但是由於YourSQLDba資料庫重建了,所以作業裡面呼叫的儲存過程可能沒有了)。

轉載於:https://www.cnblogs.com/kerrycode/p/5579176.html

相關文章