Restore From Backup

Restore the data from the database backup of your source database to your target database.

Install Oracle Database Backup on the Target Database

Copy the oci_install.jar file over to the target database host and run the command to install Oracle Database Backup on the target.

Install Oracle Database Backup Cloud Service on the source database
  1. Copy the oci_install.jar file over to the target database host through the bastion host and unzip.
    BASTION_IP=BASTION_IP # public IP
    DB_HOST=DB_HOST # private IP
    
    scp -o ProxyCommand="ssh -W %h:%p
    opc@${BASTION_IP}" oci_install.jar 
    opc@${DB_HOST}:~/
    
    ssh -J opc@${BASTION_IP} opc@${DB_HOST} 'sudo chown oracle:oinstall oci_install.jar; sudo mv oci_install.jar
    /home/oracle/'
  2. SSH to the OCI target database through the bastion host with, and switch to the oracle user.
    ssh -J opc@${BASTION_IP} opc@${DB_HOST}
    sudo su - oracle
  3. Backup the current wallet, and install the wallet on the target database.
    mv $ORACLE_HOME/data/wallet $ORACLE_HOME/data/wallet_bck
    mkdir -p $ORACLE_HOME/data/wallet
    unzip wallet.zip -d $ORACLE_HOME/data/wallet/
  4. Run the Database Cloud Backup Module command to install the library and create the config file.
    This is the same command that you ran to install Oracle Database Backup Cloud Service on the source database, although the ORACLE_HOME variable may be different.
    java -jar oci_install.jar \
    -host https://objectstorage.region.oraclecloud.com \
    -pubFingerPrint wallet_public_key_fingerprint \
    -tOCID tenancy_OCID \
    -uOCID user_OCID \
    -cOCID compartment_OCID \
    -libDir $ORACLE_HOME/lib \
    -walletDir $ORACLE_HOME/data/wallet \
    -pvtKeyFile $ORACLE_HOME/data/wallet/oci_pvt \
    -bucket bucket_name \
    -configFile ~/config
    
    The config file appears in the home folder of the oracle user.
  5. Backup the original target database SPF file with the SID_NAME.
    If you don't backup the original target database SPF file, RMAN will try to use it to restore the backup and fail.
    mv $ORACLE_HOME/dbs/spfileSID_NAME.ora $ORACLE_HOME/dbs/spfileSID_NAME.ora.bck

Configure the Backup Storage on the Target Database

Configure the backup SBT_TAPE storage device on the target database.

  1. Run the RMAN target command.
    rman target /
  2. Configure the backup SBT_TAPE storage device on the target database.
    Use the ORACLE_HOME environment variable to define the SBT library.
    RMAN> CONFIGURE CHANNEL DEVICE TYPE 'SBT_TAPE' PARMS 'SBT_LIBRARY=ORACLE_HOME/lib/libopc.so, SBT_PARMS=(OPC_PFILE=/home/oracle/config)';
    

Set the DBID and Restore the SPF File From Backup

Run RMAN commands to set the DBID and the decryption password to restore the SPF file from backup. When setting the DBID, you'll use RMAN to replace the target DBID with the source DBID.

  1. Set the database ID (DBID).
    RMAN> run {
    shutdown immediate;
    set dbid DBID number;
    STARTUP FORCE NOMOUNT;
    }
  2. Set the decryption password (the password that was used for encryption) and restore the SPF file from backup.
    RMAN> SET DECRYPTION IDENTIFIED BY password;
    RMAN> set controlfile autobackup format for device type sbt to '%F';
    RMAN> run {
      allocate channel c1 device type sbt PARMS 'SBT_LIBRARY=ORACLE_HOME/lib/libopc.so, SBT_PARMS=(OPC_PFILE=/home/oracle/config)';
      restore spfile from autobackup;
    }
  3. Exit RMAN.

Create a Directory for the Audit File

Create a destination directory for the audit file.

The default location is /u01/app/oracle/admin/$ORACLE_SID/adump. You can see the setting used by the original database by searching the restored spfile for the string audit_file_dest.

The spfile is a binary file, requiring strings to parse properly. However, line breaks may be present that prevent a simple grep from providing the full path. The -s "" option on strings removes line breaks and the sed command parses out the text after audit_file_dest. Because the sed command does not handle non-greedy regex, the awk command is needed to trim the end of the file.

  • Create the folder with the added xargs command:
    strings -s "" ${ORACLE_HOME}/dbs/spfile*.ora | sed -E "s|.*audit_file_dest='(.*)'.*|\1|" | awk -F"'" '{print $1}' | xargs mkdir -p 

Restore and Recover the Database

Use RMAN to restore the control file from backup and then restore and recover the database. RMAN recovers the database using archived redo logs.

  1. Open RMAN and restore the control file from backup. Use the DBID number and the decyrption password that you set earlier.
    Rman target /
    RMAN> set dbid DBID number;
    RMAN> STARTUP FORCE NOMOUNT;
    RMAN> SET DECRYPTION IDENTIFIED BY password;
    RMAN> set controlfile autobackup format for device type sbt to '%F';
    RMAN> run {
    allocate channel c1 device type sbt PARMS 'SBT_LIBRARY=ORACLE_HOME/lib/libopc.so, SBT_PARMS=(OPC_PFILE=/home/oracle/config)';
      restore controlfile from autobackup;
      alter database mount;
    }
  2. Restore and recover the database using RMAN.
    RMAN> run {
    CONFIGURE CHANNEL DEVICE TYPE 'SBT_TAPE' PARMS 'SBT_LIBRARY=ORACLE_HOME/lib/libopc.so, SBT_PARMS=(OPC_PFILE=/home/oracle/config)';
    RESTORE DATABASE;
    RECOVER DATABASE;
    }
    When RMAN has applied the last archived redo log in the backup and can't find any more logs, a message similar to the following appears: unable to find archived log
  3. Open the database with resetlogs.
    RMAN> ALTER DATABASE OPEN RESETLOGS;
  4. Ready the target database to receive connections.
  5. Re-instate the TNS Listener by editing the listener configuration to create a static listener.
    nano $ORACLE_HOME/network/admin/listener.ora
  6. Add the following section to the TNS Listener to define ORACLE_HOME and the CDB name of the source database.

    Replace ORACLE_HOME with the path value of ORACLE_HOME and SID_NAME with the Service Name (CDB name) of the source database.

    SID_LIST_LISTENER=
      (SID_LIST=
        (SID_DESC=
          (ORACLE_HOME=ORACLE_HOME)
          (SID_NAME=SID_NAME))
      )
    
  7. Edit the tnsname file.
    nano $ORACLE_HOME/network/admin/tnsnames.ora
  8. Edit the SERVICE_NAME to matches the SID name of the source database (without the domain name).
    (SERVICE_NAME = SID_NAME)
  9. Restart the listener.
    $ORACLE_HOME/bin/lsnrctl stop
    $ORACLE_HOME/bin/lsnrctl start
    $ORACLE_HOME/bin/lsnrctl status
    
The database should be accessible.