Skip to main content

Linux (CLI) Restore


There are two (2) restore options to choose from in Linux CLI mode:

  • Original location - AhsayOBM will restore the database(s) from the backup destination and apply them to the original production Oracle instance.
  • Restore raw file - AhsayOBM will restore the Oracle database files to a location on the local machine, which then can be copied to another Oracle server on another machine for recovery.

    The Restore Raw File option is for advanced Oracle database administrators and should only be used if you have in-depth knowledge and understanding of Oracle database engine, Oracle database schema, knowledge of the database server and network infrastructure. Therefore, it is not recommended to use this restore option as there is a need to utilize additional Oracle techniques and scripts to facilitate a manual database restore.

    Please refer to the following article of Oracle Database Backup and Recovery User's Guide for details:

Before restoring your Oracle database, check the following:

  1. TNS listener service must be started to allow connections to the Oracle database server for the restore process. To check if the TNS listener service is running, use the lsnrctl status command. If the TNS listener service is not started, use the lsnrctl start command to start the service.

    Example: A running TNS Listener service on Oracle 19c.

    
    $ lsnrctl status
    
    LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 22-FEB 2022 11:33:44
    
    Copyright (c) 1991, 2019, Oracle.  All rights reserved.
    
    Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oracle19c.local)(PORT=1521)))
    STATUS of the LISTENER
    ------------------------
    Alias                     LISTENER
    Version                   TNSLSNR for Linux: Version 19.0.0.0.0 - Production
    Start Date                22-FEB-2022 12:13:24
    Uptime                    1 days 23 hr. 20 min. 20 sec
    Trace Level               off
    Security                  ON: Local OS Authentication
    SNMP                      OFF
    Listener Parameter File   /u01/app/oracle/product/19.0.0/dbhome_1/network/admin/listener.ora
    Listener Log File         /u01/app/oracle/diag/tnslsnr/oracle19c/listener/alert/log.xml
    Listening Endpoints Summary...
      (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle19c.local)(PORT=1521)))
      (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
    Services Summary...
    Service "86b637b62fdf7a65e053f706e80a27ca" has 1 instance(s).
      Instance "cdb1", status READY, has 1 handler(s) for this service...
    Service "8886b84fb1e0709de053631e100a76ed" has 1 instance(s).
      Instance "cdb1", status READY, has 1 handler(s) for this service...
    Service "cdb1" has 1 instance(s).
      Instance "cdb1", status READY, has 1 handler(s) for this service...
    Service "cdb1XDB" has 1 instance(s).
      Instance "cdb1", status READY, has 1 handler(s) for this service...
    Service "pdb1" has 1 instance(s).
      Instance "cdb1", status READY, has 1 handler(s) for this service...
    The command completed successfully
    		

    The values shown are just examples and might be different on your Oracle instance.

  2. Run the sqlplus / as sysdba command to verify if the Oracle service is active.

    The following is just an example of an Oracle instance failure due to corrupted data and/or configuration files. It might be different on your Oracle instance.

    
    $ sqlplus / as sysdba
    SQL*Plus: Release 19.0.0.0.0 - Production on Mon Nov 9 15:23:12 2020
    Version 19.3.0.0.0
    
    Copyright (c) 1982, 2019, Oracle.  All rights reserved.
    
    Connected to an idle instance.
    		

Restore on Linux (CLI)

Follow the steps below to restore the Oracle database either to the original production Oracle instance or to another location on the local machine.

  1. Open the Restore.sh script using a text editor (e.g. vi) and configure the restore settings:

    • BACKUP_SET - the name of the backup set which you would like to restore.
    • DESTINATION - the destination where the backup will be restored from. You can leave this blank if you only have one (1) destination.
    • RESTORE_TO - the location where the backup will be restored. This setting should be left blank if restoring to Original Location.
    • RESTORE_FROM - the file or directory that you would like to restore.
    • POINT_IN_TIME - the specific successful backup that you would like to restore. You can use Current if you want to use the latest backup snapshot.
    • RESTORE_PERMISSION - the setting where you can enable or disable the restore file permissions.
    • SKIP_INVALID_KEY - the setting where you can choose to skip the restore file with invalid key or prompt user to input a correct key.
    • SYNC_OPTION - the setting where you can choose to delete extra files by selecting from the following sync options:
      • SYNC_OPTION="Y" - to enable sync option
      • SYNC_OPTION="N" - to disable sync option
      • SYNC_OPTION="" - to prompt for selection
    • REPLACE_EXISTING_FILE - the setting where you can choose if you want to replace or keep existing files with the same filename, or prompt for selection:
      • REPLACE_EXISTING_FILE="--all" - to replace all existing file(s) of the same filename
      • REPLACE_EXISTING_FILE="--none" - to skip all existing file(s) with the same filename
      • REPLACE_EXISTING_FILE="" - to prompt for selection
    • SETTING_HOME - the directory of setting home.
    • FILTER - the setting where you can filter the files which you would like to restore.
    • TEMP_DIR - the temporary directory where the backup will be restored.
    • VERIFY_CHKSUM - the setting where you can enable or disable the in-file delta file checksum to be verified during restore.

    The RESTORE_TO=”” setting must be blank when restoring to Original Location.

    
    # cd /usr/local/obm/bin
    # vi Restore.sh
    
    # !/bin/sh
    
    ################################  Restore.sh ###########################
    # You can use this shell script to restore backup files using command- #             # line.                                                                #
    # Just customize the "User Define Section" below with values for your          # restore action.                                                      #
    ########################################################################
    
    ########################  Start: User Defined Section  #################
    
    # -----------------------------  BACKUP_SET  ---------------------------
    # | The name or ID of the backup set that you want to restore.         |
    # | If backup set name is not in English, please use ID instead.       |
    # | e.g. BACKUP_SET="1119083740107"                                    |
    # |  or  BACKUP_SET="FileBackupSet-1"                                  |
    # |                                                                    |
    # | You can leave this parameter blank if you have only 1 backupset.   |
    # ---------------------------------------------------------------------|
    BACKUP_SET="Oracle Database Server Backup Set"
    
    # ------------------------------ DESTINATION  --------------------------
    # | The name or ID of the backup destination that you want to restore  |    # | from.                                                              |
    # | If backup destination name is not in English, please use ID instead.   
    # | e.g. DESTINATION="1740107119083"                                   |
    # |  or  DESTINATION="Destination-1"                                   |   
    # |                                                                    |    
    # | You can leave this parameter blank if you have only 1 destination. |    
    # ----------------------------------------------------------------------
    DESTINATION=""
    
    # -------------------------------  RESTORE_TO  -------------------------
    # | Directory to where you want files to be restored                   |   
    # | set to "" to restore files to original location                    |    
    # | e.g. RESTORE_TO="/tmp"                                             |   
    # |---------------------------------------------------------------------
    RESTORE_TO=""
    
    # ------------------------------  RESTORE_FROM  ------------------------
    # | File/Directory on the backup server that you would like to restore |    
    # | e.g. RESTORE_FROM="/Data"                                          |   
    # ----------------------------------------------------------------------
    RESTORE_FROM="Oracle Database Server"
    
    # -----------------------------  POINT_IN_TIME  -----------------------
    # | The point-in-time snapshot (successful backup) that you want to    | # | restore                                                            | 
    # | from the backup server. Use "Current" for the latest backup snapshot   
    # | e.g. POINT_IN_TIME="2006-10-04-12-57-13"                           |   
    # |  or  POINT_IN_TIME="Current"                                       |    
    # |                                                                    |    
    # | You can retrieve the point in time by using the ListBackupJob.sh   |    
    # ----------------------------------------------------------------------
    POINT_IN_TIME="Current"
    
    # --------------------------  RESTORE_PERMISSION  ----------------------
    # | set to "Y" if you want to restore file permissions                 |    
    # | set to "N" if you do NOT want to restore file permissions          |    
    # ----------------------------------------------------------------------
    RESTORE_PERMISSION="N"
    
    # ----------------------------  SKIP_INVALID_KEY  ----------------------
    # | set to "Y" if you want to skip restore file with invalid key       |    
    # | set to "N" if you want to prompt user to input a correct key       |    
    # ----------------------------------------------------------------------
    SKIP_INVALID_KEY="N"
    
    # ------------------------------  SYNC_OPTION  -------------------------
    # | Delete extra files                                                 |    
    # | set to "Y" if you want to enable sync option                       |    
    # | set to "N" if you do NOT want to enable sync option                |   
    # | set to "" to prompt for selection                                  |    
    # ----------------------------------------------------------------------
    SYNC_OPTION="N"
    
    # -------------------------  REPLACE_EXISTING_FILE  --------------------
    # | set to "--all" to replace all existing file(s) of the same filename|    
    # | set to "--none" to skip all existing file(s) with the same filename|    
    # | set to "" to prompt for selection                                  |    
    # ----------------------------------------------------------------------
    REPLACE_EXISTING_FILE="--all"
    
    # ------------------------------  SETTING_HOME  ------------------------
    # | Directory to your setting home.                                    |    
    # | Default to ${HOME}/.obm when not set.                              |   
    # | e.g. SETTING_HOME="${HOME}/.obm"                                   |    
    # ----------------------------------------------------------------------
    SETTING_HOME=""
    
    # ---------------------------------  FILTER  ---------------------------
    # | Filter out what files you want to restore                          |     
    # | -Pattern=xxx-Type=yyy-Target=zzz                                   |    
    # | where xxx is the filter pattern,                                   |   
    # |       yyy is the filter type, whice can be one of the following:   |    
    # |           [exact | exactMatchCase | contains | containsMatchCase|  |    
    # |            startWith | startWithMatchCase | endWith |              |  # |endWithMatchCase]                                                   |
    # |       zzz is the filter target, which can be one of the following: |    
    # |           [toFile | toFileDir | toDir]                             |    
    # |                                                                    |    
    # | e.g. FILTER="-Pattern=.txt-Type=exact-Target=toFile"               |    
    # ----------------------------------------------------------------------
    FILTER=""
    
    # --------------------------------  TEMP_DIR  --------------------------
    # | Directory to where you want to store restore files temporarily     |    
    # | set to "" to use the temporary directory in the backup set         |    
    # | e.g. TEMP_DIR="/tmp"                                                   
    # ----------------------------------------------------------------------
    TEMP_DIR="/temp"
    
    # -----------------------------  VERIFY_CHKSUM  ------------------------
    # | set to "Y" if you want to verify in-file delta file checksum during| # |restore                                                             |
    # | set to "N" if you do NOT want to verify in-file delta file checksum| # | during restore                                                     |           # ----------------------------------------------------------------------
    VERIFY_CHKSUM="N"
    
    ########################  END: User Defined Section  ###################
    
    ########################################################################
    #      R E T R I E V E            A P P _ H O M E           P A T H    #    #                                                                      #
    ########################################################################
    		
  2. After the Restore.sh script is configured, the files can be:

    • restored automatically to the Oracle Database Server. When the “Database is required to shutdown. Continue?” appears, select 1.YES.
    • restore the raw file to another location on the local machine and manually recover the database.

    The following example only shows the main process of restore. To see the complete restore log, refer to Troubleshooting - Example of Restore Log.

    
    # cd /usr/local/obm/bin
    # sh Restore.sh
    
    Using APP_HOME:          : /usr/local/obm
    Using BACKUP_SET         : Oracle Database Server Backup Set
    Using RESTORE_FROM       : Oracle Database Server
    Using RESTORE_TO         :
    Using POINT_IN_TIME      : Current
    Using RESTORE_PERMISSION : N
    Using TEMP_DIR           : /temp
    Filter Pattern not set, filter would not apply to restore
    Temporary directory not set, use the temporary directory in the backup set
    Filter Pattern not set, filter would not apply to restore
    [2023/06/29 11:22:59] Start [ AhsayOBM v9.5.4.63]
    [2023/06/29 11:22:59] OS: Linux 3.10.0-1160.45.1.el7.x86_64 (localhost.localdomain); CPU Model: Intel(R) Xeon(R) Gold 5218R CPU @ 2.10GHz,Intel(R) Xeon(R) Gold 5218R CPU @ 2.10GHz; Number of Processors: 4; Heap Size: 60.4MB (Current) / 1.8GB (Maximum); Physical Memory: 3.3GB (Free) / 7.6GB (Total)
    [2023/06/29 17:43:33] start,Start [ AhsayOBM v9.5.4.63],0,0,0,,0,0
    
    [2023/06/29 11:22:59] [hide] Selected job: 2023-06-29--00-00
    [2023/06/29 11:22:59] [hide] Selected source: [Oracle Database Server]
    [2023/06/29 11:22:59] Info: [followLink=false marshalTargetPath=false deleteForSync=false skipFaultKey=false verifyDeltaFileChecksum=false ignoreSegmentInfoCorruptedData=true restorePermission=false [RestoreLocation] type=ORIGINAL path=[null]] 
    
    [2023/06/29 11:23:01] Initializing decrypt action...
    [2023/06/29 11:23:01] Initializing decrypt action... Completed
    [2023/06/29 11:23:01] Start restore database "orcl"
    [2023/06/29 11:23:03] Initializing Oracle module...
    Database is required to shutdown. Continue?
    1.YES    2.YES TO ALL    3.NO    4.NO TO ALL  >>1
    [2023/06/29 11:23:08] Shutdown database
    [2023/06/29 11:23:44] Removed file "/u01/app/oracle/oradata/ORCL/control01.ctl" 
    [2023/06/29 11:23:44] Removed file "/u01/app/oracle/fast_recovery_area/ORCL/control02.ctl" 
    [2023/06/29 11:23:44] Removed file "/u01/app/oracle/oradata/ORCL/redo03.log" 
    [2023/06/29 11:23:44] Removed file "/u01/app/oracle/oradata/ORCL/redo02.log"
    [2023/06/29 11:23:44] Removed file "/u01/app/oracle/oradata/ORCL/redo01.log"
    [2023/06/29 11:23:45] Removed file "/u01/app/oracle/oradata/ORCL/sysaux01.dbf"
    [2023/06/29 11:23:54] Existing item found (overwrite)... /u01/database/dbs/spfileorcl.ora
    [2023/06/29 11:23:54] Downloading... "/u01/database/dbs/spfileorcl.ora" (Total 3K bytes)
    [2023/06/29 11:23:54] Downloading... "/u01/app/oracle/oradata/ORCL/control01.ctl" (Total 17.89M bytes)
    [2023/06/29 11:23:54] Downloading... "/u01/app/oracle/fast_recovery_area/ORCL/control02.ctl" (Total 17.89M bytes)
    [2023/06/29 11:23:55] Mount database
    [2023/06/29 11:27:48] Downloading... "/u01/app/oracle/oradata/ORCL/pdb/sysaux01.dbf" (Total 370.01M bytes)
    [2023/06/29 11:27:51] Downloading... "/u01/app/oracle/oradata/ORCL/pdbseed/sysaux01.dbf" (Total 350.01M bytes)
    [2023/06/29 11:27:54] Downloading... "/u01/app/oracle/oradata/ORCL/pdb/system01.dbf" (Total 250.01M bytes)
    [2023/06/29 11:28:04] Downloading... "/u01/app/oracle/oradata/ORCL/pdbseed/undotbs01.dbf" (Total 100.01M bytes)
    [2023/06/29 11:29:21] Recover database
    [2023/06/29 11:29:22] Reset database logs
    [2023/06/29 11:29:53] Restart database
    [2023/06/29 11:30:57] Restore Completed Successfully
    [2023/06/29 11:30:57] end,RESTORE_STOP_SUCCESS,0,0,0,,0,0
    		
  3. After the restore job is completed, verify whether the Oracle database instance has been restored using the following SQL query to verify if the instance is online.

    
    $ sqlplus / as sysdba
    SQL*Plus: Release 19.0.0.0.0 - Production on Wed Feb 23 11:35:54 2022
    Version 19.3.0.0.0
    Copyright (c) 1982, 2019, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
    Version 19.3.0.0.0
    SQL> select instance from v$thread;
    INSTANCE
    ---------------------------------------------------------------
    orcl
    SQL>
    			
    		

    For restore raw file, locate the path where you restored the Oracle database files.

    For example: RESTORE_TO="/usr/local/restorefolder"

    
    # ls -la "/usr/local/restorefolder/Oracle Database Server/u01/app/oracle/oradata/ORCL"
    total 2552752
    drwxrwxrwx. 4 oracle oinstall        133 Jun 29 17:18 .
    drwxrwxrwx. 3 oracle oinstall         18 Jun 29 17:14 ..
    -rw-r--r--. 1 oracle oinstall   18759680 Jun 29 12:12 control01.ctl
    drwxrwxrwx. 2 oracle oinstall         86 Jun 29 17:17 pdb
    drwxrwxrwx. 2 oracle oinstall         67 Jun 29 17:17 pdbseed
    -rw-rw-rw-. 1 oracle oinstall 1447043072 Jun 29 12:11 sysaux01.dbf
    -rw-rw-rw-. 1 oracle oinstall  912269312 Jun 29 12:12 system01.dbf
    -rw-rw-rw-. 1 oracle oinstall  230694912 Jun 29 12:12 undotbs01.dbf
    -rw-r--r--. 1 oracle oinstall    5251072 Jun 29 12:12 users01.dbf
    		
  4. This step is only needed if you restored a raw file.

    To recover RAW databases, please refer to the following articles of Oracle Database Backup and Recovery User's Guide for details: