I have two buckets in different regions in OCI object store. I want to compare files in the two buckets using Oracle Autonomous Database, to detect missing files and copy them over and synchronize the two buckets. I use the two buckets in different regions as replicating some configuration metadata between the services running in the two regions.
Eg:
- Bucket1 = 'https://objectstorage.us-ashburn-1.oraclecloud.com/n/mynamespace/b/mybucket/folder1/'
- Bucket2 = 'https://objectstorage.us-phoenix-1.oraclecloud.com/n/mynamespace/b/mybucket/folder1/'
Oracle Autonomous Database provides the DBMS_CLOUD package for accessing object store files.
DBMS_CLOUD package has a function LIST_OBJECTS, which provides a list of files in an object store location (bucket or subfolder). This function provides the object name , size in bytes and checksum, which can be used to compare files in the 2 buckets with the help of Oracle SQL FULL OUTER JOIN and WITH Clause.
SQL Script:
Explanation:
In the above script:
Use Cases:
The DBMS_CLOUD package works for multiple object stores such as Oracle OCI, AWS S3, Azure BLOB, Google Cloud, Wasabi, so the above script can be used to compare buckets in multiple scenarios such as -
References: