Baking Clouds Ltd

Baking Clouds provide tailored IT consultancy services to small and medium-sized companies; we cover all aspects of IT without any hidden costs.

Working with Oracle Cloud Storage from the Command Line

Baking Clouds - Oracle Cloud Storage from the Command Line

In our previous post we talked about general aspects of Oracle Cloud Storage Buckets, and this time we will go through some basic commands to manage buckets, objects and versioning. Enjoy!

Introduction

Oracle Cloud Infrastructure Cloud (OCI) Shell is a web browser-based terminal accessible from the Oracle Cloud Console. Cloud Shell is free to use (within monthly tenancy limits), and provides access to a Linux shell, with a pre-authenticated Oracle Cloud Infrastructure CLI, a pre-authenticated Ansible installation, and other useful tools for following Oracle Cloud Infrastructure service tutorials and labs. Cloud Shell is a feature available to all OCI users, accessible from the Console.

Cloud Shell provides:

  • An ephemeral machine to use as a host for a Linux shell, pre-configured with the latest version of the OCI Command Line Interface (CLI) and a number of useful tools
  • 5GB of storage for your home directory
  • A persistent frame of the Console which stays active as you navigate to different pages of the console

Create a bucket

1. Click the Cloud Shell icon in the upper-right corner of the Console:

Baking Clouds - Working with Oracle Cloud Storage from the Command Line

In the default bash prompt in Cloud Shell, the region that the OCI CLI is interacting with is echoed in the Cloud Shell command line prompt:

Baking Clouds - Working with Oracle Cloud Storage from the Command Line

2. Enter the following command to list the available commands and help topics in

oci os bucket -h

pressing spacebar to advance the output:

Baking Clouds - Working with Oracle Cloud Storage from the Command Line

3. Create a bucket using the oci os bucket create command:

oci os bucket create --name bucket-test --compartment-id ocid1.tenancy.oc1..aaaaaaaaxe5a7xuzsrqawsih2kzxm2cricjz2gr7izr574pnukxp2haaqp4q
Baking Clouds - Working with Oracle Cloud Storage from the Command Line

In this case we have created a Standard Bucket with Storage Tier Standard, with Private access. As we’ve seen in the help, you can customize the settings adding more parameters.

Uploading Files to Oracle Cloud Storage

The oci os bucket command is very versatile. You can upload files from local storage or objects from other Cloud Storage buckets.

Download a couple of sample image file to an images directory:

mkdir images
curl -o images/oraclecloud.png https://github.com/bakingclouds/oraclecloud/oraclecloud.png
Baking Clouds - Working with Oracle Cloud Storage from the Command Line

Upload the file from images directory to your Cloud Storage bucket:

oci os object bulk-upload -ns axzt5tlh3ol3 -bn bucket-test --src-dir /home/aliciathom/images
Baking Clouds - Working with Oracle Cloud Storage from the Command Line

Understanding Object Versioning

With Cloud Storage is possible of keeping track of any object version. This helps you to recover from unintended removal and alteration.
You can enable object versioning at bucket creation time or later. Versioning is disabled by default.
Each Object Storage bucket has object versioning status of disabled, enabled, or suspended

List the details of the bucket to observe the status of versioning

oci os bucket get --namespace MyNamespace --name MyBucket

Example
oci os bucket get --namespace axzt5tlh3ol3 --name bucket-test		
Baking Clouds - Working with Oracle Cloud Storage from the Command Line

Use the oci os bucket update command to enable versioning:

oci os bucket update --namespace mynamespace --name bucketname --versioning [text]
Example
oci os bucket update --namespace axzt5tlh3ol3 --name bucket-test --versioning Enabled
Baking Clouds - Working with Oracle Cloud Storage from the Command Line

Upload an empty text file to the bucket and inspect its generation number:

touch plan.txt
 oci os object put --file /home/aliciathom/images/plan.txt --namespace axzt5tlh3ol3 --bucket-name bucket-test
Baking Clouds - Working with Oracle Cloud Storage from the Command Line

To see the version number assigned to the file:

oci os object head --namespace <object_storage_namespace> --bucket-name <bucket_name> --name <object_name>
Example:
oci os object head --namespace axzt5tlh3ol3 --bucket-name bucket-test --name plan.txt
Baking Clouds - Working with Oracle Cloud Storage from the Command Line

Upload a new version of plan.txt and see the new version ID:

Baking Clouds - Working with Oracle Cloud Storage from the Command Line

From GUI you can also see all versions:

Baking Clouds - Working with Oracle Cloud Storage from the Command Line

We hope you enjoyed this post! If you like it or want us to include more information click the button below to send us your comments. Thanks!!

Reference Documents

Object Versioning https://docs.cloud.oracle.com/en-us/iaas/Content/Object/Tasks/usingversioning.htm

Managing Objects https://docs.cloud.oracle.com/en-us/iaas/Content/Object/Tasks/managingobjects.htm

OCI CLI Command Guide https://docs.cloud.oracle.com/en-us/iaas/tools/oci-cli/2.13.0/oci_cli_docs/cmdref/os/bucket/update.html

Working with Oracle Cloud Storage from the Command Line
Scroll to top