Automated pfSense Backups

February 29, 2012 by Ed
Tags: pfsense, python

Due to some hardware failures, I recently replaced my home-grown pfSense router with an off the shelf, pre-built package from Netgate. Installation and setup were quick and painless, but I quickly realized I didn't have a backup of my previous configuration. After setting things up as best I could from memory, I decided to make sure this didn't happen again.

Python to the Rescue

After some searching online, I came up with a solution using a few built-in Python modules (urllib/urllib2/cookielib) to authenticate with the pfSense system and then request a backup. The response is then saved to a file. I added a quick cron job and now I have nightly backups of my pfSense configuration.

I polished things up a bit and posted the code to GitHub. I hope this helps someone avoid the mistake I made of not keeping regular backups.

Update (2013-08-16): Accepted a pull request from darksoul42 to allow you to specify the output file.