#!/usr/bin/bash# Change API key and secret, number of days to keep backups, the path to your backups and the hostname for your firewallkey="redacted"secret="redacted"daystokeep=90destination="backup/path"fwhost="opnsense.hostnameredacted.com"date=$(date +%Y-%m-%d)result=$(/usr/bin/curl -I -s -k -u "$key":"$secret" https://$fwhost/api/core/backup/download/this | head -1)if [[ $result != *"200"* ]]; then echo "Result of the HTTP request is $result" exit 1 fi /usr/bin/curl -s -k -u "$key":"$secret" https://$fwhost/api/core/backup/download/this > $fwhost-config-$date.xml error=$?
./opnsense_backup_v2API.shResult of the HTTP request is HTTP/2 500
#!/bin/bashKEY="partiallyredacted6Raif/mEENSbm8"SECRET="partiallyredacted6RaifsInpBlickOeUCZcf"HOST="opnsense.redacted.com"PATHCONFIG="/Downloads/opnsense"DATE=$(date +%Y%m%d)curl -u "${KEY}":"${SECRET}" https://"${HOST}"/api/core/backup/download/this --create-dirs -o "$PATHCONFIG"/opnsense-config-"${DATE}".xml
❯ cat opnsense-config-20240726.xml{"errorMessage":"Unexpected error, check log for details"}%
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Host opnsense.redacted.com:443 was resolved.* IPv6: (none)* IPv4: [myIP]* Trying [myIP]:443...* Connected to opnsense.redacted.com (myIP) port 443* ALPN: curl offers h2,http/1.1* (304) (OUT), TLS handshake, Client hello (1):} [327 bytes data]* CAfile: /etc/ssl/cert.pem* CApath: none* (304) (IN), TLS handshake, Server hello (2):{ [122 bytes data]* (304) (IN), TLS handshake, Unknown (8):{ [19 bytes data]* (304) (IN), TLS handshake, Certificate (11):{ [2829 bytes data]* (304) (IN), TLS handshake, CERT verify (15):{ [520 bytes data]* (304) (IN), TLS handshake, Finished (20):{ [36 bytes data]* (304) (OUT), TLS handshake, Finished (20):} [36 bytes data]* SSL connection using TLSv1.3 / AEAD-CHACHA20-POLY1305-SHA256 / [blank] / UNDEF* ALPN: server accepted h2* Server certificate:* subject: CN=*.redacted.com* start date: Jul 10 13:02:21 2024 GMT* expire date: Oct 8 13:02:20 2024 GMT* subjectAltName: host "opnsense.redacted.com" matched cert's "*.redacted.com"* issuer: C=US; O=Let's Encrypt; CN=R10* SSL certificate verify ok.* using HTTP/2* Server auth using Basic with user 'partiallyredacted6Raif/mEENSbm8'* [HTTP/2] [1] OPENED stream for https://opnsense.redacted.com/api/core/backup/download/this* [HTTP/2] [1] [:method: GET]* [HTTP/2] [1] [:scheme: https]* [HTTP/2] [1] [:authority: opnsense.redacted.com]* [HTTP/2] [1] [:path: /api/core/backup/download/this]* [HTTP/2] [1] [authorization: Basic K3FpcmNSOUZ2YXlKOWUrOTJTNVJaZUZucW1ETY2Y=]* [HTTP/2] [1] [user-agent: curl/8.7.1]* [HTTP/2] [1] [accept: */*]> GET /api/core/backup/download/this HTTP/2> Host: opnsense.redacted.com> Authorization: Basic K3FpcmNSOUZ2YXlKOWUrOTJTNVJaZUZucW1ET0UNaY2Y=> User-Agent: curl/8.7.1> Accept: */*>* Request completely sent off< HTTP/2 500< set-cookie: PHPSESSID=3b69be9b49af90e42a7a16b3713f9546; path=/; secure; HttpOnly< expires: Thu, 19 Nov 1981 08:52:00 GMT< cache-control: no-store, no-cache, must-revalidate< pragma: no-cache< content-type: application/json;charset=utf-8< strict-transport-security: max-age=31536000< date: Fri, 26 Jul 2024 10:49:06 GMT< server: OPNsense<{ [58 bytes data]100 58 0 58 0 0 865 0 --:--:-- --:--:-- --:--:-- 878* Connection #0 to host opnsense.redacted.com left intact
https://github.com/opnsense/core/commit/897d3cce3# opnsense-patch 897d3cce3Cheers,Franco
Thanks, will be hotfixed on Monday.Cheers,Franco
[26-Jul-2024 14:27:41 America/New_York] ArgumentCountError: Too few arguments to function OPNsense\Mvc\Response::setContentType(), 1 passed in /usr/local/opnsense/mvc/app/controllers/OPNsense/Core/Api/BackupController.php on line 200 and exactly 2 expected in /usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Response.php:64Stack trace:#0 /usr/local/opnsense/mvc/app/controllers/OPNsense/Core/Api/BackupController.php(200): OPNsense\Mvc\Response->setContentType('application/oct...')#1 /usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Dispatcher.php(165): OPNsense\Core\Api\BackupController->downloadAction('this')#2 /usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Router.php(156): OPNsense\Mvc\Dispatcher->dispatch(Object(OPNsense\Mvc\Request), Object(OPNsense\Mvc\Response), Object(OPNsense\Mvc\Session))#3 /usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Router.php(139): OPNsense\Mvc\Router->performRequest(Object(OPNsense\Mvc\Dispatcher))#4 /usr/local/opnsense/www/api.php(36): OPNsense\Mvc\Router->routeRequest('/api/core/backu...', Array)#5 {main}
#!/bin/bash# Since we need curl let's see if it is installedif cmd=$(command -v curl); then CURL=$cmdelse echo "$(date "+[%Y-%m-%d - %H:%M:%S%p]"): ERROR: Required binary curl is missing, please install it" > $LOG 2>&1 exit 1fi# Slack notification functionnotify () { message=$1 curl -s https://api.pushover.net/1/messages.json -d "token=${apitoken}&user=${userkey}&title=OPNSense%20Backup&message=${message}×tamp=${ts}&device=${device}" echo "$message" | mailx -r opnsense-backup@domain.com -s "OPNsense Backup" user@domain.com}# VariablesPINGHOST=192.168.xx.1HOST=$PINGHOSTPFPATH=/mnt/scripts/opnsensets=$(date +%s)# api access# Backup userkey="redacted"secret="redacted"# pushover settingsuserkey="redacted"apitoken="redacted"device="redacted"# Check to make sure firewall is upping -c 1 -W 5 $PINGHOST &>/dev/nullif [ $? -ne 0 ] ; then echo "$PINGHOST is down! bailing" notify "$PINGHOST is down! Check to make sure firewall is online" exitfi# Clean up old filesfind $PFPATH -name "*.xml" -mtime +7 -exec rm -rf {} \;# Download the config# Pre 23.7.8, this is now native in the API#/usr/bin/curl -k -u "$key":"$secret" https://$HOST/api/backup/backup/download -o $PFPATH/$(/bin/date +%Y%m%d).xml/usr/bin/curl -k -u "$key":"$secret" https://$HOST/api/core/backup/download/this -o $PFPATH/$(/bin/date +%Y%m%d).xml# Check if the configuration is the right size...XML_CHECK=$(grep -c "?xml" $PFPATH/`date +%Y%m%d`.xml)SIZE=$(stat -c %s $PFPATH/`date +%Y%m%d`.xml)# File must be zero size...if [ $SIZE -eq 0 ]; then notify "Configuration download was ZERO bytes, check the backup process!" exitfiif [ $XML_CHECK -eq 0 ]; then notify "Configuration download did not meet expected XML format, check the backup process!" exitfinotify "Backup of Firewall completed on $(date)"