pfSense remote backup

I've recently moved my pfSense box from a VM to a physical machine so I needed to find another to way to back it up. I found this and made a script from it which is run as a cron every day.


# You'll need to escape your password if it includes stuff like a dollar sign (e.g. p$assword will become p\$assword)

wget -qO- --keep-session-cookies --save-cookies cookies.txt --no-check-certificate "$URL/diag_backup.php" | grep "name='__csrf_magic'" | sed 's/.*value="\(.*\)".*/\1/' > csrf.txt

wget -qO- --keep-session-cookies --load-cookies cookies.txt --save-cookies cookies.txt --no-check-certificate --post-data "login=Login&usernamefld=$USERNAME&passwordfld=$PASSWORD&__csrf_magic=$(cat csrf.txt)" \
"$URL/diag_backup.php" | grep "name='__csrf_magic'" | sed 's/.*value="\(.*\)".*/\1/' > csrf2.txt

wget --keep-session-cookies --load-cookies cookies.txt --no-check-certificate --post-data "Submit=download&donotbackuprrd=yes&__csrf_magic=$(head -n 1 csrf2.txt)" \
"$URL/diag_backup.php" -O $OUTPUTDIR/config-router-`date +%Y%m%d%H%M%S`.xml

rm csrf.txt
rm cookies.txt
rm csrf2.txt