| 1 | #!/bin/bash |
| 2 | set -eeuo pipefail |
| 3 | |
| 4 | # your configuration constants |
| 5 | # generate key and secret on /ui/auth/user |
| 6 | OPNSENSE_URL="https://opnsense.yournetwork.lan" |
| 7 | OPNSENSE_KEY="" |
| 8 | OPNSENSE_SECRET="" |
| 9 | GPG_RECIPIENT="" |
| 10 | BACKUP_DESTINATION="./backups" |
| 11 | |
| 12 | # general constants |
| 13 | API_PATH="/api/core/backup/download/this" |
| 14 | DATE_FORMAT="%Y_%m_%d_%H_%M" |
| 15 | DATE=$(date +"${DATE_FORMAT}") |
| 16 | BACKUP_FILENAME="${BACKUP_DESTINATION}/${DATE}.xml.gz.gpg" |
| 17 | |
| 18 | curl -k -f -u "${OPNSENSE_KEY}:${OPNSENSE_SECRET}" "${OPNSENSE_URL}${API_PATH}" \ |
| 19 | | gzip -c - \ |
| 20 | | gpg -e -r ${GPG_RECIPIENT} > ${BACKUP_FILENAME} |
| 21 | |
| 22 | echo "Written opnsense backup to ${BACKUP_FILENAME}" |
adridoesthings / Opnsense config backup script
Last active 6 months ago
An opnsense config backup script which gzip's the config file and encrypts it with gpg. Just change the first variables to your configuration specific. Then you can run this script with cronjob for example.
Revision 3d66ae210b9eb90da5ca841433b207c5a92385a3
Comments 0
Log in to leave a comment