Last active 1747499118

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.

adridoesthings's Avatar adridoesthings revised this gist 1747499118. Go to revision

1 file changed, 22 insertions

opnsense_backup.sh(file created)

@@ -0,0 +1,22 @@
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}"
Newer Older