YourSQLDba 配置——修改备份路径

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 1个月
简介:

    公司一直使用YourSQLDba做本地备份,磁带机将本地备份文件上带做异地容灾备份。近期整理、验证备份时发现本地备份目录命名五花八门

clipboard

其中有历史原因,也有无规划化的缘故,看着这些五花八门的目录,越看越不顺眼。于是想统一规范化。备份目录统一为DB_BACKUP,完整备份位于FULL_BACKUP子目录,事务日志备份位于LOG_BACKUP子目录下。例如如下所示:

    完整备份目录    :G:\DB_BACKUP\FULL_BACKUP\

    事务日志备份目录:G:\DB_BACKUP\LOG_BACKUP\

于是需要修改YourSQLDba备份路径,本来是一个简单的事情,但是在测试过程中,发现了一些小问题,特此记录一下:

 

问题1:在哪里修改备份路径? 修改是否立即生效?

    修改YourSQLDba的备份路径,需要修改两个作业YourSQLDba_FullBackups_And_Maintenance 和YourSQLDba_LogBackups的配置. 即修改调用的存储过程Maint.YourSqlDba_DoMaint中的@FullBackupPath和@LogBackupPath参数。如下所 示:

clipboard[1]

 

YourSQLDba_FullBackups_And_Maintenance作业

exec Maint.YourSqlDba_DoMaint
  @oper = 'YourSQLDba_Operator'
, @MaintJobName = 'YourSQLDba: DoInteg,DoUpdateStats,DoReorg,Full backups'
, @DoInteg = 1
, @DoUpdStats = 1
, @DoReorg = 1
, @DoBackup = 'F'
, @FullBackupPath = 'G:\DB_BACKUP\FULL_BACKUP\'
, @LogBackupPath = 'G:\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).
, @ConsecutiveFailedbackupsDaysToPutDbOffline = 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 =
'
'

 

YourSQLDba_LogBackups作业

exec Maint.YourSqlDba_DoMaint
  @oper = 'YourSQLDba_Operator'
, @MaintJobName = 'Log backups'
, @DoBackup = 'L'
, @FullBackupPath = 'G:\DB_BACKUP\FULL_BACKUP\'
, @LogBackupPath = 'G:\DB_BACKUP\LOG_BACKUP\'
-- Specify to user that full database backups are mandatory before log backups
, @NotifyMandatoryFullDbBkpBeforeLogBkp = 1
, @BkpLogsOnSameFile = 1
-- 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 =
'
'

 

将@FullBackupPath和 @LogBackupPath 从D:\backup\修改为G:\DB_BACKUP\FULL_BACKUP\与G:\DB_BACKUP\LOG_BACKUP\后,修 改后是否立即生效?  修改过后,如果没有先做一次完整备份,事务日志备份文件(事务日志备份有可能半小时。一小时一次等多种选择)并不会在新目录G:\DB_BACKUP \LOG_BACKUP\生成,依然还是在旧目录G:\backup\下生成。直到完整备份备份后,事务日志备份才在新目录生效。这样就导致我必须等到旧 目录数据文件完全上带后才能删除旧目录。但是为什么会这样呢?

从Maint.YourSqlDba_DoMaint追查开始,发现其调用[yMaint].[Backups]做备份,做事务日志备份的一段代码如下

