Files

175 lines
4.8 KiB
Markdown
Executable File

# OCI Data Safe ADB Inventory
Inventory tool for Oracle Cloud Infrastructure Autonomous Databases and Oracle Data Safe target registration.
The tool scans Autonomous Databases in an OCI tenancy, region, compartment, or compartment subtree, compares them with Oracle Data Safe target databases, and exports CSV or JSON reports showing whether each database is registered in Data Safe.
## Features
- Inventory Autonomous Databases by region, multiple regions, or all subscribed regions.
- Limit scans to a specific compartment or recursively scan a compartment subtree.
- Compare Autonomous Database OCIDs against Oracle Data Safe target databases.
- Export a consolidated report with `datasafe_registered=true/false`.
- Optionally generate separate reports for registered and not registered databases.
- Show terminal progress with processed compartments and running counts.
- Retry transient OCI API errors such as throttling (`429 TooManyRequests`).
- Support OCI SDK by default, with optional OCI CLI fallback.
## Requirements
- Python 3.9 or later.
- OCI Python SDK, installed from `requirements.txt`.
- An OCI config profile in `~/.oci/config`, or OCI instance/resource principal authentication.
- Permissions to list:
- IAM compartments
- Autonomous Databases
- Oracle Data Safe target databases
Install dependencies:
```bash
python3 -m pip install -r requirements.txt
```
On Windows, use `python` or `py` instead of `python3` depending on your installation.
## Recommended Command
Run a scan for one region and generate the consolidated report plus the two split reports:
```bash
python3 ./adb_datasafe_inventory.py \
--profile DEFAULT \
--region sa-saopaulo-1 \
--workers 3 \
--retries 8 \
--retry-base-sleep 5 \
--split-outputs \
--output ./adb_datasafe_inventory.csv
```
Generated files:
- `adb_datasafe_inventory.csv`: consolidated inventory.
- `adb_in_datasafe.csv`: only Autonomous Databases registered in Data Safe.
- `adb_not_in_datasafe.csv`: only Autonomous Databases not registered in Data Safe.
## Scan A Specific Compartment
Scan only one compartment:
```bash
python3 ./adb_datasafe_inventory.py \
--profile DEFAULT \
--region sa-saopaulo-1 \
--compartment-id ocid1.compartment.oc1..example \
--output ./adb_datasafe_inventory.csv
```
Scan one compartment and all of its subcompartments recursively:
```bash
python3 ./adb_datasafe_inventory.py \
--profile DEFAULT \
--region sa-saopaulo-1 \
--compartment-id ocid1.compartment.oc1..example \
--compartment-subtree \
--output ./adb_datasafe_inventory.csv
```
## Other Common Options
Scan multiple regions:
```bash
python3 ./adb_datasafe_inventory.py \
--profile DEFAULT \
--regions sa-saopaulo-1,us-ashburn-1 \
--output ./adb_datasafe_inventory.csv
```
Scan all subscribed regions:
```bash
python3 ./adb_datasafe_inventory.py \
--profile DEFAULT \
--all-regions \
--output ./adb_datasafe_inventory_all_regions.csv
```
Generate only registered databases:
```bash
python3 ./adb_datasafe_inventory.py \
--profile DEFAULT \
--region sa-saopaulo-1 \
--filter registered \
--output ./adb_in_datasafe.csv
```
Generate only databases not registered in Data Safe:
```bash
python3 ./adb_datasafe_inventory.py \
--profile DEFAULT \
--region sa-saopaulo-1 \
--filter not_registered \
--output ./adb_not_in_datasafe.csv
```
Reduce API throttling:
```bash
python3 ./adb_datasafe_inventory.py \
--profile DEFAULT \
--region sa-saopaulo-1 \
--workers 2 \
--retries 8 \
--retry-base-sleep 5 \
--output ./adb_datasafe_inventory.csv
```
## Output Columns
The first columns in the CSV are:
1. `datasafe_registered`
2. `adb_time_created`
3. `adb_compartment_name`
4. `adb_compartment_path`
Additional columns include Autonomous Database identifiers, lifecycle state, workload, compartment OCID, Data Safe target information, and associated target OCIDs.
## Scripts
- `adb_datasafe_inventory.py`: recommended consolidated inventory script.
- `adb_in_datasafe.py`: legacy helper that exports only registered databases.
- `adb_not_in_datasafe.py`: legacy helper that exports only databases not registered in Data Safe.
- `oci_datasafe_inventory.py`: shared library used by the scripts.
## OCI Cloud Shell
In OCI Cloud Shell:
```bash
unzip oci-datasafe-adb-inventory.zip
cd oci-datasafe-adb-inventory
python3 -m pip install --user -r requirements.txt
python3 ./adb_datasafe_inventory.py \
--region sa-saopaulo-1 \
--workers 3 \
--retries 8 \
--retry-base-sleep 5 \
--split-outputs \
--output ./adb_datasafe_inventory.csv
```
## Notes
- `--all-regions` can take a long time in tenancies with many compartments.
- Use `--workers` conservatively if the tenancy hits API throttling.
- Use `--no-progress` to disable the terminal progress bar.
- Use `--format json` to export JSON instead of CSV.
- By default, terminated Autonomous Databases and deleted Data Safe targets are excluded.