Automate Oracle RMAN Backup Validation and Restore with Shell Scripts
This article presents two comprehensive Shell scripts—one to validate Oracle RMAN backup sets and another to perform a full backup‑restore experiment—detailing SSH trust configuration, source information collection, log transfer, directory preparation, and step‑by‑step RMAN restore commands, all illustrated with practical screenshots and a GitHub repository link.
Overview
This guide provides a set of shell scripts to automate Oracle RMAN backup‑set validation and to perform a full restore experiment on a separate target host. The workflow includes establishing SSH mutual trust, collecting source database metadata, transferring logs, and executing RMAN restore and recovery steps.
Backup‑set validation script
The script rman_validate_v2.sh validates the integrity of the RMAN backup sets generated on the previous day. It performs the following actions:
Loads environment variables from the user’s profile.
Uses sqlplus to query the BS_KEY values of yesterday’s backup sets and builds a comma‑separated list.
Invokes RMAN with a VALIDATE BACKUPSET command that checks each backup set logically.
Example RMAN command generated by the script:
validate backupset 6197,6198,6199,6200,6201,6202 check logical;The script contains extensive comments and safety checks and should be tested in a non‑production environment before use.
Restore experiment scripts
The restore experiment consists of five scripts, each handling a specific stage: ssh_mutual_trust_linux_for_source.sh – creates SSH trust from the source host to the target. ssh_mutual_trust_linux_for_target.sh – creates SSH trust from the target host to the source. collect_info_from_source_oracle.sh – extracts 28 database parameters (host name, OS, DB name, DBID, archive‑log path, backup size, listener files, etc.) and writes them to /tmp/source_oracle_dbinfo.log. scp_log_file_to_target.sh – copies the generated log file to the target host’s /tmp directory using scp. rman_restore_and_recover_to_target_oracle.sh – creates required directories, transfers SPFILE, control file, optional block‑trace files, and the RMAN backup set files; then restores SPFILE and control file, mounts the database, restores data files, applies redo logs, and opens the database with RESETLOGS.
SSH mutual trust setup
Both source and target hosts run their respective ssh_mutual_trust_*.sh scripts. Each script:
Adds the counterpart host entry to /etc/hosts.
Generates an RSA key pair ( ssh-keygen -t rsa).
Copies the public key to the opposite host’s authorized_keys file.
Outputs a “Proceeding further…” message when the remote host is reachable via ping and password‑less SSH works.
After execution, a simple ssh target_host should log in without prompting for a password.
Collecting source database information
The script collect_info_from_source_oracle.sh runs a series of sqlplus queries to obtain values such as HOSTNAME, OSNAME, DBVERSION, DBNAME, DBID, archive‑log directory, total archive‑log size (MB), listener configuration files, and other relevant parameters. The output is written to /tmp/source_oracle_dbinfo.log and echoed to the console for verification.
Transferring the log file
The script scp_log_file_to_target.sh uses the following command to copy the log file: scp /tmp/source_oracle_dbinfo.log oracle@target_host:/tmp/ After the transfer, the target host lists /tmp to confirm the presence of the file.
RMAN restore on the target host
The script rman_restore_and_recover_to_target_oracle.sh performs these major steps:
Create required directories with mkdir -p (ensure sufficient disk space).
Copy SPFILE, control file, and optional block‑trace files from source to target.
Transfer the RMAN backup set files to the target location.
Restore SPFILE and control file, then start the database in MOUNT mode.
Restore data files and apply archived redo logs.
Open the database with RESETLOGS, start the listener, and update /etc/oratab to register the instance.
Each step logs success messages that can be reviewed in the generated log file.
Verification of the restored database
After the restore, the script queries the database status; a successful restoration shows the instance in READ WRITE mode.
Reference
All scripts and documentation are available in the GitHub repository:
https://github.com/guestart/rman_backup_and_restore_experiment
dbaplus Community
Enterprise-level professional community for Database, BigData, and AIOps. Daily original articles, weekly online tech talks, monthly offline salons, and quarterly XCOPS&DAMS conferences—delivered by industry experts.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
