docker-volume-backup/docs/NOTIFICATION-TEMPLATES.md
Mauro Molin 8dfdd14527
Added custom notification messages using text/template (#60)
* Added custom notification messages using text/template

* Change notification template path and removed automatic newline trim

* Added stats and changed structure of template params

* Stat file hotfix

* Embedded and fixed default notification templates


Fix

* Changed Output to LogOutput

* Changed stats integer to unsigned

* Bytes formatting in template func


fix

* Changed Archives to Storages

* Removed unecessary sleep for pruning leeway

* Set EndTime after pruning is completed

* Added custom notifications documentation

* Added 5s sleep in swarm test

* Fixed documentation

* Dockerfile copies all files in cmd/backup
2022-02-11 20:05:16 +01:00

2.5 KiB

Notification templates reference

In order to customize title and body of notifications you'll have to write a go template and mount it inside the /etc/dockervolumebackup/notifications.d/ directory.

Configuration, data about the backup run and helper functions will be passed to this template, this page documents them fully.

Data

Here is a list of all data passed to the template:

  • Config: this object holds the configuration that has been passed to the script. The field names are the name of the recognized environment variables converted in PascalCase. (e.g. BACKUP_STOP_CONTAINER_LABEL becomes BackupStopContainerLabel)
  • Error: the error that made the backup fail. Only available in the title_failure and body_failure templates
  • Stats: objects that holds stats regarding script execution. In case of an unsuccessful run, some information may not be available.
    • StartTime: time when the script started execution
    • EndTime: time when the backup has completed successfully (after pruning)
    • TookTime: amount of time it took for the backup to run. (equal to EndTime - StartTime)
    • LogOutput: full log of the application
    • Containers: object containing stats about the docker containers
      • All: total number of containers
      • ToStop: number of containers matched by the stop rule
      • Stopped: number of containers successfully stopped
      • StopErrors: number of containers that were unable to be stopped (equal to ToStop - Stopped)
    • BackupFile: object containing information about the backup file
      • Name: name of the backup file (e.g. backup-2022-02-11T01-00-00.tar.gz)
      • FullPath: full path of the backup file (e.g. /archive/backup-2022-02-11T01-00-00.tar.gz)
      • Size: size in bytes of the backup file
    • Storages: object that holds stats about each storage
      • Local, S3 or WebDAV:
        • Total: total number of backup files
        • Pruned: number of backup files that were deleted due to pruning rule
        • PruneErrors: number of backup files that were unable to be pruned

Functions

Some formatting functions are also available:

  • formatTime: formats a time object using RFC3339 format (e.g. 2022-02-11T01:00:00Z)
  • formatBytesBin: formats an amount of bytes using powers of 1024 (e.g. 7055258 bytes will be 6.7 MiB)
  • formatBytesDec: formats an amount of bytes using powers of 1000 (e.g. 7055258 bytes will be 7.1 MB)