How to Configure OCI CLI on local VM machine

1.Requirements:

Python =>3
Cloud User OCID
Cloud Tenancy OCID
Cloud Region
Directory of public and private keys

2.How to get Python:

Download python3.6 from below link on the machine where you want to access Oracle cloud.

$curl -O https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz

$tar -xvzf Python-3.6.0.tgz

# cd < Python-3.6.0 unzip directory>
# ./configure
# make
# make install

Once done the same can be verified using below command:

[root@mumbai ~]# python3 –version
Python 3.6.0
[root@mumbai ~]#

3.How to get Cloud User OCID:

Login to cloud console using the account details and click on the profile icon at the right corner.

Clicking on Profile->User Setting will land you to below page.

You can copy the highlighted OCID which is User ocid.

4.How to get Tenancy OCID:

To get the tenancy id, login to the cloud console page and click on the profile->Tenancy

Copy OCID which is tenancy OCID.

5.How to get Cloud Region:

You get the region details from the address bar of the URL as well as by clicking Manage Regions

6.Install OCI:

Dowload oci-cli.zip from following URL: https://github.com/oracle/oci-cli/releases and ship and unzip the same on desired machine. The unzipped contents look similar to below.

#cd oci-cli
# ls -lrt
total 7888
drwxr-xr-x 5 root root    4096 Apr 20 20:04 oci_cli_docs
-rw-r--r-- 1 root root   41334 Apr 20 20:07 THIRD_PARTY_LICENSES.txt
-rw-r--r-- 1 root root 7871263 Apr 20 20:07 oci_cli-2.10.0-py2.py3-none-any.whl
-rw-r--r-- 1 root root   41206 Apr 20 20:07 LICENSE.txt
-rw-r--r-- 1 root root  108688 Apr 20 20:07 CHANGELOG.rst

Run the following command to install the oci binaries.

[root@mumbai oci-cli]# pip3 install /root/oci-cli/oci_cli-2.10.0-py2.py3-none-any.whl

7.Configure CLI:

Following steps are required to configure CLI.

A) Setup Config.
B) Upload Public Keys to OCI Console
C) Verify the CLI

A) Setup Config.

To set up confi execute command “oci setup config” from the local machine. The command asks for the details (user ocid,tenancy ocid,cloud region and key location )which were captured in previous steps. Please refer below output of the same.

[root@mumbai oci-cli]# oci setup config
This command provides a walkthrough of creating a valid CLI config file.

The following links explain where to find the information required by this
script:

User API Signing Key, OCID and Tenancy OCID:

https://docs.cloud.oracle.com/Content/API/Concepts/apisigningkey.htm#Other

Region:

https://docs.cloud.oracle.com/Content/General/Concepts/regions.htm

General config documentation:

https://docs.cloud.oracle.com/Content/API/Concepts/sdkconfig.htm


Enter a location for your config [/root/.oci/config]:
Enter a user OCID: <user OCID from previous steps>
Enter a tenancy OCID: <Tenancy OCID from previous steps>
Enter a region (e.g. ap-melbourne-1, ap-mumbai-1, ap-osaka-1, ap-seoul-1, ap-sydney-1, ap-tokyo-1, 
ca-montreal-1, ca-toronto-1, eu-amsterdam-1, eu-frankfurt-1, eu-zurich-1, me-jeddah-1, sa-saopaulo-1, 
uk-gov-london-1, uk-london-1, us-ashburn-1, us-gov-ashburn-1, us-gov-chicago-1, us-gov-phoenix-1, 
us-langley-1, us-luke-1, us-phoenix-1): ap-mumbai-1
Do you want to generate a new API Signing RSA key pair? (If you decline you will be asked to supply the path to an existing key.) [Y/n]: Y
Enter a directory for your keys to be created [/root/.oci]:
Enter a name for your key [oci_api_key]:
Public key written to: /root/.oci/oci_api_key_public.pem
Enter a passphrase for your private key (empty for no passphrase):
Private key written to: /root/.oci/oci_api_key.pem
Fingerprint: 00:0f:3d:95:c3:59:36:b6:40:50:4e:3d:95:4b:b3:cc
Config written to /root/.oci/config


If you haven't already uploaded your API Signing public key through the
console, follow the instructions on the page linked below in the section
'How to upload the public key':

https://docs.cloud.oracle.com/Content/API/Concepts/apisigningkey.htm#How2

The key points to make note of from above output for the next steps are:

Public key
Fingerprint

B) Upload Public Keys to OCI Console:

cat the public key from above output file and upload to OCI console.

[root@mumbai oci-cli]# cat /root/.oci/oci_api_key_public.pem
—–BEGIN PUBLIC KEY—–
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArhKuxh82TS6m29btmC0Y
YupEoHcSFEZOfPiCFWrb62QFuuAtevdcRaMjaHp5vR8Zma1t23xd4eJLZU2M+GgE
f9tYIa7A9y7Z+nO4sEP6y3+lVtbSJ1A2XQMPxMgP2WFVcfMIMd8BtqrOCS5Vbm0Y
j2JqTZT13d55yvpNa6O7CdisFp9JtbEnS/ahrjoceqAUYj0JUxY6Ui9OHEVpHNUV
29ZcrMv1eCzEiPGYi8YydJUSZIAV0ayIGB4cEOPWFXCczUqgDHj0IKQIML46QBIN
JUdSkErzudlsdpHRx1yv1OgpgfXCD96CKYroIrkte8C/7gbUN2WH5JrYU6Jxl2IM
qQIDAQAB
—–END PUBLIC KEY—–

For uploading to OCI console, login to the cloud account and go to Profile->user setting as below.

As highlighted, please check if the Fingerprint from the console matches with
the one captured earlier.

