Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
elphel-pbx
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Elphel
elphel-pbx
Commits
beef99ae
Commit
beef99ae
authored
Mar 22, 2026
by
Andrey Filippov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use authenticated SMTP for weekly PBX report
parent
3f59f976
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
5 deletions
+65
-5
pbx-backup.example
config/pbx-backup.example
+7
-1
2026-03-22-backup-and-reports.md
notes/2026-03-22-backup-and-reports.md
+5
-3
pbx-backup-report.sh
scripts/pbx-backup-report.sh
+53
-1
No files found.
config/pbx-backup.example
View file @
beef99ae
...
@@ -2,4 +2,10 @@ BACKUP_MOUNT=/mnt/pbx-backup
...
@@ -2,4 +2,10 @@ BACKUP_MOUNT=/mnt/pbx-backup
BACKUP_SUBDIR=elphel-pbx
BACKUP_SUBDIR=elphel-pbx
KEEP_COUNT=30
KEEP_COUNT=30
# BACKUP_MAILTO=andrey@elphel.com
# BACKUP_MAILTO=andrey@elphel.com
# REPORT_MAILTO=andrey@elphel.com
# REPORT_FROM=pbx@elphel.com
# REPORT_MAILTO=backups@elphel.com
# SMTP_HOST=mail.elphel.com
# SMTP_PORT=465
# SMTP_MODE=ssl
# SMTP_USER=pbx@elphel.com
# SMTP_PASS=...
notes/2026-03-22-backup-and-reports.md
View file @
beef99ae
...
@@ -13,7 +13,7 @@ Reason:
...
@@ -13,7 +13,7 @@ Reason:
Replace the old Sunday restart mail with:
Replace the old Sunday restart mail with:
-
scheduled local backup to the USB stick
-
scheduled local backup to the USB stick
-
optional short weekly email report from the backup job
-
optional short weekly email report from the backup job
using authenticated SMTP
## USB
## USB
...
@@ -44,7 +44,8 @@ The backup script is designed to capture the live state that is harder to recons
...
@@ -44,7 +44,8 @@ The backup script is designed to capture the live state that is harder to recons
-
systemd timer: daily at
`03:17`
-
systemd timer: daily at
`03:17`
-
retention: keep the newest
`30`
runs by default
-
retention: keep the newest
`30`
runs by default
-
optional weekly mail: set
`REPORT_MAILTO`
in
`/etc/default/pbx-backup`
-
optional weekly mail: set
`REPORT_FROM`
,
`REPORT_MAILTO`
,
`SMTP_USER`
, and
`SMTP_PASS`
in
`/etc/default/pbx-backup`
-
for better secret separation, the live PBX may place the weekly mail settings in
`/etc/default/pbx-backup-mail`
-
optional per-run mail: set
`BACKUP_MAILTO`
in
`/etc/default/pbx-backup`
-
optional per-run mail: set
`BACKUP_MAILTO`
in
`/etc/default/pbx-backup`
## Installed On Live PBX
## Installed On Live PBX
...
@@ -53,6 +54,7 @@ Installed on `192.168.1.16`:
...
@@ -53,6 +54,7 @@ Installed on `192.168.1.16`:
-
`/usr/local/sbin/pbx-backup.sh`
-
`/usr/local/sbin/pbx-backup.sh`
-
`/usr/local/sbin/pbx-backup-report.sh`
-
`/usr/local/sbin/pbx-backup-report.sh`
-
`/etc/default/pbx-backup`
-
`/etc/default/pbx-backup`
-
`/etc/default/pbx-backup-mail`
-
`/etc/systemd/system/pbx-backup.service`
-
`/etc/systemd/system/pbx-backup.service`
-
`/etc/systemd/system/pbx-backup.timer`
-
`/etc/systemd/system/pbx-backup.timer`
-
`/etc/systemd/system/pbx-backup-report.service`
-
`/etc/systemd/system/pbx-backup-report.service`
...
@@ -62,7 +64,7 @@ Installed on `192.168.1.16`:
...
@@ -62,7 +64,7 @@ Installed on `192.168.1.16`:
Verified on
`2026-03-22`
:
Verified on
`2026-03-22`
:
-
USB mounted at
`/mnt/pbx-backup`
-
USB mounted at
`/mnt/pbx-backup`
-
timer active and scheduled for the next daily run
-
timer active and scheduled for the next daily run
-
weekly report timer installed; mail delivery still depends on setting
`REPORT_MAILTO`
-
weekly report timer installed; mail delivery still depends on setting
the authenticated SMTP variables
-
manual backup run
`20260322_125605`
completed successfully
-
manual backup run
`20260322_125605`
completed successfully
-
resulting backup size: about
`81M`
-
resulting backup size: about
`81M`
...
...
scripts/pbx-backup-report.sh
View file @
beef99ae
...
@@ -7,10 +7,20 @@ if [[ -r /etc/default/pbx-backup ]]; then
...
@@ -7,10 +7,20 @@ if [[ -r /etc/default/pbx-backup ]]; then
# shellcheck disable=SC1091
# shellcheck disable=SC1091
.
/etc/default/pbx-backup
.
/etc/default/pbx-backup
fi
fi
if
[[
-r
/etc/default/pbx-backup-mail
]]
;
then
# shellcheck disable=SC1091
.
/etc/default/pbx-backup-mail
fi
BACKUP_MOUNT
=
"
${
BACKUP_MOUNT
:-
/mnt/pbx-backup
}
"
BACKUP_MOUNT
=
"
${
BACKUP_MOUNT
:-
/mnt/pbx-backup
}
"
BACKUP_SUBDIR
=
"
${
BACKUP_SUBDIR
:-$(
hostname
-s
)}
"
BACKUP_SUBDIR
=
"
${
BACKUP_SUBDIR
:-$(
hostname
-s
)}
"
REPORT_MAILTO
=
"
${
REPORT_MAILTO
:-}
"
REPORT_MAILTO
=
"
${
REPORT_MAILTO
:-}
"
REPORT_FROM
=
"
${
REPORT_FROM
:-${
SMTP_USER
:-
pbx
@elphel.com
}}
"
SMTP_HOST
=
"
${
SMTP_HOST
:-
mail
.elphel.com
}
"
SMTP_PORT
=
"
${
SMTP_PORT
:-
465
}
"
SMTP_MODE
=
"
${
SMTP_MODE
:-
ssl
}
"
SMTP_USER
=
"
${
SMTP_USER
:-}
"
SMTP_PASS
=
"
${
SMTP_PASS
:-}
"
HOSTNAME_SHORT
=
"
$(
hostname
-s
)
"
HOSTNAME_SHORT
=
"
$(
hostname
-s
)
"
ROOT_DIR
=
"
${
BACKUP_MOUNT
}
/
${
BACKUP_SUBDIR
}
"
ROOT_DIR
=
"
${
BACKUP_MOUNT
}
/
${
BACKUP_SUBDIR
}
"
...
@@ -54,6 +64,8 @@ if ! (cd "$LATEST_DIR" && sha256sum -c SHA256SUMS >/dev/null 2>&1); then
...
@@ -54,6 +64,8 @@ if ! (cd "$LATEST_DIR" && sha256sum -c SHA256SUMS >/dev/null 2>&1); then
fi
fi
SUBJECT
=
"[PBX weekly backup]
${
HOSTNAME_SHORT
}
${
BACKUP_TIME
}
"
SUBJECT
=
"[PBX weekly backup]
${
HOSTNAME_SHORT
}
${
BACKUP_TIME
}
"
BODY_FILE
=
"
$(
mktemp
)
"
trap
'rm -f "$BODY_FILE"'
EXIT
{
{
echo
"PBX weekly backup report"
echo
"PBX weekly backup report"
...
@@ -86,4 +98,44 @@ SUBJECT="[PBX weekly backup] ${HOSTNAME_SHORT} ${BACKUP_TIME}"
...
@@ -86,4 +98,44 @@ SUBJECT="[PBX weekly backup] ${HOSTNAME_SHORT} ${BACKUP_TIME}"
echo
echo
echo
"Recent backup log:"
echo
"Recent backup log:"
tail
-n
20
"
$BACKUP_LOG
"
tail
-n
20
"
$BACKUP_LOG
"
}
| mail
-s
"
$SUBJECT
"
"
$REPORT_MAILTO
"
}
>
"
$BODY_FILE
"
if
[[
-z
"
$SMTP_USER
"
||
-z
"
$SMTP_PASS
"
]]
;
then
echo
"SMTP credentials are not configured; skipping weekly PBX backup report."
exit
0
fi
REPORT_FROM
=
"
$REPORT_FROM
"
REPORT_MAILTO
=
"
$REPORT_MAILTO
"
SMTP_HOST
=
"
$SMTP_HOST
"
SMTP_PORT
=
"
$SMTP_PORT
"
SMTP_MODE
=
"
$SMTP_MODE
"
SMTP_USER
=
"
$SMTP_USER
"
SMTP_PASS
=
"
$SMTP_PASS
"
REPORT_SUBJECT
=
"
$SUBJECT
"
REPORT_BODY_FILE
=
"
$BODY_FILE
"
python3 -
<<
'
PY
'
import os
import smtplib
from email.message import EmailMessage
host = os.environ["SMTP_HOST"]
port = int(os.environ["SMTP_PORT"])
mode = os.environ["SMTP_MODE"].lower()
user = os.environ["SMTP_USER"]
password = os.environ["SMTP_PASS"]
mail_to = os.environ["REPORT_MAILTO"]
mail_from = os.environ["REPORT_FROM"]
subject = os.environ["REPORT_SUBJECT"]
body_path = os.environ["REPORT_BODY_FILE"]
msg = EmailMessage()
msg["Subject"] = subject
msg["From"] = mail_from
msg["To"] = mail_to
with open(body_path, "r", encoding="utf-8") as f:
msg.set_content(f.read())
if mode == "starttls":
with smtplib.SMTP(host, port) as s:
s.ehlo()
s.starttls()
s.ehlo()
s.login(user, password)
s.send_message(msg)
else:
with smtplib.SMTP_SSL(host, port) as s:
s.login(user, password)
s.send_message(msg)
PY
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment