mirror of
https://github.com/jkaninda/mysql-bkup.git
synced 2025-12-07 05:59:43 +01:00
doc: reviewed docs
This commit is contained in:
@@ -4,10 +4,20 @@ layout: default
|
||||
parent: How Tos
|
||||
nav_order: 12
|
||||
---
|
||||
Send Email or Telegram notifications on successfully or failed backup.
|
||||
|
||||
### Email
|
||||
To send out email notifications on failed or successfully backup runs, provide SMTP credentials, a sender and a recipient:
|
||||
# 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
|
||||
|
||||
```yaml
|
||||
services:
|
||||
@@ -23,25 +33,33 @@ services:
|
||||
- DB_NAME=database
|
||||
- DB_USERNAME=username
|
||||
- DB_PASSWORD=password
|
||||
- MAIL_HOST=
|
||||
## SMTP Configuration
|
||||
- MAIL_HOST=smtp.example.com
|
||||
- MAIL_PORT=587
|
||||
- MAIL_USERNAME=
|
||||
- MAIL_PASSWORD=!
|
||||
- MAIL_USERNAME=your-email@example.com
|
||||
- MAIL_PASSWORD=your-email-password
|
||||
- MAIL_FROM=Backup Jobs <backup@example.com>
|
||||
## Multiple recipients separated by a comma
|
||||
- MAIL_TO=me@example.com,team@example.com,manager@example.com
|
||||
- MAIL_SKIP_TLS=false
|
||||
## Time format for notification
|
||||
## Time format for notifications
|
||||
- TIME_FORMAT=2006-01-02 at 15:04:05
|
||||
## Backup reference, in case you want to identify every backup instance
|
||||
## Backup reference (e.g., database/cluster name or server name)
|
||||
- BACKUP_REFERENCE=database/Paris cluster
|
||||
networks:
|
||||
- web
|
||||
|
||||
networks:
|
||||
web:
|
||||
```
|
||||
|
||||
### Telegram
|
||||
---
|
||||
|
||||
## 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
|
||||
|
||||
```yaml
|
||||
services:
|
||||
@@ -57,41 +75,49 @@ services:
|
||||
- DB_NAME=database
|
||||
- DB_USERNAME=username
|
||||
- DB_PASSWORD=password
|
||||
## Telegram Configuration
|
||||
- TG_TOKEN=[BOT ID]:[BOT TOKEN]
|
||||
- TG_CHAT_ID=
|
||||
## Time format for notification
|
||||
- TG_CHAT_ID=your-chat-id
|
||||
## Time format for notifications
|
||||
- TIME_FORMAT=2006-01-02 at 15:04:05
|
||||
## Backup reference, in case you want to identify every backup instance
|
||||
## Backup reference (e.g., database/cluster name or server name)
|
||||
- BACKUP_REFERENCE=database/Paris cluster
|
||||
networks:
|
||||
- web
|
||||
|
||||
networks:
|
||||
web:
|
||||
```
|
||||
|
||||
### Customize notifications
|
||||
---
|
||||
|
||||
The title and body of the notifications can be tailored to your needs using Go templates.
|
||||
Template sources must be mounted inside the container in /config/templates:
|
||||
## Customize Notifications
|
||||
|
||||
- email.tmpl: Email notification template
|
||||
- telegram.tmpl: Telegram notification template
|
||||
- email-error.tmpl: Error notification template
|
||||
- telegram-error.tmpl: Error notification template
|
||||
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:
|
||||
|
||||
### Data
|
||||
- `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.
|
||||
|
||||
Here is a list of all data passed to the template:
|
||||
- `Database` : Database name
|
||||
- `StartTime`: Backup start time process
|
||||
- `EndTime`: Backup start time process
|
||||
- `Storage`: Backup storage
|
||||
- `BackupLocation`: Backup location
|
||||
- `BackupSize`: Backup size
|
||||
- `BackupReference`: Backup reference(eg: database/cluster name or server name)
|
||||
### Template Data
|
||||
|
||||
> email.template:
|
||||
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).
|
||||
|
||||
---
|
||||
|
||||
### Example Templates
|
||||
|
||||
#### `email.tmpl` (Successful Backup)
|
||||
|
||||
```html
|
||||
<h2>Hi,</h2>
|
||||
@@ -104,29 +130,29 @@ Here is a list of all data passed to the template:
|
||||
<li>Backup Storage: {{.Storage}}</li>
|
||||
<li>Backup Location: {{.BackupLocation}}</li>
|
||||
<li>Backup Size: {{.BackupSize}} bytes</li>
|
||||
<li>Backup Reference: {{.BackupReference}} </li>
|
||||
<li>Backup Reference: {{.BackupReference}}</li>
|
||||
</ul>
|
||||
<p>Best regards,</p>
|
||||
```
|
||||
|
||||
> telegram.template
|
||||
#### `telegram.tmpl` (Successful Backup)
|
||||
|
||||
```html
|
||||
✅ Database Backup Notification – {{.Database}}
|
||||
✅ Database Backup Notification – {{.Database}}
|
||||
Hi,
|
||||
Backup of the {{.Database}} database has been successfully completed on {{.EndTime}}.
|
||||
|
||||
Backup Details:
|
||||
- Database Name: {{.Database}}
|
||||
- Backup Start Time: {{.StartTime}}
|
||||
- Backup EndTime: {{.EndTime}}
|
||||
- Backup End Time: {{.EndTime}}
|
||||
- Backup Storage: {{.Storage}}
|
||||
- Backup Location: {{.BackupLocation}}
|
||||
- Backup Size: {{.BackupSize}} bytes
|
||||
- Backup Reference: {{.BackupReference}}
|
||||
```
|
||||
|
||||
> email-error.template
|
||||
#### `email-error.tmpl` (Failed Backup)
|
||||
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
@@ -140,16 +166,15 @@ Backup Details:
|
||||
<p>An error occurred during database backup.</p>
|
||||
<h3>Failure Details:</h3>
|
||||
<ul>
|
||||
<li>Error Message: {{.Error}}</li>
|
||||
<li>Date: {{.EndTime}}</li>
|
||||
<li>Backup Reference: {{.BackupReference}} </li>
|
||||
<li>Error Message: {{.Error}}</li>
|
||||
<li>Date: {{.EndTime}}</li>
|
||||
<li>Backup Reference: {{.BackupReference}}</li>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
> telegram-error.template
|
||||
|
||||
#### `telegram-error.tmpl` (Failed Backup)
|
||||
|
||||
```html
|
||||
🔴 Urgent: Database Backup Failure Notification
|
||||
@@ -159,4 +184,14 @@ Failure Details:
|
||||
|
||||
Error Message: {{.Error}}
|
||||
Date: {{.EndTime}}
|
||||
```
|
||||
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.
|
||||
Reference in New Issue
Block a user