#!/bin/bashKEY="api_key"SECRET="api_secret"HOST="opnsense_hostname"PATH="/path/to/backups"curl -s -k -u $KEY:$SECRET https://$HOST/api/backup/backup/download \ -o $PATH/opnsense-config-$(date +%Y%m%d).xmlfind $PATH/ -type f -name '*.xml' -mtime +30 -exec rm {} \;
#!/bin/bashKEY="api_key"SECRET="api_secret"HOST="opnsense_hostname"PATHCONFIG="/path/to/backups"DATE=`date +%Y%m%d`curl -s -u ${KEY}:${SECRET} https://${HOST}/api/backup/backup/download -o $PATHCONFIG/opnsense-config-${DATE}.xmlfind ${PATHCONFIG} -type f -name opnsense-config\*.xml -mtime +30 -delete
Do you know if is possible to request an encrypted backup using the APIs? (Passwords are in clear text!)
I took your script as an example and created a version which also encrypts the backups using GPG.You can find the script here:https://codeberg.org/SWEETGOOD/andersgood-opnsense-scripts/src/branch/main/backup-opnsense-via-api.shI also wrote a short blogpost in German with some explanations:https://andersgood.de/kurz-notiert/opnsense-per-api-verschluesseltes-backup-der-konfiguration-anlegenThanks to the TS for your work!
Just as a side note: 23.7.6 will offer a base component for config export through the API. I'm not sure where that leaves os-api-backup but it will probably be removed as it's likely redundant and practically unmaintained.Cheers,Franco