A Python script for finding and optionally deleting old Nutanix recovery points and Prism Element snapshots.
The script runs in dry-run mode by default. It only deletes matching items when the --delete flag is explicitly provided.
- Lists old Nutanix v4 Data Protection recovery points through Prism Central
- Lists old Prism Element v2.0 snapshots on configured Prism Element clusters
- Supports cleanup of recovery points, snapshots, or both
- Runs in safe dry-run mode by default
- Requires
--deletebefore anything is removed - Supports filtering by item age
- Supports filtering by name
- Can write cleanup results to a JSON report
- Uses only the Python standard library
The same user account must exist on Prism Central and on every configured Prism Element cluster.
The username and password must be identical everywhere. This script uses one shared authentication token for Prism Central and all Prism Element API calls. Different users, different passwords, or separate credentials per Prism Element are not supported by this script.
- Python 3.8 or newer
- Network access to Nutanix Prism Central
- Network access to all configured Prism Element clusters
- A valid Nutanix API token
- Correct Prism Element host configuration
No external Python packages are required.
Before running the script, update these values in nutanix_cleanup.py:
NTNX_PRISMCENTRAL_IP = "YOUR_IP:9440"
PE_AND_PC_TOKEN = "YOUR GENERATED TOKEN FROM nutanix_auth.py"
PE_HOSTS = [
"IP_FROM_ELEMENTS_CLUSTER_1:9440",
"IP_FROM_ELEMENTS_CLUSTER_2:9440",
"IP_FROM_ELEMENTS_CLUSTER_3:9440",
]Dry-run mode:
python nutanix_cleanup.py \
--mode recovery \
--older-than-days 14Actually delete matching recovery points:
python nutanix_cleanup.py \
--mode recovery \
--older-than-days 14 \
--deleteDry-run mode:
python nutanix_cleanup.py \
--mode snapshot \
--older-than-days 14Actually delete matching snapshots:
python nutanix_cleanup.py \
--mode snapshot \
--older-than-days 14 \
--deleteDry-run mode:
python nutanix_cleanup.py \
--mode both \
--older-than-days 14Actually delete matching items:
python nutanix_cleanup.py \
--mode both \
--older-than-days 14 \
--deleteOnly include items where the name contains a specific string:
python nutanix_cleanup.py \
--mode both \
--older-than-days 14 \
--name-contains backupBy default, items without a detected creation timestamp are not included.
To include them:
python nutanix_cleanup.py \
--mode both \
--older-than-days 14 \
--include-without-creation-timeWrite cleanup results to a JSON file:
python nutanix_cleanup.py \
--mode both \
--older-than-days 14 \
--json-file cleanup-report.jsonThis script is intentionally conservative:
- It runs in dry-run mode by default.
- It requires
--deletebefore deleting anything. - It only includes items older than the value passed to
--older-than-days. - It can filter by name with
--name-contains. - It does not include items without a detected creation timestamp unless
--include-without-creation-timeis set.
Always run the script without --delete first and review the output carefully.
Do not commit real API tokens, passwords, Prism Central addresses, Prism Element addresses, or internal infrastructure details to a public GitHub repository.
The script currently disables SSL certificate verification by using:
ssl._create_unverified_context()This may be useful in lab environments, but it is not recommended for production. For production use, configure proper certificate validation.
This script is provided as an example. Test it in a safe environment before using it against production Nutanix infrastructure.