You can back up and restore your VMS database with the HTTP REST API. This guide walks you through creating a binary database backup and restoring your system from a backup file using Python.
Prerequisites
Before running the Python scripts, ensure you meet the following requirements:
Local user account: Access to an active local user account with administrative privileges in Nx Witness.
Authentication token: A valid bearer or session token for authorization. For detailed instructions on generating tokens, see Authentication through the REST API.
Python environment: Python 3 installed with the standard
requests,datetime,json, andbase64libraries.
Back up the system database
Creating a system backup generates a binary dump of your VMS database and saves it as a local file.
To fetch the database, send a GET request to the /rest/v4/site/database endpoint.
The following Python script authenticates your request, downloads the database payload, saves it as a timestamped binary file (systembackup_<MM-DD-YYYY-HH-MM-SS>.db), and revokes the session token.
get_method_header = create_header(primary_token)
system_backup = request_api(LOCAL_URL, f'/rest/v4/site/database', 'GET', verify=False, headers=get_method_header)
delete_method_header = create_header(secondary_token)
request_api(LOCAL_URL, f'/rest/v4/login/sessions/{secondary_token}', 'DELETE', verify=False, headers=delete_method_header)
backup_time = datetime.now().strftime('%m-%d-%Y-%H-%M-%S')
with open(f'systembackup_{backup_time}.db', 'bw') as backup:
backup.write(base64.b64decode(system_backup["data"]))
Restore the system database
Restoring the system database overwrites your current database configuration with the contents of a previously saved backup file.
To restore the database, send a POST request to the /rest/v4/site/database endpoint containing your encoded database backup file.
| NOTE: Restoring a database overwrites existing system configurations. The Media Server automatically restarts after completing the restore operation. For the changes to appear in Nx Witness Desktop, restart the client. |
Open your Python script.
Replace
'FILENAME'with the actual path and name of your backup file (for example,'systembackup_08-27-2026-10-15-00.db').Run the following code:
filename = 'FILENAME' # replace FILENAME with your backup file
with open(f'{filename}', 'br') as recovery:
recovery_file = recovery.read()
recovery_file = json.dumps({"data": base64.b64encode(recovery_file).decode()})
get_method_header = create_header(primary_token)
request_api(LOCAL_URL, f'/rest/v4/site/database', 'POST', verify=False, headers={**get_method_header, 'Content-type':'application/json'}, data=recovery_file)
delete_method_header = create_header(secondary_token)
Comments
0 comments
Article is closed for comments.