Notify about backup with mail
This commit is contained in:
+32
-1
@@ -47,6 +47,37 @@ Run once, by hand, on the server:
|
||||
# create a remote named "scaleway", type S3, matching your Scaleway
|
||||
# Object Storage credentials and region
|
||||
```
|
||||
7. Set up email notifications (optional — skip this if you don't want mail):
|
||||
Install a mail transport agent (choose one):
|
||||
```bash
|
||||
# Option A: mailutils (Debian/Ubuntu) — includes /usr/bin/mail
|
||||
apt install -y mailutils
|
||||
|
||||
# Option B: msmtp + mailutils (lightweight, no full MTA)
|
||||
apt install -y msmtp msmtp-mta mailutils
|
||||
```
|
||||
Configure the recipient address. Either set `MAIL_TO` in the environment
|
||||
(`/etc/environment` or the cron file itself) or edit `borg-backup.sh`:
|
||||
```
|
||||
MAIL_TO="${MAIL_TO:-you@example.com}"
|
||||
```
|
||||
If using `msmtp`, configure `/etc/msmtprc`:
|
||||
```
|
||||
# /etc/msmtprc — example for Gmail SMTP
|
||||
defaults
|
||||
auth on
|
||||
tls on
|
||||
tls_trust_file /etc/ssl/certs/ca-certificates.crt
|
||||
|
||||
account default
|
||||
host smtp.gmail.com
|
||||
port 587
|
||||
from backup-sender@gmail.com
|
||||
user backup-sender@gmail.com
|
||||
password your-app-password
|
||||
```
|
||||
The script auto-detects which command is available (`mail` → `sendmail` → `msmtp`)
|
||||
and falls back silently if none is present — notifications are never fatal.
|
||||
|
||||
## 2. Deploying the Scripts
|
||||
|
||||
@@ -62,9 +93,9 @@ chmod +x /opt/backup-agent/dump_db.sh
|
||||
## 3. Scheduling
|
||||
|
||||
Add a cron entry to run the backup daily, off-peak:
|
||||
|
||||
```
|
||||
# /etc/cron.d/borg-backup
|
||||
MAIL_TO=you@example.com
|
||||
30 2 * * * root /opt/backup-agent/borg-backup.sh >> /var/log/borg/cron.log 2>&1
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user