在使用YourSQLDba做資料庫備份、維護時,像其它軟體一樣,版本升級是不可避免的。因為YourSQLDba一直在不停更新版本、擴展功能。下麵介紹一下升級YourSQLDba時的具體步驟和一些註意事項。下麵案例,YourSQLDba原版本為YourSQLDba version: 5.0.2 201... ...
在使用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 =