Last modified at 5/11/2016 1:29 PM by Koen Zomers

​pfSense contains easy to use backup/restore functionality which you can utilize to create one file with all the pfSense server settings in it. When restoring the configuration using this backed up file on another pfSense server, it will fully configure this server on the fly. Ideal to use when migrating servers or if your server has crashed. Just install a clean pfSense server, restore the config file and you're done.

This backup and restore function can be reached through the pfSense web UI by going to Diagnostics -> Backup/restore.

pfSense-Automate-Backup-BackupMenuOption.png 

Once at the Diagnostics: Backup/restore screen, with one click on the button "Download configuration" the configuration can be downloaded in one XML file to your machine so you can back it up.

pfSense-Automate-Backup-BackupSection.png 

Now wouldn't it be nice if we could automate this backup process so we don't have to look at it anymore? You're probably thinking now: "someone MUST have thought about that before and this MUST be available already", right? Right! There is a package available via the System -> Packages menu which is called "AutoConfigBackup" and does just that. HOWEVER, when looking at the package description, it should get clear to you now why I created a custom tool to perform automated backups and why I'm writing this article:

pfSense-Automate-Backup-BackupPackage.png
It is only available for paying pfSense customers with a Premium support contract. How unfortunate. So after forgetting to backup my pfSense firewall config a while and ending up in a crashed server situation loosing all recent changes and RRD traffic statistics, I decided to write my own tool to automate the backup process. And here it is for you to use as well:

Note: The latest versions are now only available on GitHub. The versions below are old versions.

https://github.com/KoenZomers/pfSenseBackup​

Version 2.0 - released 20 May 2015

pfSenseBackupv2.0.zip (executable only - 9 KB)

pfSenseBackupSourcev2.0.zip (source code in Visual Studio 2010/2012/2013 - 17 KB)

Changelog:

  • Changed the way parameters are parsed so that it now also is possible to use the -o parameter and specify a location which contains spaces. Use double quotes to wrap the location in case it contains a space. I.e. -o "c:\my backups" or -o "c:\backups\my backup file.xml" or you may omit the quotes if you don't have any spaces -o c:\backups or -o c:\backups\mybackup.xml or -o "c:\backups\mybackup.xml". Thanks to David Zachhuber for pointing out this issue!

Version 1.9 - released 20 February 2015

pfSenseBackupv1.9.zip (executable only - 9 KB)

pfSenseBackupSourcev1.9.zip (source code in Visual Studio 2010/2012/2013 - 17 KB)

Changelog:

  • Added support for pfSense version 2.2
  • Added the option to use the -o parameter to specify an existing folder. The backup file will be stored inside that folder using the filename as provided by pfSense, which is in the format config-<servername>-<year><month><day><hour><minute><second>.xml. It is still possible to use the -o parameter to provide a full path including filename as well.

Version 1.8 - released 2 November 2013

pfSenseBackupv1.8.zip (executable only - 9 KB)

pfSenseBackupSourcev1.8.zip (source code in Visual Studio 2010/2012/2013 - 17 KB)

Changelog:

  • Bugfix: when not using the -o switch, it would crash (thanks to Mauro Bornet for pointing this out)
  • Added extra check to make sure the user account under which the tool is run has write rights to wherever the backup contents are to be written to

Version 1.7 - released 27 August 2013
pfSenseBackupv1.7.zip (executable only - 12 KB)
pfSenseBackupSourcev1.7.zip (source code in Visual Studio 2012 - 20 KB)

Changelog:

  • Added error handling on illegal characters in the output filename (based on feedback from Dan Peterson)

Version 1.6 - released 11 August 2013
pfSenseBackupv1.6.zip (executable only - 9 KB)
pfSenseBackupSourcev1.6.zip (source code in Visual Studio 2012 - 29 KB)

Changelog:

  • Added the -silent parameter to avoid output for usage in batch scripts (based on request of Anthony Cassinelli)

Version 1.5 - released 8 May 2013

pfSenseBackupv1.5.zip (executable only - 12 KB)
pfSenseBackupSourcev1.5.zip (source code in Visual Studio 2012 - 20 KB)

Changelog:

  • Fixed the -o parameter to specify a location for the backup file which got broken in v1.4

Version 1.4 - released 8 May 2013

pfSenseBackupv1.4.zip (executable only - 12 KB)
pfSenseBackupSourcev1.4.zip (source code in Visual Studio 2012 - 20 KB)

Changelog:

  • Support has been added for pfSense version 2.1 released on or after May 2013. This now includes an anti cross site scripting security token in the login page which caused the application to have to be rewritten.
  • Default is now version 2.1 of the protocol which expects the security token in the login page. If you want to backup a pfSense 2.x version released before May 2013, please specify -v 2.0 as a command line argument.
  • Application code has been rewritten to be cleaner and provide support for the different protocols used to communicate with the different pfSense versions

Version 1.3 - released 28 February 2012

pfSenseBackupv1.3.zip (executable only - 7 KB)
pfSenseBackupSourcev1.3.zip (source code in Visual Studio 2010 - 12 KB)

Changelog:

  • Support has been added for pfSense v1.x by Athanasios Oikonomou. Thanks for contributing!

Version 1.2 - released 26 January 2012

pfSenseBackupv1.2.zip (executable only - 6 KB)

pfSenseBackupSourcev1.2.zip (source code in Visual Studio 2010 - 16 KB)

Changelog:

  • Added code to ignore all SSL related issues when using the -useSSL option

Version 1.1 - released 25 January 2012

pfSenseBackupv1.1.zip (executable only - 6 KB)

pfSenseBackupSourcev1.1.zip (source code in Visual Studio 2010 - 16 KB)

Changelog:

  • Added -useSSL option to have the tool use HTTPS to connect to pfSense instead of HTTP
  • Clarified with a sample that a port number can be added to the -s server directive

Version 1.0 - released 23 January 2012

pfSenseBackupv1.0.zip (executable only - 6 KB)

pfSenseBackupSourcev1.0.zip (source code in Visual Studio 2010 - 16 KB)

It is very lightweight and easy to use this tool. It requires the Microsoft .NET framework 2.0 to be installed on the machine from which you are running it. Extract the executable in the ZIP and run it without parameters to see the help text which explains the options you have to run it:

pfSense-Automate-Backup-ToolHelp.png
As you can see, by providing just the username, password and server IP or DNS name of your pfSense server, it can already download the backup file from your pfSense for you to your local machine. From thereon it's easy to schedule this command using a tool like Windows Task Scheduler to have it run at scheduled intervals. Create a batch script and include this tool in it to for example download the backup file and FTP it to your backups FTP server.

pfSense-Automate-Backup-ToolExample.png