oracle/oci-python-sdk

volume backups are not getting all records in this list_volume_backups api call

Gopichand-Heeddata opened this issue · 8 comments

while running the list_volume_backups API call getting 82 records, but I have more than 1000 records even when I implemented pagination also got less records. @adizohar can you suggest the right API call?

import oci

config = oci.config.from_file()
identity_client = oci.identity.IdentityClient(config)

# Fetch list of compartments
compartments = identity_client.list_compartments(config['tenancy']).data

regions = identity_client.list_region_subscriptions(tenancy_id=config['tenancy']).data
blockstorage_client = oci.core.BlockstorageClient(config)

# Iterate over compartments
for compartment in compartments:
    compartment_id = compartment.id
    compartment_name = compartment.name
    print(f"Fetching backups for compartment: {compartment_name} ({compartment_id})")

    # Iterate over regions
    for region in regions:
        print(f"Fetching backups for compartment: {compartment_name} ({compartment_id}) in region {region.region_name}")

        # Fetch backups for each compartment in each region
        list_backups_response = blockstorage_client.list_boot_volume_backups(
            compartment_id=compartment_id,
            limit=1000
        ) 
        for backup in list_backups_response.data:
            print(backup)

I don't see any pagination on your code, also I don't see any use of region set, please check the code I wrote which has backups as well - https://github.com/oracle/oci-python-sdk/tree/master/examples/showoci

@adizohar here you can find.

import oci

config = oci.config.from_file()
identity_client = oci.identity.IdentityClient(config)

# Fetch list of compartments
compartments = identity_client.list_compartments(config['tenancy']).data

regions = identity_client.list_region_subscriptions(tenancy_id=config['tenancy']).data
blockstorage_client = oci.core.BlockstorageClient(config)

# Iterate over compartments
for compartment in compartments:
    compartment_id = compartment.id
    compartment_name = compartment.name
    print(f"Fetching backups for compartment: {compartment_name} ({compartment_id})")

    # Iterate over regions
    for region in regions:
        print(f"Fetching backups for compartment: {compartment_name} ({compartment_id}) in region {region.region_name}")

        list_backups_response= oci.pagination.list_call_get_all_results(
            oci.core.BlockstorageClient(config).list_volume_backups,
            compartment_id=compartment_id,
            limit=1000
        ).data
        for backup in list_backups_response:
            print(backup)
``

remove the region loop because it is not correct
change the call to below:

        list_backups_response= oci.pagination.list_call_get_all_results(
            blockstorage_client.list_volume_backups,
            compartment_id=compartment_id
        ).data

boot volume backup has different api calls which you need to add another loop

I have changed the code base but getting 42 records only. is the any limitation on this API call?
please provide resolution regarding this behaviours.

Are those on same compartments or other ? the list compartment you mentioned only list one level
Add this to the list compartment
compartment_id_in_subtree=True,
You should check the documentation for each API.
Also, as I mentioned, you only list backup on Volumes not boot volumes

If it is working, please close ticket and open new one for new .
Appreciate it.

working fine @adizohar closing this ticket.