Snapshot client documentation confusion

Versions (relevant - OpenSearch/Dashboard/Server OS/Browser):
opensearch-py version 2.2.0
python version 3.9.2
Debian GNU/Linux 11 (bullseye)

Describe the issue:
I’m struggling to understand how to use the Snapshot client for opensearch-py

I’m mostly likely misunderstanding the documentation, but I got the impression that you first initialize the OpenSearch client and pass that to the Snapshot client like below, but I am getting an error [ERROR] AttributeError: ‘Client’ object has no attribute ‘transport’. It sounds like I’m not using the Snapshot class correctly, but I am struggling to find an example.

Am I using this API incorrectly? Does anyone have an example of how the Snapshot client should be used?

from opensearchpy import OpenSearch, RequestsHttpConnection
from opensearchpy.client.snapshot import SnapshotClient

host = '<host link>'
port = 443
auth = ("username", "password")

# create an opensearch client
os_client = OpenSearch(
        hosts = [{'host': host, 'port': port}],
        http_auth = auth,
        use_ssl = True,
        verify_certs = True,
        connection_class = RequestsHttpConnection)
snapshot_client = SnapshotClient(os_client)
snapshot_client.SnapshotClient.create_repository(
            repository='opensearch_backup',
            body={
                'type': 's3',
                'settings': {
                    'bucket': '<bucket-name>',
                    'region': '<region>',
                    'role_arn': '<arn>'
                }
            }
        )

Hey @sdhoyt

Before you use the API did you setup a repo in opensearch.yml file?

To use a shared file system as a snapshot repository, add it to opensearch.yml:

mkdir /mnt/snapshots
chown opensearch:opensearch -R /mnt/snapshots

Opensearch.yml file add the following.

path.repo: ["/mnt/snapshots"]

systemctl restart opensearch

Oh, I just realize your using opensearch.py, Not sure if that will work for ya

EDIT: I just came across this documentation, not sure if you seen it or if it will help.

https://opensearch-project.github.io/opensearch-py/api-ref/clients/snapshot_client.html

Thanks, I was looking at the opensearch-py documentation that you linked, but it’s not clear to me exactly how/if the OpenSearch object should be used in the Snapshot client. I do have an S3 bucket setup with the correct roles/policies (I think), but am running into an issue when I use the opensearch-py method to create the repository in the S3 bucket. But I don’t think the issue has to do with the inputs to the create_repository method, I think it’s how I’m using the opensearch-py Snapshot class and how/if that connects to the OpenSearch client object.

Hey,

I personally never used opensearch.py. This is new to me but caught my interest for sure.

Hello @sdhoyt, Thanks for letting us know about the missing documentation. I have created an issue to add a guide for snapshot API in opensearch-py repo. Please feel free to comment on it. :slight_smile:

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.