From 78de12e3f75154cb29a1da47204c133d4bd94850 Mon Sep 17 00:00:00 2001 From: James Pattinson Date: Mon, 6 Oct 2025 08:43:54 -0400 Subject: [PATCH] Add README and PDB support --- README.md | 35 +++++++++++++++++++++++++++++++++++ oracle_clone.sh | 30 +++++++++++++++++++++++------- 2 files changed, 58 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e69de29..8883e77 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,35 @@ +# Oracle Clone Script + +This script (`oracle_clone.sh`) performs a clone of an Oracle database using the Rubrik CDM API. + +## Usage + +```bash +./oracle_clone.sh [options] +``` + +- ``: Source Oracle database SID. +- ``: Target hostname for the clone. + +## Options + +- `-h ` Source DB hostname +- `-t ` Recovery point timestamp (`"YYYY-MM-DD HH:MM:SS"`, uses latest if not specified) +- `-n ` New database SID for the clone +- `-p ` Custom pfile for the clone +- `-a ` Advanced Cloning Options (can be used multiple times) +- `-b ` Comma-separated list of PDBs to clone (include only these PDBs. `PDB$SEED` is always included) +- `-d` Dry run mode - show API payload without executing + +## Notes + +- The script requires access to the Rubrik API and expects the supporting functions `oracle_funcs.sh` to be present in the same directory. +- Time is passed to `date` on the local machine and uses the local timezone. + +## Example + +```bash +./oracle_clone.sh -h dbhost01 -t "2024-06-01 12:00:00" -n CLONE01 -b PDB1,PDB2 orcl targethost +``` + +This will clone the `orcl` database from `dbhost01` to `targethost`, using the specified timestamp, new SID `CLONE01`, and only include `PDB$SEED`, `PDB1`, and `PDB2`. diff --git a/oracle_clone.sh b/oracle_clone.sh index 8e8d220..9d23be1 100755 --- a/oracle_clone.sh +++ b/oracle_clone.sh @@ -11,6 +11,7 @@ # -n New database SID for the clone # -p Custom pfile for the clone # -a Advanced Cloning Options (can be used multiple times) +# -b Comma-separated list of PDBs to clone (include only these PDBs. PDB$SEED is always included) # -d Dry run mode - show API payload without executing # # Time is passed to 'date' on THIS machine, will use local timezone @@ -26,33 +27,38 @@ usage() { echo "Usage: $0 [options] " 1>&2 echo " -n New database SID for clone" 1>&2 echo " -p Custom pfile for the clone" 1>&2 echo " -a Advanced Cloning Options (can be used multiple times)" 1>&2 + echo " -b Comma-separated list of PDBs to clone (include only these PDBs)" 1>&2 echo " -d Dry run mode" 1>&2 exit 1; } declare -a config_pairs +declare -a pdb_list dryrun=false -while getopts "h:dt:n:p:a:" o; do +while getopts "h:dt:n:p:a:b:" o; do case "${o}" in h) RBK_HOST=${OPTARG} ;; t) datestring=${OPTARG} - ;; + ;; n) newsid=${OPTARG} - ;; + ;; p) custompfile=${OPTARG} - ;; + ;; a) config_pairs+=("${OPTARG}") - ;; + ;; + b) + IFS=',' read -ra pdb_list <<< "${OPTARG}" + ;; d) dryrun=true - ;; - *) + ;; + *) usage ;; esac @@ -123,6 +129,16 @@ if [ -n "$custompfile" ]; then PAYLOAD="$PAYLOAD,\"customPfilePath\":\"$custompfile\"" fi +# Add pdbsToClone array if -b specified +if [ ${#pdb_list[@]} -gt 0 ]; then + pdbs_json="\"PDB\$SEED\"" + for pdb in "${pdb_list[@]}"; do + pdbs_json="$pdbs_json,\"$pdb\"" + done + echo "PDB: Including PDBs in clone: PDB\$SEED ${pdb_list[*]}" + PAYLOAD="$PAYLOAD,\"pdbsToClone\":[${pdbs_json}]" +fi + PAYLOAD="$PAYLOAD,\"advancedRecoveryConfigMap\":{$configmap}}" ENDPOINT="https://$RUBRIK_IP/api/internal/oracle/db/$db_id/export"