If @DoFullBkp = 1 And DATABASEPROPERTYEX(@DbName, 'Recovery') <> 'Simple'
      Begin
        Set @fileName = yMaint.MakeBackupFileName(@DbName, 'L', @LogBackupPath, @Language, @LogBkExt)
       
        Set @sql = yMaint.MakeBackupCmd
                   (
                     @DbName
                   , 'L' -- say explicitely full backup command
                   , @fileName
                   , 1
                   , @MaintJobName
                   )
        -- Launch first log backup that creates the file that will be used
        -- to stored log backups usually for the rest of the days unless
        -- end-user launch Maint.SaveDbOnNewFileSet
        Exec yExecNLog.LogAndOrExec
          @context = 'yMaint.backups'
        , @sql = @sql
        , @Info = 'Log backups (init)'
        , @JobNo = @JobNo
        , @errorN = @errorN_BkpPartielInit output
        -- Restore the backup to the mirror server if enabled
        Exec yMirroring.QueueRestoreToMirrorCmd
             @context = 'yMaint.backups (queue restore of log backup init)'
           , @JobNo = @JobNo
           , @DbName = @DbName
           , @bkpTyp = N'L'
           , @fileName = @fileName
           , @MirrorServer = @MirrorServer
           , @BrokerDlgHandle = @BrokerDlgHandle OUT
                             
        If @errorN_BkpPartielInit = 0 -- version
        Begin
          Update Maint.JobLastBkpLocations
          Set lastLogBkpFile = @filename
           , MirrorServer = @MirrorServer
          Where dbName = @DbName
         
          -- shrink the log after backup (the procedure acts depending on the size)
          -- Exec yMaint.ShrinkLog @DbName, @JobNo
        End
      End

 

其中@fileName = yMaint.MakeBackupFileName(@DbName, 'L', @LogBackupPath, @Language, @LogBkExt)取值取决于@LogBackupPath, 而@LogBackupPath来源于Maint.JobHistory中(如下所示)。每次全备在Maint.JobHistory中生成一条记录,而 全备后不管事务日志备份多少次,只会在第一次事务日志备份时生成记录,所以即使修改了@FullBackupPath和 @LogBackupPath这两个参数的值,Maint.JobHistory表中最后一次事务日志备份记录的值依然为修改前的旧值。从而出现上面描述 的问题。

Select 
    @MaintJobName = JobName 
  , @DoFullBkp = DoFullBkp
  , @DoLogBkp = DoLogBkp
  , @FullBkpRetDays = FullBkpRetDays
  , @LogBkpRetDays = LogBkpRetDays
  , @NotifyMandatoryFullDbBkpBeforeLogBkp = NotifyMandatoryFullDbBkpBeforeLogBkp
  , @BkpLogsOnSameFile = BkpLogsOnSameFile
  , @FullBackupPath = yUtl.NormalizePath(FullBackupPath )
  , @LogBackupPath = yUtl.NormalizePath(LogBackupPath )
  , @FullBkExt = FullBkExt
  , @LogBkExt = LogBkExt
  , @ConsecutiveFailedbackupsDaysToPutDbOffline = ConsecutiveFailedbackupsDaysToPutDbOffline 
  , @IncDb = IncDb 
  , @ExcDb = ExcDb 
  , @jobStart = JobStart 
  , @MirrorServer = MirrorServer
  , @JobId = JobId
  , @StepId = StepId
  From Maint.JobHistory Where JobNo = @JobNo

 

问题2:修改备份路径后,原路径下的备份文件能否在保留期后自动删除?


如下所示,在存储过程[yMaint].[Backups]里面删除过期备份时,@Path参数来自于@FullBackupPath 和@LogBackupPath


clipboard[2]

clipboard[3]

 

这两个参数的值来源于表Maint.JobHistory, 而当修改了YourSQLDba备份路径后,如果没有做一次全备,对应记录FullBackupPath 与LogBackupPath字段的值都是原先的路径(因为事务日志备份的路径从Maint.JobHistory最后一次事务日志记录取值,也即原先的 路径),做了一次全备后,其值都是修改后路径,这样就会导致以前备份删除不了的情况。此时只能手工删除。

Select
   @MaintJobName = JobName
 , @DoFullBkp = DoFullBkp
 , @DoLogBkp = DoLogBkp
 , @FullBkpRetDays = FullBkpRetDays
 , @LogBkpRetDays = LogBkpRetDays
 , @NotifyMandatoryFullDbBkpBeforeLogBkp = NotifyMandatoryFullDbBkpBeforeLogBkp
 , @BkpLogsOnSameFile = BkpLogsOnSameFile
 , @FullBackupPath = yUtl.NormalizePath(FullBackupPath )
 , @LogBackupPath = yUtl.NormalizePath(LogBackupPath )
 , @FullBkExt = FullBkExt
 , @LogBkExt = LogBkExt
 , @ConsecutiveFailedbackupsDaysToPutDbOffline = ConsecutiveFailedbackupsDaysToPutDbOffline
 , @IncDb = IncDb
 , @ExcDb = ExcDb
 , @jobStart = JobStart
 , @MirrorServer = MirrorServer
 , @JobId = JobId
 , @StepId = StepId
 From Maint.JobHistory Where JobNo = @JobNo

 

