Date created: Sunday, January 20, 2013 4:44:41 PM. Last modified: Sunday, January 20, 2013 4:46:34 PM

Backup pfSense 2.x via HTTPS into CVS (for rancid)

Backup pfSense 2.x xml config file over HTTPS. Submit the xml file into a CVS repo, for use with rancid;

#!/bin/bash
# backup up a pfsense config and put it into a cvs
# depends on: curl, cvs

CVSROOT=/var/lib/cvs
export CVSROOT
CVSPROJ=pfsense

## HTTPS firewalls on port 8080...

DEVICES="my-pfsense-device.fqdn.com \
another-pfsense-device.fqdn.com \
3rd-pfsense-device.fqdn.com"

PROTO=https
PORT=8080
USER=rancid
PASS=rancidpassword

for DEVICE in $DEVICES; do
  TMPDIR=/tmp/$$
  mkdir $TMPDIR
  cd $TMPDIR
  cvs -Q co $CVSPROJ
  cd $CVSPROJ
  # Login
  curl -k -o /dev/null --cookie cjar --cookie-jar cjar --data "login=Login" --data "usernamefld=$USER" --data "passwordfld=$PASS" --location $PROTO://$DEVICE:$PORT/index.php
  # Download config file
  curl -k -o config-$DEVICE.xml --cookie cjar --cookie-jar cjar --data "Submit=download" --data "donotbackuprrd=yes" --location $PROTO://$DEVICE:$PORT/diag_backup.php
  # Log out
  curl -k -o /dev/null --cookie cjar --cookie-jar cjar --location $PROTO://$DEVICE:$PORT/index.php?logout
  echo  config-$DEVICE.xml
  NOW=`date +%Y-%m-%d@%H:%M:%S`
  cvs -Q commit -m "backup of $DEVICE config.xml [$NOW]"
  cvs -Q import -m "backup of $DEVICE config.xml [$NOW]" voswall configs release
  cd /tmp
  rm -rf $TMPDIR
done 

Previous page: AS & IP Lookup
Next page: Cisco Command Repeat