- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
API call to retrieve Backup DB
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 06:10 AM
Hi all and thanks in advance for any replies.
First time poster, long time subscriber.
Anyway, I am trying to retrieve the Backup DB .csv via api but keep getting the below error
C:\Users\e157716\PycharmProjects\SunchProdAndDev\venv\lib\site-packages\urllib3\connectionpool.py:1100: InsecureRequestWarning: Unverified HTTPS request is being made to host 'sdcscadnsgmavip.swacorp.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
warnings.warn(
Error creating a database backup: 400
Process finished with exit code 0
My code is as follows:
import requests
# Infoblox API information
infoblox_url = 'xxx' # Adjust the URL and version as needed
infoblox_user = 'yyy'
infoblox_password = 'zzz'
# Function to create an Infoblox database backup
def create_database_backup():
endpoint = '/grm/backup'
url = infoblox_url + endpoint
# Prepare a request to create a database backup
data = {
"comment": "Database backup created via API" # Optional comment
}
response = requests.post(url, auth=(infoblox_user, infoblox_password), json=data, verify=False) # Disable SSL verification; use it with caution
if response.status_code == 200:
response_data = response.json()
backup_url = response_data['url']
# You can download the backup file if needed
# backup_response = requests.get(backup_url, auth=(infoblox_user, infoblox_password), verify=False)
# Handle the downloaded backup file as required
print("Database backup created successfully.")
else:
print(f"Error creating a database backup: {response.status_code}")
if __name__ == "__main__":
create_database_backup()
We are running: 8.6.3-51135-1241097029df
Re: API call to retrieve Backup DB
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 07:17 AM
Looks like your grid is using self-signed certificates. That's not a problem but you will need to set up a requests session, and supply some parameters to bypass SSL certificate validation.
Here's a quick example of setting up a session, and getting the current WAPI version
global SESSION SESSION = requests.session() get_version = f'https://{gm}/wapi/v1.0/?_schema' json_headers = {'content-type': 'application/json'} resp = SESSION.get(get_version, headers=json_headers, auth=authentication, verify=False, timeout=600) json_data = json.loads(resp.text) # Save the authentication cookie for use in subsequent requests. ibapauth_cookie = resp.cookies['ibapauth'] # Use the ibapauth cookie to authenticate instead of userid/password. global COOKIE COOKIE = {'ibapauth': ibapauth_cookie} # Get supported versions versions = json_data["supported_versions"] versions.sort(key=lambda s: list(map(int, s.split('.')))) # Sort Versions # Get the latest version global WAPI WAPI = versions[-1] log.info("Using wapi version %s", WAPI) log.info("Capturing supported objects for version %s", WAPI)
You will need to generate the backup file first, using the fileop function.
Here's an example with curl.
# Download Grid Backup # Request grid backup generation curl -k -u admin:infoblox -X POST 'https://192.168.1.2/wapi/v2.12/fileop?_function=getgriddata&type=BACKUP' { "token": "eJytjj0LwjAURf9KyWyTvrSExq1SBUFaEMExpE2swX6ZRlDE/24z6Ori+M7lnnefSN9HYx/CmU6j\nZQCMp8CiNKaYA0toxBcButl2jtDZuXFaEgKcYmApBkyJZ0IZq2snTqbVwgzE6qswKszLY7ErszyE\niCYwq2LKIWFRTJR0spKTxpW8oNnvb6H7elCmb/yn1bb48m5QfhjKs0Mm9uvNJ/CMTG6wstHEdeN/\nphjlvb9q6PUGzdpb/w==\n", "url": "https://192.168.1.2/http_direct_file_io/req_id-DOWNLOAD-1024142032914603/database.bak" } # Download file from URL curl -k -u admin:infoblox -H "Content-type:application/force-download" -O 'https://192.168.1.2/http_direct_file_io/req_id-DOWNLOAD-1024142032914603/database.bak' # And then close the file using the token curl -k1 -u admin:infoblox -X POST 'https://192.168.1.2/wapi/v2.12/fileop?_function=downloadcomplete' \ -H "Content-Type: application/json" -d \ '{ "token": "eJytjj0LwjAURf9KyWyTvrSExq1SBUFaEMExpE2swX6ZRlDE/24z6Ori+M7lnnefSN9HYx/CmU6j\nZQCMp8CiNKaYA0toxBcButl2jtDZuXFaEgKcYmApBkyJZ0IZq2snTqbVwgzE6qswKszLY7ErszyE\niCYwq2LKIWFRTJR0spKTxpW8oNnvb6H7elCmb/yn1bb48m5QfhjKs0Mm9uvNJ/CMTG6wstHEdeN/\nphjlvb9q6PUGzdpb/w==\n" }'
Re: API call to retrieve Backup DB
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 07:44 AM
Could I have an example with Pythin?
Nuno
[Image result for Southwest Airlines heart clipart]
******* CONFIDENTIALITY NOTICE *******
This e-mail message and all attachments transmitted with it may contain legally privileged and confidential information intended solely for the use of the addressee. If the reader of this message is not the intended recipient, you are hereby notified that any reading, dissemination, distribution, copying, or other use of this message or its attachments is strictly prohibited. If you have received this message in error, please notify the sender immediately and delete this message from your system. Thank you.
Re: API call to retrieve Backup DB
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2024 10:15 AM
This works - could add session stuff: