使用 Hallengren 脚本指定不同的日志文件位置

She*_*rie 5 sql-server ola-hallengren

我很欣赏 Ola Hallengren 的剧本。作为 SQL Server 的新手,它们让我的生活变得更加轻松。谢谢哈伦格伦先生。

我有 5 个需要在不同时间备份的用户数据库,因此USER_DATABASES我没有使用,而是提供数据库名称。当我使用脚本创建存储过程时,我将输出文件目录指定为类似G:\Logs\Backups. 日志文件在那里,但最好在日志文件名中包含数据库名称,或者将日志文件路径作为参数传递。

我也在登录dbo.CommandLog。无需查看内部即可识别我正在查找的日志文件会很好。

有没有办法做到这一点,而不改变maintenance_solution.sql

我不喜欢修改的想法,因为当更新出来时,那些就会消失。对我来说,脚本非常复杂,因为我正在跟上 MS SQL 和 T-SQL 的步伐。

任何见解表示赞赏。

雪莉

Eri*_*ing 3

假设您有单独的作业来备份每个数据库,那么最好的选择是手动编辑。

坚果

不幸的是,根据这些令牌的实现方式,您只能在警报中引发数据库名称时获取数据库名称。

所有以“A-”开头的令牌都不能像一般信息令牌那样被调用。

Token   Description
(A-DBN) Database name. If the job is run by an alert, the database name value automatically replaces this token in the job step.
(A-SVR) Server name. If the job is run by an alert, the server name value automatically replaces this token in the job step.
(A-ERR) Error number. If the job is run by an alert, the error number value automatically replaces this token in the job step.
(A-SEV) Error severity. If the job is run by an alert, the error severity value automatically replaces this token in the job step.
(A-MSG) Message text. If the job is run by an alert, the message text value automatically replaces this token in the job step.
Run Code Online (Sandbox Code Playgroud)

如果可以的话,我确信他们最终会出现在 Ola 的代码中:

  BEGIN
    SET @TokenServer = '$' + '(SRVR)'
    SET @TokenJobID = '$' + '(JOBID)'
    SET @TokenStepID = '$' + '(STEPID)'
    SET @TokenDate = '$' + '(STRTDT)'
    SET @TokenTime = '$' + '(STRTTM)'
  END
Run Code Online (Sandbox Code Playgroud)

如果你试图粘住A-DBN绳子,任务就会失败。

$(ESCAPE_SQUOTE(SQLLOGDIR))\DatabaseBackup_$(ESCAPE_SQUOTE(JOBID))_$(ESCAPE_SQUOTE(STEPID))_$(ESCAPE_SQUOTE(STRTDT))_$(ESCAPE_SQUOTE(STRTTM))_$(ESCAPE_SQUOTE(A-DBN)).txt
Run Code Online (Sandbox Code Playgroud)

消息 无法开始执行步骤 1(原因:未找到变量 A-DBN)。这一步失败了。

希望这可以帮助!