Description |
This article describes how to get a backup config file on FortiGate by using a Python script from non-mgmt VDOM. |
Scope |
FortiGate v7.0.x. |
Solution |
so far there is a way to configure a generic API user with read/write rights but in order to be able to make a backup via API of the FortiGate unit the API admin must be set with super_admin rights, and CLI has to be used:
config system api-user
NOTE: Do not forget to modify the IP address, token, and file directory.
import os import sys import requests import json
def Api():
main_url = "https://10.109.17.34/" # Edit IP address client = requests.session() client.verify = False
token = "aaaabbbcccc…."
url_new = (main_url + "api/v2/monitor/system/config/backup?scope=vdom&vdom=TEST&access_token="+token) resp = client.get(url_new)
file= open(r'C:\Users\Desktop\config-file.txt' ,'w') # please edit file directory for line in resp.text: file.write(line)
Api()
Main_url is the IP address of the Fortigate Scope = Vdom Vdom = Vdom name ( Vdom which PC connected and sent the request) Token = Token that is generated in step 5
Execute the Python script. It will create a file named 'config-file.txt ' in the specified directory with the configuration of the FortiGate inside. |
The Fortinet Security Fabric brings together the concepts of convergence and consolidation to provide comprehensive cybersecurity protection for all users, devices, and applications and across all network edges.
Copyright 2024 Fortinet, Inc. All Rights Reserved.