Bacula 不会删除文件

Bacula 不会删除文件

我有 bacula 的配置文件。我尝试在作业后删除文件,但没有用 :(

我的会议部分内容:

Job {
  Name = "spass.mysql"
  Type = Backup
  Level = Full
  Client = spass-fd
  RunScript {
    RunsWhen = Before
    FailJobOnError = No
    RunsOnClient = Yes
    Command = "/usr/bin/mysqldump -EB syspass --result-file /tmp/syspass-%i.sql"
  }
  Client Run After Job = "/usr/bin/rm -f /tmp/*.sql"
  Schedule = "WorkTimeEveryHour"
  Storage = File-spass
  Pool = spass
  FileSet="spass.mysql"
  Messages = Standard
  Priority = 10
  Write Bootstrap = "/var/spool/bacula/%c_%n_%e.bsr"
}

FileSet {
  Name = "spass.mysql"
  Include {
    Options {
      signature = MD5
      compression = GZIP
      wildfile = "*.sql"
    }
    Options {
      Exclude = yes
      RegexFile = ".*"
      RegexDir = ".*"
    }
    File = /tmp/
  }
}

在消息中这可以:

14-Jun 17:02 bnode10-dir JobId 364: Start Backup JobId 364, Job=spass.mysql.2017-06-14_17.02.09_10
14-Jun 17:02 bnode10-dir JobId 364: Using Device "FileStorage-spass" to write.
14-Jun 17:02 spass-fd JobId 364: shell command: run ClientBeforeJob "/usr/bin/mysqldump -EB syspass --result-file /tmp/syspass-364.sql"
14-Jun 17:02 bacula-sd JobId 364: Volume "spass0006" previously written, moving to end of data.
14-Jun 17:02 bacula-sd JobId 364: Ready to append to end of Volume "spass0006" size=995952259
14-Jun 17:02 spass-fd JobId 364: shell command: run ClientAfterJob "/usr/bin/rm -f /tmp/*.sql"
14-Jun 17:02 bacula-sd JobId 364: Elapsed time=00:00:01, Transfer rate=200.8 K Bytes/second
14-Jun 17:02 bnode10-dir JobId 364: Bacula bnode10-dir 5.2.13 (19Jan13):

如何修复?

PS. 我认为问题出在许可上。但不知道如何解决

答案1

您需要在 shell 中包装您的调用。只是简单的调用rm /tmp/*.sql不会应用通配符,因此它会删除/tmp/*.sql不存在的调用文件。正如您所述,也没有警告。-f 尝试使用Client Run After Job = "/usr/bin/bash -c '/usr/bin/rm -f /tmp/*.sql'"将在 bash 中运行您的命令,然后执行通配符。

答案2

您可以将命令放在脚本中并在控制台上输出。

Bacula 会将此输出写入您作业的日志文件中。

和你一样,我有一个保存数据库转储的工作。为此,我有一个在工作之前进行转储的脚本和一个在工作之后删除转储的脚本。

我的脚本的示例在作业之前进行转储(它在 powershell 中,但想法是一样的):

$dump="e:\scripts\save\sql\"+$bdd+'.my.sql'

   $process = Start-Process -FilePath "$($mysqldump_path)mysqldump.exe" 
                                    -ArgumentList "-u uuu -ppassword -B database_name" `
                                    -RedirectStandardOutput $dump `
                                    -Wait -WindowStyle hidden -PassThru `
                                    -RedirectStandardError $log_temp

        if ($process.ExitCode -eq 0){
            write-host "   Dump OK "
            $file=Get-Item $($dump)
            write-host ("   "+$file.Name+" : "+$file.Length+" octets : "+$file.LastWriteTime)
        }
        else {
            write-host "   Error Dump of $bdd "
            Get-Content $log_temp |  Out-file -FilePath $log_error -Append
            exit_script
        }

如果转储正常,我在 bacula 作业日志中会看到一行“dump ok”:

shell command: run ClientRunBeforeJob "c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -file E:\scripts\save\command_bacula.ps1"
ClientRunBeforeJob: start script : 06/13/2017 22:59:23
ClientRunBeforeJob:
ClientRunBeforeJob: ---- PostgreSQL ----
ClientRunBeforeJob: Dump bdd1
ClientRunBeforeJob:    Dump OK
...

有了它,您可以检查脚本的输出以及出现错误的位置。

相关内容