问题3:输出日志文件MaintenanceReport.txt路径在哪里修改?


YourSQLDba的输出日志文件 MaintenanceReport.txt并不会随着@FullBackupPath和 @LogBackupPath 的修改会保存到新目录。这个文件的输出目录的值放置在msdb.dbo.sysjobsteps表中,对应记录的output_file_name字段。

可以通过两种方式来修改:

 

1 SQL脚本方式:

EXEC msdb.dbo.sp_update_jobstep @job_id=N'41662692-c7b2-47ae-8e07-df3eb12e1fe2', @step_id=1 ,

  @output_file_name=N'G:\DB_BACKUP\MaintenanceReport.txt'

2:UI图形界面:


clipboard[4]


问题4:是否可以用其它方式


可以修改@FullBackupPath和 @LogBackupPath参数值后,将旧备份文件拷贝到对应新目录,不过对备份比较大的服务器,会产生一定的IO消耗。修改修改 Maint.JobLasstBkpLocations记录中的LastLogBkpFile和LastFullBkpFile字段, 以及Maint.JobHistory中最后一条记录的FullBackupPath与LogBackupPath。

UPDATE Maint.JobLastBkpLocations set lastLogBkpFile='G:\DB_BACKUP\LOG_BACKUP\xxxx_[2014-07-15_17h48m08_Tue]_logs.TRN', 
lastFullBkpFile='G:\DB_BACKUP\FULL_BACKUP\xxxx_[2014-07-15_17h48m07_Tue]_database.BAK'
WHERE .....
 
 
UPDATE Maint.JobHistory SET FullBackupPath='G:\DB_BACKUP\LOG_BACKUP\', LogBackupPath='G:\DB_BACKUP\FULL_BACKUP' where JobNo=@JobNo

clipboard[5]

相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
相关文章
|
弹性计算 容灾 关系型数据库
PostgreSQL PITR 任意时间点恢复过程中如何手工得到recovery需要的下一个WAL文件名 - 默认情况下restore_command自动获取
标签 PostgreSQL , recovery , recovery.conf , restore_command , timeline , 时间线 , next wal , PITR , 时间点恢复 背景 PostgreSQL数据库支持PITR时间点恢复。默认情况下,只需要配置目标是时间点,resotre_command即可,PG会自动调用resotre_command去找需要的WA
1530 0
|
Oracle 关系型数据库
Oracle归档目录修改的坑,请留意
Oracle归档目录修改的坑,请留意
186 0
Oracle归档目录修改的坑,请留意
rac 归档路径设置
rac 归档路径设置
144 0
|
Oracle 关系型数据库 数据库
Oracle 数据库 - 使用UEStudio修改dmp文件版本号,解决imp命令恢复的数据库与dmp本地文件版本号不匹配导致的导入失败问题,“ORACLE error 12547”问题处理
Oracle 数据库 - 使用UEStudio修改dmp文件版本号,解决imp命令恢复的数据库与dmp本地文件版本号不匹配导致的导入失败问题,“ORACLE error 12547”问题处理
866 0
Oracle 数据库 - 使用UEStudio修改dmp文件版本号,解决imp命令恢复的数据库与dmp本地文件版本号不匹配导致的导入失败问题,“ORACLE error 12547”问题处理
|
SQL 监控 数据库
YourSQLDba 配置&mdash;&mdash;修改备份路径
公司一直使用YourSQLDba做本地备份,磁带机将本地备份文件上带做异地容灾备份。近期整理、验证备份时发现本地备份目录命名五花八门 其中有历史原因,也有无规划化的缘故,看着这些五花八门的目录,越看越不顺眼。
1004 0
|
Oracle 关系型数据库 数据库
|
网络安全 Windows Linux