pull Backup DHCP server using script
-
Hi, is there a way to access the DHCP server xml programmatically say in Python? Is there an API?
What I want:
I have already written a python script to read the DHCP server backup XML (downloaded "manually" ) and load into my custom table.I was wondering if I can run a cron job inside netgate to pull this xml file and ftp to my nas folder.
Thanks
-
You mean the lease table?
-
@stephenw10 DHCP Server info
-
Oh just the server config? That doesn't change unless you change it. Why do you want to back it periodically?
-
You don't won't the Extra Backup Data, which includes the dhcp server lease database?
-
@stephenw10 If I can get DHCP lease info that will be great. Is there an API to pull this?
-
Not really. General advice is here:
https://docs.netgate.com/pfsense/en/latest/backup/remote-backup.html -
@stephenw10 yes I did see that...
Does pfsense save all this dhcp info into a sqlite database? May be I can download the db.Never mind found the conf file!
-
@netboy said in pull Backup DHCP server using script:
Is there an API to pull this?
I'll give you the words that will show you the possibilities.
Here : pfsense backup config remote login ssh - click and see for yourself.It is possible to to use 'emulate' on the command line, on your PC, or NAS, http(s) request that does the login for you, and then, with 'scp', or 'ssh', or a web request, you can retrieve the config.xml, or actually use the pfSense web GUI server, and use the Diagnostics Backup & Restore page, pre selects "All" or just "DHCP" and retrieve that set.
And then, instead of you doing it with your keyboard, script it.Example : I using this for many years already : https://github.com/KoenZomers/pfSenseBackup on a PC that is always nearly 'on'.
It logs into pfSense ones a day, gets the config, and keeps the last 100 copies on this PC. -
@Gertjan Thanks
This is what I have implemented.
A script which runs daily polls a NAS folder and if there is indications that a file is present (I "physically" copy the backup of dhcp server from router to this folder) then the script runs and populates a database.
Since dhcp rarely changes, I do not want to automate things.
I do take a backup of ALL if I made a change to the router.