Bacula

Bacula 不刪除文件

  • June 14, 2017

我對 bacula 有信心。我嘗試在工作後刪除文件,但它不起作用:(

部分我的conf:

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。我認為麻煩是許可。但不知道如何解決它

您需要將呼叫包裝在外殼中。只是簡單地呼叫rm /tmp/*.sql不會應用萬用字元,因此它會刪除/tmp/*.sql不存在的呼叫文件。正如您所說,也沒有警告-f 嘗試使用Client Run After Job = "/usr/bin/bash -c '/usr/bin/rm -f /tmp/*.sql'"它將在 bash 中執行您的命令,然後執行 globbing。

您可以將命令放入腳本中,並在控制台上輸出。

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 作業日誌中有一條“轉儲正常”行:

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
...

有了它,您可以檢查腳本的輸出以及它會出現錯誤的位置。

引用自:https://serverfault.com/questions/855712