Files
llb-oracle/README.md
2025-10-15 17:19:17 +01:00

7.1 KiB

RSC Oracle Database Clone Script

Overview

The rsc_clone.sh script performs Oracle database clone operations using the Rubrik Security Cloud (RSC) GraphQL API. It allows you to create a clone of an existing Oracle database to a target host with customizable recovery points and advanced Oracle configuration options.

Prerequisites

  • Rubrik Security Cloud (RSC) access with valid credentials
  • Source Oracle database protected by Rubrik
  • Target Oracle host configured and registered in RSC
  • Required configuration files:
    • rsc.json - RSC API credentials
    • Oracle cloning options file

Configuration

RSC API Configuration (rsc.json)

Download the JSON configuration file from RSC:

{
    "client_id": "client|your-client-id-here",
    "client_secret": "your-client-secret-here",
    "name": "Your RSC Service Account Name",
    "access_token_uri": "https://your-organization.my.rubrik.com/api/client_token"
}

Oracle Cloning Options File

Create a text file with Oracle-specific cloning parameters. Each line should contain KEY=VALUE pairs for Oracle initialization parameters:

# Example: SHED_to_SCLONE.txt
CONTROL_FILES='/u01/app/oracle/oradata/SCLONE/control01.ctl, /u01/app/oracle/fast_recovery_area/SCLONE/control02.ctl'
DB_CREATE_FILE_DEST=/u01/app/oracle/oradata/SCLONE/
AUDIT_FILE_DEST='/u01/app/oracle/admin/SCLONE/adump'
DB_FILE_NAME_CONVERT='SHED','SCLONE'

Usage

./rsc_clone.sh -n <newname> -o <optionsfile> -h <targethost> [-s sourcehost] [-t "YYYY-MM-DD HH:MM:SS"] [-d] <srcdb>

Required Parameters

  • -n <newname> - Database name/SID for the cloned database
  • -o <optionsfile> - Path to Oracle cloning options file
  • -h <targethost> - Target host where the database will be cloned
  • <srcdb> - Source database name to clone

Optional Parameters

  • -s <sourcehost> - Source host name (use when there are multiple databases with the same name on different hosts)
  • -t "YYYY-MM-DD HH:MM:SS" - Recovery point timestamp (defaults to latest point-in-time)
  • -d - Dry-run mode (shows mutation variables without executing)
  • -v or --verbose - Enable verbose logging (prints INFO lines and debug context)
  • -c <numChannels> - Optional: configure number of RMAN channels for the clone; when provided the script adds "numChannels": <numChannels> to the config block in the GraphQL variables

Examples

Basic Clone Operation

Clone database SHED to SCLONE on target host pve-ora19c-3:

./rsc_clone.sh -n SCLONE -o SHED_to_SCLONE.txt -h pve-ora19c-3 SHED

Dry-Run Mode

Preview the clone operation without executing it:

./rsc_clone.sh -n SCLONE -o SHED_to_SCLONE.txt -h pve-ora19c-3 -d SHED

Output:

DEBUG: DB ID is b4194205-b7d6-5f0b-8360-e6f349b9fd82
INFO: No time specified, using latest PIT
Latest PIT (ISO8601): 2025-10-15T08:32:49.000Z
Latest PIT unixtime (ms): 1760517169000
Target Host ID is 26008fd4-9a96-582e-86b7-4da31584a7ad

=== DRY-RUN MODE ===
Would execute the following GraphQL mutation:

QUERY:
mutation OracleDatabaseExportMutation($input: ExportOracleDatabaseInput!) {
  exportOracleDatabase(input: $input) {
    id
    links {
      href
      rel
      __typename
    }
    __typename
  }
}

