Files
oracle-livemount-python/README.md
2025-11-14 17:34:12 +00:00

135 lines
4.6 KiB
Markdown

# Python Oracle Scripts for Rubrik Security Cloud
This directory contains Python scripts that replicate the functionality of the shell scripts for managing Oracle databases in Rubrik Security Cloud (RSC).
## Setup
1. Create and activate virtual environment:
```bash
python3 -m venv venv
source venv/bin/activate
```
2. Install dependencies:
```bash
pip install -r requirements.txt
```
3. Copy and configure credentials:
```bash
cp rsc.json.example rsc.json
# Edit rsc.json with your actual client_id, client_secret, and access_token_uri
```
## Scripts
### clone_oracle_database.py
Clones an Oracle database to a target host using Rubrik Security Cloud. This replicates the functionality of `rsc_clone.sh`.
**Usage:**
```bash
python clone_oracle_database.py -n <newname> -o <optionsfile> --targethost <targethost> [options] <srcdb>
```
**Required Arguments:**
- `-n, --newname`: Database name/SID of the new cloned or live mounted database
- `-o, --optionsfile`: Path to options file containing Oracle parameters
- `--targethost`: Target host where the database will be created
- `<srcdb>`: Source database name or RSC database ID
**Optional Arguments:**
- `-s, --sourcehost`: Source host (when there are multiple databases with the same name)
- `-t, --timestamp`: Recovery point timestamp in format "YYYY-MM-DD HH:MM:SS"
- `-d, --dryrun`: Show configuration without executing the operation
- `--livemount`: Create a live mount instead of a clone
- `-c, --channels`: Number of RMAN channels for the operation
- `-p, --pfile`: Custom pfile path (must be absolute path)
**Examples:**
```bash
# Basic clone with latest PIT
python clone_oracle_database.py -n NEWDB -o options.txt --targethost target-host SHED
# Live mount instead of clone
python clone_oracle_database.py -n LIVEMOUNT -o options.txt --targethost target-host --livemount SHED
# Clone with specific timestamp
python clone_oracle_database.py -n NEWDB -o options.txt --targethost target-host -t "2025-11-14 15:30:00" SHED
# Clone with source host disambiguation
python clone_oracle_database.py -n NEWDB -o options.txt --targethost target-host -s source-host SHED
# Dry run to see configuration
python clone_oracle_database.py -n NEWDB -o options.txt --targethost target-host --dryrun SHED
# Clone with custom RMAN channels
python clone_oracle_database.py -n NEWDB -o options.txt --targethost target-host -c 4 SHED
```
**Options File Format:**
The options file contains Oracle initialization parameters. Example:
```
CONTROL_FILES='/u01/app/oracle/oradata/NEWDB/control01.ctl, /u01/app/oracle/fast_recovery_area/NEWDB/control02.ctl'
DB_FILE_NAME_CONVERT='SHED','NEWDB'
DB_CREATE_FILE_DEST=/u01/app/oracle/oradata/NEWDB/
AUDIT_FILE_DEST='/u01/app/oracle/admin/NEWDB/adump'
```
**Features:**
- **Clone or Live Mount**: Choose between creating a persistent clone or temporary live mount
- Automatic latest Point-in-Time (PIT) detection when no timestamp specified
- Host ID resolution for target hosts
- Comprehensive error handling and validation
- Job status monitoring with progress updates
- Dry-run mode for testing configurations
### list_db_snapshots.py
Lists snapshots and recovery ranges available for a specific Oracle database, including distribution across source, replicated, and archived locations.
Usage:
```bash
python list_db_snapshots.py <database_name_or_id>
```
Examples:
```bash
python list_db_snapshots.py SHED
python list_db_snapshots.py b4194205-b7d6-5f0b-8360-e6f349b9fd82
```
This script will display:
- Database information (name, ID, cluster, host)
- Recoverable ranges (time periods when the database can be recovered)
- **Snapshot Distribution**: Shows where backups are stored:
- **Local (Source)**: Backups on the original cluster
- **Replicated**: Backups replicated to other clusters
- **Archived**: Backups stored in archival locations
- Missed recoverable ranges (gaps in coverage)
**Note:** If multiple databases have the same name, the script will list them and ask you to specify the database ID instead.
### introspect_schema.py
Explores the GraphQL schema dynamically using GraphQL introspection.
Usage:
```bash
# Explore Oracle-related types
python introspect_schema.py
# Get detailed info about a specific type
python introspect_schema.py OracleDatabase
```
## Modules
- `rsc_auth.py`: Handles authentication with RSC using OAuth2 client credentials
- `rsc_graphql.py`: Provides a client for making GraphQL queries to RSC, including schema introspection capabilities
## Notes
- Tokens are cached securely in `~/.rbkRscsession.*` files
- The scripts use the same GraphQL queries as the shell scripts
- Error handling includes GraphQL error checking