Oracle – Indirect Restore using Netbackup

Problem :

I was needed to do the production database restore in order to recover the lost data from production database. The data was lost from few tables only so I decided to restore production database from backup to another host. The Oracle is configured with Netbackup.

Solution :

As i said, We have Netbackup configured with Oracle. We backup the database to disk first and then push the backup pieces to tapes using Symantec’s Netbackup for Oracle.

Restoring the production backup on new host is called Indirect Restore in the world of Netbackup.

There are few requirements which need to be met before the actual database restore with RMAN can be started.

  • The Oracle binary version and platform must be same on both original server and new server.
  • The Netbackup Client must be installed on the client where you want to restore the database.
  • You need to set up the environment exactly same as the source else the restore would fail. You can use RMAN’s set newname command if you have different directory structure on new host.
  • Make sure you know the Original machine name where the backup was taken, the master Netbackup server name and Netbackup policy name for the database.
  • RMAN catalog should be installed and the database which needs to restore must be registered with the RMAN catalog.This is not mandatory but it will make the restore process much more easier if you have it.

Assuming that the tapes which holds the backup are loaded into the robotic library.

Netbackup also maintains the backup information in its catalog which is stored on the master netbackup server. You can always query master netbackup server’s catalog using bplist command if you want to find the backup information from netbackup’s catalog.

Now we can proceed with the restore process but before we can restore the database, we need to create pfile for new database and start the instance in nomount mode.

  • Create pfile from production’s spfile and copy it over to new server’s $ORACLE_HOME/dbs folder.

On Production,

  • Set the environment variables on new server and start the instance with pfile copied over. Please make sure that all the file paths mentioned in pfile are valid. 

On new server,

  •  Restore the control file.

We need to find the control file’s backup piece before we can restore it. We can use bplist command to find the backup piece name.

For example,

So once the backup piece has been identified we can proceed with the control file restore.

On new server,

Once control file is restored, please copy control file to the location mentioned in the pfile.

For example,

You can mount the database now.

NB_ORA_SERV = Netbackup master server name.

NB_ORA_POLICY = Netbackup Database backup policy name.

NB_ORA_CLIENT = Original Backup host name.

  • Restore the database and archive logs.

On new server,

  • Recover the database.

On new server,

  • Open the database.

On new server,

  • LOGS

The Netbackup client logs can be found in the following directory.

Create a read only user in Oracle

Problem:

I was asked to create a read only user account in Oracle.

Solution:

In Oracle, There is not straight forward way to create a user and grant db_datareader role like SQL server, so you will have to create a user and grant select privilege on all the objects for specific schema.

The following PL/SQL code will generate the SQL query to grant select on all tables and views.

If you need to do this same operation on a frequent basis then the best way is to create a role and assign role to user.

  • Create Role.

  • Assign privileges to Role.

  • Assign role to user.

 

Oracle – Restrict User login from particular IP Address

Problem :

I was asked to load new data into the database and I didn’t want users/applications to connect when I am loading the data.

Solution :

I had the following solutions in my mind.

Solution 1:Only allow login from the particular host.

  • Open the SQLNET.ORA from $ORACLE_HOME/network/admin and add following parameters.

  • Reload the listener.
Now Oracle will only allow the connections from the machine with 10.103.119.182 IP Address.It will not even allow the sys or system user so make sure you have the SSH access to the database machine because if something goes wrong than you can SSH into the box and change the sqlnet.ora accordingly.
Advantages:
  • No database configuration needs to be changed.
  • Easy to toggle the setting.
Disadvantages :
  • It applies to all the users including SYS and SYSTEM.
  • SQLNET.ORA changes the system wide setting so it will be applied to all the database which are registered with the listener.
Solution 2 : Allow particular host using the Database triggers.
  • Write a Logon Database trigger which will allow the users/applications from the particular hosts.

  • The user will get the following error if his host is not allowed.

  • Please disable the trigger once the data loading is done.
Advantages :
  • The trigger works at the database level so it wont affect the other databases.
  • Easy to disable/enable trigger.
Disadvantages :
  • The database trigger will have to created once and it may not be supported or allowed.
  • The triggers won’t be fired for the uses who has the DBA privileges/role.