# 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: ```json { "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: ```bash # 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 ```bash ./rsc_clone.sh -n -o -h [-s sourcehost] [-t "YYYY-MM-DD HH:MM:SS"] [-d] ``` ### Required Parameters - `-n ` - Database name/SID for the cloned database - `-o ` - Path to Oracle cloning options file - `-h ` - Target host where the database will be cloned - `` - Source database name to clone ### Optional Parameters - `-s ` - 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) - `-c ` - Optional: configure number of RMAN channels for the clone; when provided the script adds `"numChannels": ` to the `config` block in the GraphQL variables ## Examples ### Basic Clone Operation Clone database `SHED` to `SCLONE` on target host `pve-ora19c-3`: ```bash ./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: ```bash ./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: ```bash ./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: ```bash ./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": "", "client_secret": "", "access_token_uri": "https:///api/client_token", "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 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 ``` 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