• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login
Netgate Discussion Forum
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login

pull Backup DHCP server using script

Scheduled Pinned Locked Moved Off-Topic & Non-Support Discussion
10 Posts 3 Posters 492 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N
    netboy
    last edited by Jan 28, 2025, 8:33 PM

    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

    1 Reply Last reply Reply Quote 0
    • S
      stephenw10 Netgate Administrator
      last edited by Jan 29, 2025, 5:35 PM

      You mean the lease table?

      N 1 Reply Last reply Jan 29, 2025, 8:40 PM Reply Quote 0
      • N
        netboy @stephenw10
        last edited by netboy Jan 29, 2025, 8:42 PM Jan 29, 2025, 8:40 PM

        @stephenw10 DHCP Server info

        9b02f310-fec5-4ba9-9ef1-3db6e1cff78f-image.png

        1 Reply Last reply Reply Quote 0
        • S
          stephenw10 Netgate Administrator
          last edited by Jan 29, 2025, 9:46 PM

          Oh just the server config? That doesn't change unless you change it. Why do you want to back it periodically?

          1 Reply Last reply Reply Quote 0
          • S
            stephenw10 Netgate Administrator
            last edited by Jan 29, 2025, 10:07 PM

            You don't won't the Extra Backup Data, which includes the dhcp server lease database?

            N 1 Reply Last reply Jan 29, 2025, 10:38 PM Reply Quote 0
            • N
              netboy @stephenw10
              last edited by Jan 29, 2025, 10:38 PM

              @stephenw10 If I can get DHCP lease info that will be great. Is there an API to pull this?

              G 1 Reply Last reply Jan 30, 2025, 9:24 AM Reply Quote 0
              • S
                stephenw10 Netgate Administrator
                last edited by Jan 29, 2025, 10:49 PM

                Not really. General advice is here:
                https://docs.netgate.com/pfsense/en/latest/backup/remote-backup.html

                N 1 Reply Last reply Jan 29, 2025, 11:04 PM Reply Quote 0
                • N
                  netboy @stephenw10
                  last edited by netboy Jan 30, 2025, 12:36 AM Jan 29, 2025, 11:04 PM

                  @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!

                  1 Reply Last reply Reply Quote 0
                  • G
                    Gertjan @netboy
                    last edited by Jan 30, 2025, 9:24 AM

                    @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.

                    No "help me" PM's please. Use the forum, the community will thank you.
                    Edit : and where are the logs ??

                    N 1 Reply Last reply Jan 30, 2025, 4:05 PM Reply Quote 0
                    • N
                      netboy @Gertjan
                      last edited by netboy Jan 30, 2025, 4:06 PM Jan 30, 2025, 4:05 PM

                      @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.

                      1 Reply Last reply Reply Quote 0
                      2 out of 10
                      • First post
                        2/10
                        Last post
                      Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.
                        This community forum collects and processes your personal information.
                        consent.not_received