VARIABLES:
{
  "input": {
    "request": {
      "id": "b4194205-b7d6-5f0b-8360-e6f349b9fd82",
      "config": {
        "targetOracleHostOrRacId": "26008fd4-9a96-582e-86b7-4da31584a7ad",
        "shouldRestoreFilesOnly": false,
        "recoveryPoint": {
          "timestampMs": 1760517169000
        },
        "cloneDbName": "SCLONE",
        "shouldAllowRenameToSource": true,
        "shouldSkipDropDbInUndo": false
      }
    },
    "advancedRecoveryConfigMap": [
      {
        "key": "CONTROL_FILES",
        "value": "'/u01/app/oracle/oradata/SCLONE/control01.ctl, /u01/app/oracle/fast_recovery_area/SCLONE/control02.ctl'"
      },
      {
        "key": "DB_CREATE_FILE_DEST",
        "value": "/u01/app/oracle/oradata/SCLONE/"
      },
      {
        "key": "AUDIT_FILE_DEST",
        "value": "'/u01/app/oracle/admin/SCLONE/adump'"
      },
      {
        "key": "DB_FILE_NAME_CONVERT",
        "value": "'SHED','SCLONE'"
      }
    ]
  }
}

=== END DRY-RUN ===

Point-in-Time Recovery

Clone database to a specific point in time:

./rsc_clone.sh -n SCLONE -o SHED_to_SCLONE.txt -h pve-ora19c-3 -t "2025-10-15 08:00:00" SHED

Specify Source Host

When multiple databases with the same name exist on different hosts:

./rsc_clone.sh -n SCLONE -o SHED_to_SCLONE.txt -h pve-ora19c-3 -s pve-ora19c-1 SHED

Script Workflow

Configuration (rsc.json)

The scripts read RSC credentials and endpoint details from rsc.json in the repository root. An example file rsc.json.example is included. The expected JSON fields are:

{
  "client_id": "<your-client-id>",
  "client_secret": "<your-client-secret>",
  "access_token_uri": "https://<rsc-host>/api/client_token",
  "name": "<optional-friendly-name>"
}

Security note: rsc.json is listed in .gitignore. Ensure the file permissions are restricted (recommended chmod 600 rsc.json). If rsc.json was accidentally committed to git, consider purging it from history.

Examples

  • Basic dry-run with verbose output:
./rsc_clone.sh -n SCLONE -o SHED_to_SCLONE.txt -h pve-ora19c-3 -d -v SHED
  • Execute clone and request 4 RMAN channels:
./rsc_clone.sh -n SCLONE -o SHED_to_SCLONE.txt -h pve-ora19c-3 -c 4 SHED
  • Trigger an on-demand log backup with verbose logging:
./rsc_log_backup.sh -v <dbName>
  1. Parameter Validation - Validates required parameters and options file
  2. Database Discovery - Locates source database in RSC
  3. Host Resolution - Resolves target host ID in RSC
  4. Recovery Point - Determines recovery timestamp (latest or specified)
  5. Options Processing - Converts options file to JSON format
  6. Clone Execution - Submits GraphQL mutation to RSC API
  7. Job Monitoring - Tracks clone job status until completion

Error Handling

The script includes comprehensive error handling for:

  • Missing required parameters
  • Database not found or ambiguous matches
  • Target host not found
  • Invalid recovery timestamps
  • RSC API errors
  • Job failures

Dependencies

  • rsc_ops.sh - RSC API operations and utility functions
  • rsc.json - RSC credentials configuration
  • jq - JSON processing
  • curl - HTTP requests
  • date/gdate - Date/time operations

Troubleshooting

Common Issues

  1. Database not found - Verify database name and use -s if multiple databases exist
  2. Host not found - Check target host name is registered in RSC
  3. Permission errors - Ensure RSC service account has sufficient privileges
  4. Invalid timestamp - Use format "YYYY-MM-DD HH:MM:SS" for -t parameter

Debug Information

The script provides debug output including:

  • Source database ID
  • Target host ID
  • Recovery point details
  • Job status updates

Use dry-run mode (-d) to validate configuration before executing actual clones.

Version History

  • v0.1 - Initial release with basic clone functionality
  • Added dry-run mode for validation
  • Improved error handling and database selection logic