C) Verify the CLI:

Once done verify if you are able to list the resources and contents hosted in your respective
account. Below command gives the output in JSON format.

[root@mumbai oci-cli]# oci os ns get
{
“data”: “bmb9ypusa0sd”
}

The details can also can be obtained from tabular format using below command.

oci iam compartment list --output table --query "data [*].{Cname:name,OCID:id}"

[root@mumbai ~]# oci iam compartment list --output table --query "data [*].{Cname:name,OCID:id}"
+---------------------------+-------------------------------------------------------------------------------------+
| Cname | OCID |
+---------------------------+-------------------------------------------------------------------------------------+
| DEMO_COMPARTMENT | ocid1.compartment.oc1..aaaaaaaalvxje3bl3ux2zcixns5mdcqpz5bgduojcncavbhcbblcxlkkrlxq |
| dmeo_compartment.1HGlZnBO | ocid1.compartment.oc1..aaaaaaaa7lv27x5ylupxfaquwnc6zbdmr4zmus6cumdu7n7xmqomysdf2lca |
| ManagedCompartmentForPaaS | ocid1.compartment.oc1..aaaaaaaa3p67buwftfhvfgcqekyy42pv2ynzyszkwahkwcii4dopopnnxcbq |
| Rajesh | ocid1.compartment.oc1..aaaaaaaacphfut6uqg3tmuw5k2xjz7blrrgeyy3cwbsxjxss3fa7amd5hcuq |
| TC | ocid1.compartment.oc1..aaaaaaaasgjbxzx3bj6bqqerak44zxgcvytktztxbly7lbigc23xek5kwb2a |
+---------------------------+-------------------------------------------------------------------------------------+

References: [OCI]: How to Install and Configure Command Line Interface For Oracle Cloud Infrastructure In Linux (Doc ID 2432759.1)

How to Import and Move the Recovery Catalog

1.Requirements:

Target databases: PROD & MYDB
Catalog Database: mypdb1 & mypdb2

2.Configure catalog database:

Create catalog mypdb1:

SQL> create tablespace RC_CATALOG datafile '/db/NEWCDB/NEWCDB/SHIV//rc_db_01.dbf' size 100M ;

Tablespace created.

SQL> create user rc_owner identified by rc_owner;

User created.

SQL> grant recovery_catalog_owner to rc_owner;

Grant succeeded.

SQL> alter user rc_owner default tablespace RC_CATALOG;

User altered.

SQL> alter user rc_owner quota unlimited on RC_CATALOG;

User altered.

[oracle@NEWCDB sqlwork]$rman catalog rc_owner/rc_owner@mypdb1

Recovery Manager: Release 12.1.0.2.0 - Production on Sun Mar 8 12:55:53 2020

Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.

connected to recovery catalog database

RMAN> create catalog;

recovery catalog created

RMAN>

RMAN> list incarnation;

RMAN>

Repeat above steps to create catalog mypdb2.

3.Register database to catalog:

We will register database “PROD” to catalog “mypdb1” and “MYDB” to catalog “mypdb2” and list the incarnation of respective databases.

export ORACLE_SID=PROD
rman target / catalog rc_owner/rc_owner@mypdb1;

Recovery Manager: Release 12.1.0.2.0 - Production on Sun Mar 8 12:59:18 2020

Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.

connected to target database: PROD (DBID=443946281)
connected to recovery catalog database

RMAN> register database;

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

RMAN> list incarnation;


List of Database Incarnations
DB Key Inc Key DB Name DB ID STATUS Reset SCN Reset Time
------- ------- -------- ---------------- --- ---------- ----------
1 29 PROD 443946281 PARENT 1 2020-02-11 16:39:05
1 2 PROD 443946281 CURRENT 691578 2020-02-18 08:53:02

export ORACLE_SID=MYDB
rman target / catalog rc_owner/rc_owner@mypdb2;

Recovery Manager: Release 12.1.0.2.0 - Production on Sun Mar 8 12:59:48 2020

Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.

connected to target database: MYDB (DBID=2948889406)
connected to recovery catalog database

RMAN> register database;

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

RMAN> list incarnation;


List of Database Incarnations
DB Key Inc Key DB Name DB ID STATUS Reset SCN Reset Time
------- ------- -------- ---------------- --- ---------- ----------
1 16 MYDB 2948889406 PARENT 1 2014-07-07 05:38:47
1 2 MYDB 2948889406 CURRENT 1594143 2020-03-01 08:39:28

4.Import catalog mypdb1 to mypdb2:

Finally we will merge catalog mypdb1 into mypdb2.

[oracle@MYDB sqlwork]$rman target / catalog rc_owner/rc_owner@mypdb2

Recovery Manager: Release 12.1.0.2.0 - Production on Sun Mar 8 13:00:14 2020

Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.

connected to target database: MYDB (DBID=2948889406)
connected to recovery catalog database

RMAN> import catalog rc_owner/rc_owner@mypdb1;

Starting import catalog at 2020-03-08 13:00:20
connected to source recovery catalog database
import validation complete
database unregistered from the source recovery catalog
Finished import catalog at 2020-03-08 13:00:23

RMAN> list incarnation;


List of Database Incarnations
DB Key  Inc Key DB Name  DB ID            STATUS  Reset SCN  Reset Time
------- ------- -------- ---------------- --- ---------- ----------
1       16      MYDB     2948889406       PARENT  1          2014-07-07 05:38:47
1       2       MYDB     2948889406       CURRENT 1594143    2020-03-01 08:39:28
43      71      PROD     443946281        PARENT  1          2020-02-11 16:39:05
43      44      PROD     443946281        CURRENT 691578     2020-02-18 08:53:02

 

As we can see,now catalog mypdb2 lists incarnation of both the databases.