Files
oracle-livemount-python/README.md
T
2026-06-01 04:23:12 -04:00

249 lines
7.2 KiB
Markdown

# Python Oracle Scripts for Rubrik Security Cloud
This directory contains Python command-line tools for Oracle database operations in Rubrik Security Cloud (RSC), including database discovery, snapshot visibility, clone/live mount operations, files-only mounts, and live mount cleanup.
## RSC Service Account
A Service Account will need to be created in RSC, and a role assigned to it that allows databases to be listed and mounted.
The recommended minimum privileges for the role are:
On the Database Host object level:
* View Protectable Objects
* Mount Snapshot
Recovery Targets: Same Oracle host
## 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
Creates either a full clone or a live mount of an Oracle database.
**Usage:**
```bash
./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 multiple databases share the same name
- `-t, --timestamp`: Recovery point timestamp in format "YYYY-MM-DD HH:MM:SS"
- `-d, --dryrun`: Show configuration without executing
- `--livemount`: Create a live mount instead of a clone
- `-c, --channels`: RMAN channel count (must be positive)
- `-p, --pfile`: Absolute path to custom pfile
**Examples:**
```bash
# Basic clone
./clone_oracle_database.py -n NEWDB -o options.txt --targethost target-host SHED
# Live mount
./clone_oracle_database.py -n LIVEMOUNT -o options.txt --targethost target-host --livemount SHED
# Dry run
./clone_oracle_database.py -n NEWDB -o options.txt --targethost target-host --dryrun SHED
```
**Features:**
- Supports both clone and live mount flows
- Resolves source/target objects through GraphQL
- Uses latest PIT automatically when timestamp is not provided
- Includes dry-run output and job status monitoring
### list_oracle_databases.py
Lists all Oracle databases protected by Rubrik Security Cloud.
**Usage:**
```bash
./list_oracle_databases.py
```
**Features:**
- Displays database name, RSC ID, cluster, host, and relic status
- Filters out replicated databases (shows only source databases)
- Outputs in a formatted table
### list_oracle_snapshots.py
Lists snapshots and recovery ranges available for a specific Oracle database, including distribution across source, replicated, and archived locations.
**Usage:**
```bash
./list_oracle_snapshots.py [database_name_or_id]
```
**Examples:**
```bash
./list_oracle_snapshots.py SHED
./list_oracle_snapshots.py b4194205-b7d6-5f0b-8360-e6f349b9fd82
./list_oracle_snapshots.py
```
**Features:**
- 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.
If no database argument is provided, the script uses the local database ID.
### mount_oracle_filesonly.py
Mounts Oracle database files to a target host without starting the database instance (files-only mount).
**Usage:**
```bash
./mount_oracle_filesonly.py --mountpath <path> [options] [srcdb]
```
**Required Arguments:**
- `--mountpath`: Target mount path for the database files
**Optional Arguments:**
- `--targethost`: Target host where files will be mounted (defaults to local hostname)
- `--timestamp`: Recovery point timestamp in format "YYYY-MM-DD HH:MM:SS"
- `srcdb`: Source database name or RSC database ID (defaults to local database)
**Examples:**
```bash
# Mount local database files to /tmp/mount
./mount_oracle_filesonly.py --mountpath /tmp/mount
# Mount specific database to remote host
./mount_oracle_filesonly.py --targethost target-host --mountpath /tmp/mount SHED
# Mount with specific timestamp
./mount_oracle_filesonly.py --mountpath /tmp/mount --timestamp "2025-11-25 12:00:00" SHED
```
**Features:**
- Mounts database files without starting the Oracle instance
- Useful for file-level restores or manual recovery operations
- Automatic latest Point-in-Time detection when no timestamp specified
- Defaults to local hostname and local database when not specified
### list_oracle_mounts.py
Lists all Oracle Live Mounts in Rubrik Security Cloud with filtering and sorting options.
**Usage:**
```bash
./list_oracle_mounts.py [options]
```
**Options:**
- `--name`: Filter by mounted database name
- `--cluster-uuid`: Filter by cluster UUID
- `--source-db-id`: Filter by source database ID
- `--org-id`: Filter by organization ID
- `--sort-field`: Sort by NAME, CREATION_DATE, or STATUS
- `--sort-order`: Sort order (ASC or DESC, default: ASC)
- `--limit`: Maximum number of results (default: 50)
**Examples:**
```bash
# List all live mounts
./list_oracle_mounts.py
# List mounts for a specific source database
./list_oracle_mounts.py --source-db-id abc123-def456
# List mounts sorted by creation date
./list_oracle_mounts.py --sort-field CREATION_DATE --sort-order DESC
```
**Features:**
- Displays mount ID, source DB, mounted DB name, cluster, target host, status, and creation date
- Automatically defaults to local database if no filters specified
- Outputs in a formatted table
### unmount_oracle_livemount.py
Unmounts an Oracle Live Mount using its RSC ID.
**Usage:**
```bash
./unmount_oracle_livemount.py <livemount_id> [--force]
```
**Required Arguments:**
- `livemount_id`: RSC ID of the Oracle Live Mount to unmount (get from list_oracle_mounts.py)
**Optional Arguments:**
- `--force`: Force unmount even if the mount is in use
**Examples:**
```bash
# Normal unmount
./unmount_oracle_livemount.py abc123-def456-ghi789
# Force unmount
./unmount_oracle_livemount.py abc123-def456-ghi789 --force
```
**Features:**
- Clean unmount of live mounts
- Force option for emergencies
- Displays result links and status
### introspect_schema.py
Inspects GraphQL schema types exposed by RSC.
**Usage:**
```bash
# List Oracle-related types
./introspect_schema.py
# Dump schema details for one type
./introspect_schema.py OracleDatabase
```
**Features:**
- Lists Oracle-related GraphQL types
- Retrieves detailed introspection output for a requested type
- Useful for query/mutation development and troubleshooting
## Modules
- `rsc.py`: Contains RSCAuth class for OAuth2 authentication and RSCGraphQL class for making GraphQL queries to RSC
## Notes
- Tokens are cached securely in `~/.rbkRscsession.*` files
- Scripts use GraphQL queries and mutations against the RSC API
- Error handling includes GraphQL error checking