Chapter 10. Logging

JSON

You can create a simple json logfile with PHPBU's json logger.

Example 10.1: json XML example

<!-- create a json logfile -->
<log type="json" target="backup/log.json"/>


Example 10.2: json JSON example

{"type": "json", "target": "backup/log.json"}


E-Mail

PHPBU uses SwiftMailer to send backup reports to one or more configured E-Mail-Addresses. If you just want to get notified if something went wrong, you can use the sendOnlyOnError option to not send any E-Mail on a successful backup.

Table 10.1. Capacity-Options

NameValueRequiredDefaultDescription
recipientsstringyes-List of emails separated by semicolon.
sendOnlyOnErrorstringnofalseSending reports only if something goes wrong.
subjectstringnoPHPBU Backup Report from $HOSTNAMEE-Mail subject of the backup report.
transportstringyes-SwiftMailer Transport that's used to send the E-Mail (mail, sendmail, smtp, null).
sender.mailstringphpbu@hostname-The sender E-Mail-Address
sender.namestringnoOS-UserThe sender name.
sender.namestringnoOS-UserThe sender name.
sendmail options    
sendmail.pathstringno-Path to local sendmail binary.
sendmail.optionsstringno-Sendmail options (e.g. -bs).
SMTP options    
smtp.portstringno25Port to use to connect to SMTP server.
smtp.hoststringno-SMTP hostname.
smtp.usernamestringno-The SMTP login.
smtp.passwordstringno-The SMTP password.
smtp.encryptionstringno-Type of encryption (e.g. ssl).


Example 10.3: mail XML example

<!-- use mail to keep up to date with you backup creation -->
<log type="mail">
  <option name="transport" value="mail"/>
  <option name="recipients" value="user.name@example.com"/>
</log>


Example 10.4: mail JSON example

{
  "type": "mail",
  "options": {
     "transport": "mail",
     "recipients": "user.name@example.com"
   }
}


Webhook

You can call a webhook and phpbu will send report data to the webhook.

Table 10.2. Webhook-Options

NameValueRequiredDefaultDescription
uristringno-URI to call
usernamestringno-Basic auth user name.
passwordstringno-Basic auth password.
methodstringnogetHTTP request method (get, post).
contentTypestringnoapplication/jsonPost method request body content type.
templatestringno-A template to use for the request body For example if you want to you xml over json.


Example 10.5: webhook XML example

<!-- call webhook -->
<log type="webhook">
  <option name="uri" value="http://example.com/hook"/>
</log>


Example 10.6: webhook JSON example

{
  "type": "webhook",
  "options": {
     "transport": "uri",
     "recipients": "http://example.com/hook"
   }
}


If you change the request method to post by default you will receive a request body in the following format.

Example 10.7: Default request body example

{
  "status": 0,
  "timestamp": 12783781381,
  "duration": 234.3402,
  "backupCount": 1,
  "backupFailed": 0,
  "errorCount": 0,
  "errors": [],
  "backups": [
    {
      "name":
      "status":
      "checks": {
          "executed": 1,
          "failed": 0,
      },
      "crypt": {
          "executed": 1,
          "skipped": 0,
          "failed": 0,
      },
      "syncs" => {
          "executed": 1,
          "skipped": 0,
          "failed": 0
      },
      "cleanup" => {
          "executed": 1,
          "skipped": 0,
          "failed": 0
      }
    }
  ]
}


If this format doesn't work for you, you can define your own request body with a template.

Example 10.8: Template example

<?xml version="1.0" encoding="UTF-8"?>
<report>
  <status>%status%</status>
  <date>%timestamp%</date>
  <backups>
    %%backup%%
    <backup>
      <name>%name%</name>
      <status>%status%</status>
    </backup>
    %%backup%%
  </backups>
  <errors>
    %%error%%
    <error class="%class%" message="%message%" file="%file%" line="%line%" />
    %%error%%
  </errors>
</report>


Please open a ticket on GitHub to suggest improvements to this page. Thanks!