Wednesday, November 26, 2025

How to Transfer Files Between an OCI VM (Compute Instance) and Object Storage (Part - 2)

How to Transfer Files Between an OCI VM (Compute Instance) and Object Storage (Part - 2)

Transferring a file from an OCI Compute Instance (VM) to Object Storage is one of the simplest and most reliable ways to store, archive, or share data.
Once your OCI CLI is installed and configured (as explained in Part - 1), you're ready for the next step.


Step 1: Verify You Have Access to the Bucket

Before uploading anything, check that:

- The bucket exists
- You have the right permissions (via IAM policy)
- Your CLI is configured for the correct region
- List the buckets in your compartment:
        oci os bucket list --compartment-id <compartment_ocid>

If the bucket you want appears, you're good to go.


Step 2: Upload a File

Use the oci os object put command to upload a file.

Basic Upload Command
oci os object put \
  --bucket-name <bucket_name> \
  --file <local_file_path>

Example

Suppose your file is /u01/backups/db_backup.tar.gz and your bucket is my-backup-bucket:

oci os object put \
  --bucket-name my-backup-bucket \
  --file /u01/backups/db_backup.tar.gz

What Happens Here?
-> OCI CLI uploads the file
-> The object appears inside the bucket with the same filename
-> If the object already exists, it will be overwritten unless you disable overwrite

If you want to specify a different object name:
Example:
oci os object put \
  --bucket-name my-backup-bucket \
  --file db_backup.tar.gz \
  --name MY_Backup_26Nov2025.tar.gz

Bulk Upload files using below command
Example:
oci os object bulk-upload \
  -bn my-backup-bucket \
  --src-dir /u01/RMANBackup26Nov2025 \
  --include "*.bkp" \
  --prefix rman/

Upload Large Files
For large files (GBs or TB-scale), use the --part-size option.

Example:
oci os object put \
  --bucket-name my-backup-bucket \
  --file db_backup.tar.gz \
  --part-size 64

Step 3: Verify Upload
List objects inside the bucket:

oci os object list --bucket-name my-backup-bucket

To confirm size or metadata:
oci os object head \
  --bucket-name my-backup-bucket \
  --name db_backup.tar.gz


🎉 That's It!

You’ve now successfully uploaded files from a VM to Object Storage using OCI CLI.
This is the method I use daily for backups and log transfers.

In the next article, we will go the opposite direction — downloading files from Object Storage to a private subnet VM, even when it has no public internet access.


Thanks & Regards,
Chandan Tanwani

No comments: