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
3f59f976
Commit
3f59f976
authored
Mar 22, 2026
by
Andrey Filippov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add weekly PBX backup report
parent
c9d9031d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
129 additions
and
8 deletions
+129
-8
pbx-backup.example
config/pbx-backup.example
+2
-1
2026-03-22-backup-and-reports.md
notes/2026-03-22-backup-and-reports.md
+10
-2
pbx-backup-report.sh
scripts/pbx-backup-report.sh
+89
-0
pbx-backup.sh
scripts/pbx-backup.sh
+8
-5
pbx-backup-report.service
systemd/pbx-backup-report.service
+9
-0
pbx-backup-report.timer
systemd/pbx-backup-report.timer
+11
-0
No files found.
config/pbx-backup.example
View file @
3f59f976
BACKUP_MOUNT=/mnt/pbx-backup
BACKUP_SUBDIR=elphel-pbx
KEEP_COUNT=30
# MAILTO=andrey@elphel.com
# BACKUP_MAILTO=andrey@elphel.com
# REPORT_MAILTO=andrey@elphel.com
notes/2026-03-22-backup-and-reports.md
View file @
3f59f976
...
...
@@ -13,7 +13,7 @@ Reason:
Replace the old Sunday restart mail with:
-
scheduled local backup to the USB stick
-
optional short email report from the backup job
-
optional short
weekly
email report from the backup job
## USB
...
...
@@ -44,29 +44,37 @@ The backup script is designed to capture the live state that is harder to recons
-
systemd timer: daily at
`03:17`
-
retention: keep the newest
`30`
runs by default
-
optional mail: set
`MAILTO`
in
`/etc/default/pbx-backup`
-
optional weekly mail: set
`REPORT_MAILTO`
in
`/etc/default/pbx-backup`
-
optional per-run mail: set
`BACKUP_MAILTO`
in
`/etc/default/pbx-backup`
## Installed On Live PBX
Installed on
`192.168.1.16`
:
-
`/usr/local/sbin/pbx-backup.sh`
-
`/usr/local/sbin/pbx-backup-report.sh`
-
`/etc/default/pbx-backup`
-
`/etc/systemd/system/pbx-backup.service`
-
`/etc/systemd/system/pbx-backup.timer`
-
`/etc/systemd/system/pbx-backup-report.service`
-
`/etc/systemd/system/pbx-backup-report.timer`
-
`/etc/fstab`
entry for
`/mnt/pbx-backup`
Verified on
`2026-03-22`
:
-
USB mounted at
`/mnt/pbx-backup`
-
timer active and scheduled for the next daily run
-
weekly report timer installed; mail delivery still depends on setting
`REPORT_MAILTO`
-
manual backup run
`20260322_125605`
completed successfully
-
resulting backup size: about
`81M`
## Repo Artifacts
-
`scripts/pbx-backup.sh`
-
`scripts/pbx-backup-report.sh`
-
`config/pbx-backup.example`
-
`systemd/pbx-backup.service`
-
`systemd/pbx-backup.timer`
-
`systemd/pbx-backup-report.service`
-
`systemd/pbx-backup-report.timer`
## Notes
...
...
scripts/pbx-backup-report.sh
0 → 100644
View file @
3f59f976
#!/bin/bash
set
-euo
pipefail
umask
077
if
[[
-r
/etc/default/pbx-backup
]]
;
then
# shellcheck disable=SC1091
.
/etc/default/pbx-backup
fi
BACKUP_MOUNT
=
"
${
BACKUP_MOUNT
:-
/mnt/pbx-backup
}
"
BACKUP_SUBDIR
=
"
${
BACKUP_SUBDIR
:-$(
hostname
-s
)}
"
REPORT_MAILTO
=
"
${
REPORT_MAILTO
:-}
"
HOSTNAME_SHORT
=
"
$(
hostname
-s
)
"
ROOT_DIR
=
"
${
BACKUP_MOUNT
}
/
${
BACKUP_SUBDIR
}
"
if
[[
-z
"
$REPORT_MAILTO
"
]]
;
then
echo
"REPORT_MAILTO is not configured; skipping weekly PBX backup report."
exit
0
fi
if
!
command
-v
mail
>
/dev/null 2>&1
;
then
echo
"mail command is not available"
>
&2
exit
1
fi
if
!
mountpoint
-q
"
$BACKUP_MOUNT
"
;
then
mount
"
$BACKUP_MOUNT
"
fi
LATEST_LINK
=
"
${
ROOT_DIR
}
/latest"
if
[[
!
-L
"
$LATEST_LINK
"
]]
;
then
echo
"Latest backup link
${
LATEST_LINK
}
is missing"
>
&2
exit
1
fi
LATEST_DIR
=
"
$(
readlink
-f
"
$LATEST_LINK
"
)
"
RUN_NAME
=
"
$(
basename
"
$LATEST_DIR
"
)
"
BACKUP_LOG
=
"
${
LATEST_DIR
}
/backup.log"
MANIFEST
=
"
${
LATEST_DIR
}
/manifest.tsv"
SHA256SUMS
=
"
${
LATEST_DIR
}
/SHA256SUMS"
if
[[
!
-d
"
$LATEST_DIR
"
||
!
-f
"
$BACKUP_LOG
"
||
!
-f
"
$MANIFEST
"
||
!
-f
"
$SHA256SUMS
"
]]
;
then
echo
"Backup metadata is incomplete under
${
LATEST_DIR
}
"
>
&2
exit
1
fi
BACKUP_SIZE
=
"
$(
du
-sh
"
$LATEST_DIR
"
|
awk
'{print $1}'
)
"
BACKUP_TIME
=
"
$(
date
-d
"
${
RUN_NAME
:0:8
}
${
RUN_NAME
:9:2
}
:
${
RUN_NAME
:11:2
}
:
${
RUN_NAME
:13:2
}
"
'+%Y-%m-%d %H:%M:%S %Z'
2>/dev/null
||
echo
"
$RUN_NAME
"
)
"
LAST_LOG_LINE
=
"
$(
tail
-n
1
"
$BACKUP_LOG
"
)
"
HASHSUM_STATUS
=
"OK"
if
!
(
cd
"
$LATEST_DIR
"
&&
sha256sum
-c
SHA256SUMS
>
/dev/null 2>&1
)
;
then
HASHSUM_STATUS
=
"FAILED"
fi
SUBJECT
=
"[PBX weekly backup]
${
HOSTNAME_SHORT
}
${
BACKUP_TIME
}
"
{
echo
"PBX weekly backup report"
echo
echo
"Host:
${
HOSTNAME_SHORT
}
"
echo
"Latest backup:
${
RUN_NAME
}
"
echo
"Backup time:
${
BACKUP_TIME
}
"
echo
"Backup location:
${
LATEST_DIR
}
"
echo
"Backup size:
${
BACKUP_SIZE
}
"
echo
"Integrity check:
${
HASHSUM_STATUS
}
"
echo
"Last log line:
${
LAST_LOG_LINE
}
"
echo
echo
"Included data:"
echo
"- MySQL dumps: asterisk, asteriskcdrdb"
echo
"- /etc/asterisk and /etc/freepbx.conf"
echo
"- voicemail, call recordings, custom sounds, music-on-hold"
echo
"- PBX host config: fail2ban, network, firewall whitelist, postfix"
echo
echo
"Quick restore outline:"
echo
"1. Reinstall Debian 12 and FreePBX/Asterisk on replacement hardware."
echo
"2. Clone repo: git@git.elphel.com:Elphel/elphel-pbx.git"
echo
"3. Mount USB stick at
${
BACKUP_MOUNT
}
."
echo
"4. Use the latest run under
${
ROOT_DIR
}
."
echo
"5. Restore MySQL from mysql-asterisk.sql.gz and mysql-asteriskcdrdb.sql.gz."
echo
"6. Restore etc-asterisk.tgz, asterisk-state.tgz, and host-config.tgz."
echo
"7. Reload FreePBX/Asterisk and retest inbound/outbound calls."
echo
echo
"Key files in latest backup:"
sed
's/^/- /'
"
$MANIFEST
"
echo
echo
"Recent backup log:"
tail
-n
20
"
$BACKUP_LOG
"
}
| mail
-s
"
$SUBJECT
"
"
$REPORT_MAILTO
"
scripts/pbx-backup.sh
View file @
3f59f976
...
...
@@ -11,7 +11,7 @@ fi
BACKUP_MOUNT
=
"
${
BACKUP_MOUNT
:-
/mnt/pbx-backup
}
"
BACKUP_SUBDIR
=
"
${
BACKUP_SUBDIR
:-$(
hostname
-s
)}
"
KEEP_COUNT
=
"
${
KEEP_COUNT
:-
30
}
"
MAILTO
=
"
${
MAILTO
:-}
"
BACKUP_MAILTO
=
"
${
BACKUP_
MAILTO
:-}
"
HOSTNAME_SHORT
=
"
$(
hostname
-s
)
"
STAMP
=
"
$(
date
+%Y%m%d_%H%M%S
)
"
ROOT_DIR
=
"
${
BACKUP_MOUNT
}
/
${
BACKUP_SUBDIR
}
"
...
...
@@ -27,10 +27,13 @@ send_report() {
finish
()
{
local
rc
=
$?
if
[[
$rc
-eq
0
]]
;
then
send_report
"[PBX backup]
${
HOSTNAME_SHORT
}
OK
${
STAMP
}
"
else
send_report
"[PBX backup]
${
HOSTNAME_SHORT
}
FAILED
${
STAMP
}
"
if
[[
-n
"
$BACKUP_MAILTO
"
]]
;
then
MAILTO
=
"
$BACKUP_MAILTO
"
if
[[
$rc
-eq
0
]]
;
then
send_report
"[PBX backup]
${
HOSTNAME_SHORT
}
OK
${
STAMP
}
"
else
send_report
"[PBX backup]
${
HOSTNAME_SHORT
}
FAILED
${
STAMP
}
"
fi
fi
exit
"
$rc
"
}
...
...
systemd/pbx-backup-report.service
0 → 100644
View file @
3f59f976
[Unit]
Description=Weekly PBX backup summary report
Wants=network-online.target
After=network-online.target local-fs.target
[Service]
Type=oneshot
User=root
ExecStart=/usr/local/sbin/pbx-backup-report.sh
systemd/pbx-backup-report.timer
0 → 100644
View file @
3f59f976
[Unit]
Description=Weekly PBX backup summary report
[Timer]
OnCalendar=Sun *-*-* 07:15:00
RandomizedDelaySec=15m
Persistent=true
Unit=pbx-backup-report.service
[Install]
WantedBy=timers.target
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