managed/api-examples/python-simple/backups.ipynb
session_infosession_info contains current user and current customer uuid.import http.client
import json
import os
from pprint import pprint
platform_api_key = os.getenv('YB_API_KEY')
platform_address = os.getenv('API_BASE_URL', "portal.dev.yugabyte.com")
conn = http.client.HTTPConnection(f"{platform_address}")
headers = {
'Content-Type': "application/json",
'X-AUTH-YW-API-TOKEN': f"{platform_api_key}"
}
conn.request("GET", "/api/v1/session_info", headers=headers)
res = conn.getresponse()
data = res.read()
session_info = json.loads(data)
pprint(session_info)
./list-customer-config.ipynb for how to list all configsstorage_config_uuid = os.getenv('STORAGE_CONF_UUID',
"f5cfe9fb-cd4f-46e7-8ed8-af285b730cc0")
uuid of universe to be backed up. See list-universes.ipynb for how to
universe_uuid = os.getenv('UNIVERSE_UUID',
"303cf5ac-a6f5-492b-b68c-7d4d9633c4cc")
payload = ('{\n'
' "actionType": "CREATE",\n'
' "keyspace": "postgres",\n'
f' "storageConfigUUID": "{storage_config_uuid}",\n'
' "timeBeforeDelete": "864000000",\n'
' "sse": "false",\n'
' "transactionalBackup": "false",\n'
' "parallelism": "8",\n'
' "backupType": "PGSQL_TABLE_TYPE"\n'
'}')
url = f"/api/v1/customers/{session_info.get('customerUUID')}" \
f"/universes/{universe_uuid}/multi_table_backup"
conn.request("PUT", url, payload, headers)
res = conn.getresponse()
yb_task = json.load(res)
pprint(yb_task)
table_name = "cassandrakeyvalue"
url = f"/api/v1/customers/{session_info.get('customerUUID')}" \
f"/universes/{universe_uuid}/tables"
conn.request("GET", url, headers=headers)
res = conn.getresponse()
data = res.read()
table_list = json.loads(data)
for table in table_list:
if table['tableName'] == table_name:
break
pprint(table)
payload = ('{\n'
' "actionType": "CREATE",\n'
f' "keyspace": "{table.get("keySpace")}",\n'
f' "tableName": "{table_name}",\n'
f' "storageConfigUUID": "{storage_config_uuid}",\n'
' "timeBeforeDelete": "864000000"\n'
'}')
print(payload)
url = f"/api/v1/customers/{session_info.get('customerUUID')}" \
f"/universes/{universe_uuid}/tables/{table['tableUUID']}/create_backup"
print(url)
conn.request("PUT", url, payload, headers)
res = conn.getresponse()
yb_task = json.load(res)
pprint(yb_task)
url = f"/api/v1/customers/{session_info.get('customerUUID')}" \
f"/backups/{yb_task.get('resourceUUID')}/stop"
print(url)
conn.request("POST", url, "{}", headers=headers)
res = conn.getresponse()
print(json.loads(res.read()))
url = f"/api/v1/customers/{session_info.get('customerUUID')}" \
f"/backups"
payload = ('{\n'
f' "backupUUID": ["{yb_task.get("resourceUUID")}"]\n'
'}')
print(payload)
conn.request("DELETE", url, payload, headers=headers)
res = conn.getresponse()
print(res.read())
payload = ('{\n'
' "actionType": "CREATE",\n'
' "keyspace": "postgres",\n'
f' "storageConfigUUID": "{storage_config_uuid}",\n'
' "timeBeforeDelete": "864000000",\n'
' "sse": "false",\n'
' "transactionalBackup": "false",\n'
' "parallelism": "8",\n'
' "schedulingFrequency": "86400000",\n'
' "backupType": "PGSQL_TABLE_TYPE"\n'
'}')
url = f"/api/v1/customers/{session_info.get('customerUUID')}" \
f"/universes/{universe_uuid}/multi_table_backup"
conn.request("PUT", url, payload, headers)
res = conn.getresponse()
schedule_info = json.load(res)
pprint(schedule_info)
url = f"/api/v1/customers/{session_info.get('customerUUID')}" \
f"/schedules/{schedule_info.get('scheduleUUID')}"
conn.request("DELETE", url, headers=headers)
res = conn.getresponse()
print(res.read())