Zuletzt aktiv 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.

Änderung 3d66ae210b9eb90da5ca841433b207c5a92385a3

opnsense_backup.sh Orginalformat
1#!/bin/bash
2set -eeuo pipefail
3
4# your configuration constants
5# generate key and secret on /ui/auth/user
6OPNSENSE_URL="https://opnsense.yournetwork.lan"
7OPNSENSE_KEY=""
8OPNSENSE_SECRET=""
9GPG_RECIPIENT=""
10BACKUP_DESTINATION="./backups"
11
12# general constants
13API_PATH="/api/core/backup/download/this"
14DATE_FORMAT="%Y_%m_%d_%H_%M"
15DATE=$(date +"${DATE_FORMAT}")
16BACKUP_FILENAME="${BACKUP_DESTINATION}/${DATE}.xml.gz.gpg"
17
18curl -k -f -u "${OPNSENSE_KEY}:${OPNSENSE_SECRET}" "${OPNSENSE_URL}${API_PATH}" \
19 | gzip -c - \
20 | gpg -e -r ${GPG_RECIPIENT} > ${BACKUP_FILENAME}
21
22echo "Written opnsense backup to ${BACKUP_FILENAME}"