Monday, August 1, 2022

How to install OCI CLI in windows and push backup to object storage

 How to install OCI CLI in windows and push backup to object storage

Documentation link : https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/cliinstall.htm#InstallingCLI__windows

OCI provides CLI to mange your cloud account. You can do almost all the task which you are doing using console can be done using CLI.

Here, we are going to install CLI on a windows 2019 server and push the backup files to Object Storage.

Login to your windows VM


Right click on “Windows PowerShell” and open as administrator.


Issue the following commands


Set-ExecutionPolicy RemoteSigned


Invoke-WebRequest https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.ps1 -OutFile install.ps1

iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.ps1'))


This will install Python automatically. OCI CLI is build on Python






Now you can see the oci cli installation is good. 

# oci --version will return the cli version.

Next step is to setup the cli configuration. We need to authorise the configuration to perform actions. This is based on the user permissions.

# oci setup config

Enter the location of your config [C:\Users\opc\.config] :

Enter user OCID : 

 

Tenancy OCID :


Chose your DC Region :


Do you want to generate API key : Y


Enter directory for your keys to created [C:\Users\opc\.oci]


Enter a name for your key [oci_api_key] :


Passphrase :


Now we need to upload your public key




After this step, you should able to interact with your oracle cloud account using oci cli.

For testing, issue this command

# oci os ns get ( This will return back the namespace of our account)


This means we are good !

How to copy backup files from this windows VM to object storage.


# oci os object put [options]

-bn = bucket name
--file = filename

# oci os object put -bn my-upload-bucket --file mssql-july31.sql

In this example, the backup file is mssql-july31.sql and this should be in the path or you need to add the full path and the bucket name is my-upload-bucket.