2024-10-09 22:31:52 +02:00
---
title: Receive notifications
layout: default
parent: How Tos
nav_order: 12
---
2025-01-13 14:56:08 +01:00
# Receive Notifications
You can configure the system to send email or Telegram notifications when a backup succeeds or fails.
This section explains how to set up and customize notifications.
---
## Email Notifications
To send email notifications, provide SMTP credentials, a sender address, and recipient addresses. Notifications will be sent for both successful and failed backup runs.
### Example: Email Notification Configuration
2024-10-09 22:31:52 +02:00
```yaml
services:
mysql-bkup:
image: jkaninda/mysql-bkup
container_name: mysql-bkup
command: backup
volumes:
- ./backup:/backup
environment:
- DB_PORT=3306
- DB_HOST=mysql
- DB_NAME=database
- DB_USERNAME=username
- DB_PASSWORD=password
2025-01-13 14:56:08 +01:00
## SMTP Configuration
- MAIL_HOST=smtp.example.com
2024-10-09 22:31:52 +02:00
- MAIL_PORT=587
2025-01-13 14:56:08 +01:00
- MAIL_USERNAME=your-email@example .com
- MAIL_PASSWORD=your-email-password
2024-10-12 10:47:14 +02:00
- MAIL_FROM=Backup Jobs <backup@example .com>
## Multiple recipients separated by a comma
2024-10-09 22:31:52 +02:00
- MAIL_TO=me@example .com,team@example .com,manager@example .com
- MAIL_SKIP_TLS=false
2025-01-13 14:56:08 +01:00
## Time format for notifications
2024-10-10 04:14:42 +02:00
- TIME_FORMAT=2006-01-02 at 15:04:05
2025-01-13 14:56:08 +01:00
## Backup reference (e.g., database/cluster name or server name)
2024-10-10 04:14:42 +02:00
- BACKUP_REFERENCE=database/Paris cluster
2024-10-09 22:31:52 +02:00
networks:
- web
2025-01-13 14:56:08 +01:00
2024-10-09 22:31:52 +02:00
networks:
web:
```
2025-01-13 14:56:08 +01:00
---
## Telegram Notifications
To send Telegram notifications, provide your bot token and chat ID. Notifications will be sent for both successful and failed backup runs.
### Example: Telegram Notification Configuration
2024-10-09 22:31:52 +02:00
```yaml
services:
mysql-bkup:
image: jkaninda/mysql-bkup
container_name: mysql-bkup
command: backup
volumes:
- ./backup:/backup
environment:
- DB_PORT=3306
- DB_HOST=mysql
- DB_NAME=database
- DB_USERNAME=username
- DB_PASSWORD=password
2025-01-13 14:56:08 +01:00
## Telegram Configuration
2024-10-09 22:31:52 +02:00
- TG_TOKEN=[BOT ID]:[BOT TOKEN]
2025-01-13 14:56:08 +01:00
- TG_CHAT_ID=your-chat-id
## Time format for notifications
2024-10-10 04:14:42 +02:00
- TIME_FORMAT=2006-01-02 at 15:04:05
2025-01-13 14:56:08 +01:00
## Backup reference (e.g., database/cluster name or server name)
2024-10-10 04:14:42 +02:00
- BACKUP_REFERENCE=database/Paris cluster
2024-10-09 22:31:52 +02:00
networks:
- web
2025-01-13 14:56:08 +01:00
2024-10-09 22:31:52 +02:00
networks:
web:
```
2025-01-13 14:56:08 +01:00
---
## Customize Notifications
2024-10-09 22:31:52 +02:00
2025-01-13 14:56:08 +01:00
You can customize the title and body of notifications using Go templates. Template files must be mounted inside the container at `/config/templates` . The following templates are supported:
2024-10-09 22:31:52 +02:00
2025-01-13 14:56:08 +01:00
- `email.tmpl` : Template for successful email notifications.
- `telegram.tmpl` : Template for successful Telegram notifications.
- `email-error.tmpl` : Template for failed email notifications.
- `telegram-error.tmpl` : Template for failed Telegram notifications.
2024-10-09 22:31:52 +02:00
2025-01-13 14:56:08 +01:00
### Template Data
2024-10-09 22:38:07 +02:00
2025-01-13 14:56:08 +01:00
The following data is passed to the templates:
- `Database` : Database name.
- `StartTime` : Backup start time.
- `EndTime` : Backup end time.
- `Storage` : Backup storage type (e.g., local, S3, SSH).
- `BackupLocation` : Backup file location.
- `BackupSize` : Backup file size in bytes.
- `BackupReference` : Backup reference (e.g., database/cluster name or server name).
- `Error` : Error message (only for error templates).
---
2024-10-09 22:38:07 +02:00
2025-01-13 14:56:08 +01:00
### Example Templates
2024-10-09 22:31:52 +02:00
2025-01-13 14:56:08 +01:00
#### `email.tmpl` (Successful Backup)
2024-10-09 22:31:52 +02:00
```html
<h2>Hi,</h2>
<p>Backup of the {{.Database}} database has been successfully completed on {{.EndTime}}.</p>
<h3>Backup Details:</h3>
<ul>
2024-10-10 04:14:42 +02:00
<li>Database Name: {{.Database}}</li>
<li>Backup Start Time: {{.StartTime}}</li>
<li>Backup End Time: {{.EndTime}}</li>
<li>Backup Storage: {{.Storage}}</li>
<li>Backup Location: {{.BackupLocation}}</li>
<li>Backup Size: {{.BackupSize}} bytes</li>
2025-01-13 14:56:08 +01:00
<li>Backup Reference: {{.BackupReference}}</li>
2024-10-09 22:31:52 +02:00
</ul>
<p>Best regards,</p>
```
2025-01-13 14:56:08 +01:00
#### `telegram.tmpl` (Successful Backup)
2024-10-09 22:31:52 +02:00
```html
2025-01-13 14:56:08 +01:00
✅ Database Backup Notification – {{.Database}}
2024-10-09 22:31:52 +02:00
Hi,
Backup of the {{.Database}} database has been successfully completed on {{.EndTime}}.
Backup Details:
- Database Name: {{.Database}}
- Backup Start Time: {{.StartTime}}
2025-01-13 14:56:08 +01:00
- Backup End Time: {{.EndTime}}
2024-10-09 22:31:52 +02:00
- Backup Storage: {{.Storage}}
- Backup Location: {{.BackupLocation}}
- Backup Size: {{.BackupSize}} bytes
2024-10-10 04:14:42 +02:00
- Backup Reference: {{.BackupReference}}
```
2025-01-13 14:56:08 +01:00
#### `email-error.tmpl` (Failed Backup)
2024-10-10 04:14:42 +02:00
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>🔴 Urgent: Database Backup Failure Notification</title>
</head>
<body>
<h2>Hi,</h2>
<p>An error occurred during database backup.</p>
<h3>Failure Details:</h3>
<ul>
2025-01-13 14:56:08 +01:00
<li>Error Message: {{.Error}}</li>
<li>Date: {{.EndTime}}</li>
<li>Backup Reference: {{.BackupReference}}</li>
2024-10-10 04:14:42 +02:00
</ul>
</body>
</html>
2024-10-09 22:31:52 +02:00
```
2025-01-13 14:56:08 +01:00
#### `telegram-error.tmpl` (Failed Backup)
2024-10-09 22:31:52 +02:00
```html
🔴 Urgent: Database Backup Failure Notification
An error occurred during database backup.
Failure Details:
Error Message: {{.Error}}
Date: {{.EndTime}}
2025-01-13 14:56:08 +01:00
Backup Reference: {{.BackupReference}}
```
---
## Key Notes
- **SMTP Configuration**: Ensure your SMTP server supports TLS unless `MAIL_SKIP_TLS` is set to `true` .
- **Telegram Configuration**: Obtain your bot token and chat ID from Telegram.
- **Custom Templates**: Mount custom templates to `/config/templates` to override default notifications.
- **Time Format**: Use the `TIME_FORMAT` environment variable to customize the timestamp format in notifications.