Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,65 @@ AsyncIndex asyncIndex = pinecone.getAsyncIndexConnection("PINECONE_INDEX_NAME");
// Cancel import
asyncIndex.cancelImport("2");
```
# Backups and restore

The following example shows how to backup and restore from a serverless index.

```java
import io.pinecone.clients.Pinecone;
import org.openapitools.db_control.client.ApiException;
import org.openapitools.db_control.client.model.*;

...

Pinecone pinecone = new Pinecone.Builder("PINECONE_API_KEY").build();

String indexName1 = "test-index-1";
String indexName2 = "test-index-2";

// create a backup from index
BackupModel backupModel1 = pinecone.createBackup(indexName1, "backup-id-1", "description-for-backup-1");
System.out.println("backupModel1: " + backupModel1);

BackupModel backupModel2 = pinecone.createBackup(indexName2, "backup-id-2", "description-for-backup-2");
System.out.println("backupModel2: " + backupModel2);

// list all backups for an index
BackupList backupList = pinecone.listIndexBackups(indexName1);
System.out.println("backupList for index1: " + backupList);

// list all backups for a project
backupList = pinecone.listProjectBackups();
System.out.println("backupList for project: " + backupList);

// describe backup
backupModel1 = pinecone.describeBackup(backupModel1.getBackupId());
System.out.println("describe backup for index1: " + backupModel1);

backupModel2 = pinecone.describeBackup(backupModel2.getBackupId());
System.out.println("describe backup index2: " + backupModel2);

// delete backup
pinecone.deleteBackup(backupModel1.getBackupId());

// wait for the backup to be ready
Thread.sleep(10000);

// create index from a backup
CreateIndexFromBackupResponse backupResponse = pinecone.createIndexFromBackup(backupModel1.getBackupId(), "test-index-3");
System.out.println(backupResponse.getRestoreJobId());

// wait for index to be created
Thread.sleep(5000);

// describeRestoreJob
RestoreJobModel restoreJobModel = pinecone.describeRestoreJob(backupResponse.getRestoreJobId());
System.out.println("restore model: " + restoreJobModel);

// listRestoreJobs
RestoreJobList restoreJobList = pinecone.listRestoreJobs(2);
System.out.println("restore job list: " + restoreJobList);
```

## Examples

Expand Down
148 changes: 148 additions & 0 deletions src/main/java/io/pinecone/clients/Pinecone.java
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,154 @@ public void deleteIndex(String indexName) throws PineconeException {
}
}

/**
* Create a backup of an index
*
* @param indexName Name of the index to backup (required)
* @param backupName Name of the backup (optional)
* @param description A description of the backup. (optional)
* @return BackupModel
*/
public BackupModel createBackup(String indexName, String backupName, String description) throws ApiException {
return manageIndexesApi.createBackup(indexName,
new CreateBackupRequest().name(backupName).description(description));
}

/**
* Overload to list all backups for an index with default limit = 10 and pagination token = null.
*
* @param indexName Name of the backed up index (required)
* limit which is the number of results to return per page is set to 10 by default.
* paginationToken which is the token to use to retrieve the next page of results is set to null.
* @return BackupList
*/
public BackupList listIndexBackups(String indexName) throws ApiException {
return manageIndexesApi.listIndexBackups(indexName, 10, null);
}

/**
* List all backups for an index.
*
* @param indexName Name of the backed up index (required)
* @param limit The number of results to return per page. (optional, default to 10)
* @param paginationToken The token to use to retrieve the next page of results. (optional)
* @return BackupList
*/
public BackupList listIndexBackups(String indexName, Integer limit, String paginationToken) throws ApiException {
return manageIndexesApi.listIndexBackups(indexName, limit, paginationToken);
}

/**
* List backups for all indexes in a project
* List all backups for a project.
*
* @return BackupList
*/
public BackupList listProjectBackups() throws ApiException {
return manageIndexesApi.listProjectBackups();
}

/**
* Describe a backup
* Get a description of a backup.
*
* @param backupId The ID of the backup to describe. (required)
* @return BackupModel
*/
public BackupModel describeBackup(String backupId) throws ApiException {
return manageIndexesApi.describeBackup(backupId);
}

/**
* Delete a backup
*
* @param backupId The ID of the backup to delete. (required)
*/
public void deleteBackup(String backupId) throws ApiException {
manageIndexesApi.deleteBackup(backupId);
}

/**
* Create an index from a backup
*
* @param backupId The ID of the backup to create an index from. (required)
* @param indexName The name of the index. Resource name must be 1-45 characters long, start and end with an
* alphanumeric character, and consist only of lower case alphanumeric characters. (required)
* @param tags Custom user tags added to an index. (optional)
* @param deletionProtection Whether deletion protection is enabled for the index. If enabled, the index
* cannot be deleted. Defaults to disabled if not provided.
*/
public void createIndexFromBackup(String backupId, String indexName, Map<String, String> tags, DeletionProtection deletionProtection) throws ApiException {
CreateIndexFromBackupRequest createIndexFromBackupRequest = new CreateIndexFromBackupRequest()
.name(indexName)
.tags(tags);

if (deletionProtection != null) {
createIndexFromBackupRequest.deletionProtection(deletionProtection);
}
manageIndexesApi.createIndexFromBackup(backupId, createIndexFromBackupRequest);
}

/**
* Overload to create an index from a backup with name and backupId.
*
* @param backupId The ID of the backup to create an index from. (required)
* @param indexName The name of the index. Resource name must be 1-45 characters long, start and end with an
* alphanumeric character, and consist only of lower case alphanumeric characters. (required)
* cannot be deleted. Defaults to disabled if not provided.
* @return CreateIndexFromBackupResponse
*/
public CreateIndexFromBackupResponse createIndexFromBackup(String backupId, String indexName) throws ApiException {
CreateIndexFromBackupRequest createIndexFromBackupRequest = new CreateIndexFromBackupRequest()
.name(indexName);
return manageIndexesApi.createIndexFromBackup(backupId, createIndexFromBackupRequest);
}

/**
* Describe a restore job
* Get a description of a restore job.
*
* @param jobId The ID of the restore job to describe. (required)
* @return RestoreJobModel
*/
public RestoreJobModel describeRestoreJob(String jobId) throws ApiException {
return manageIndexesApi.describeRestoreJob(jobId);
}

/**
* Overload to list restore jobs
* List all restore jobs for a project.
*
* @param limit The number of results to return per page.
* @return RestoreJobList
*/
public RestoreJobList listRestoreJobs(Integer limit) throws ApiException {
return manageIndexesApi.listRestoreJobs(limit, null);
}

/**
* Overload to list restore jobs
* List all restore jobs for a project.
*
* @param paginationToken The token to use to retrieve the next page of results.
* @return RestoreJobList
*/
public RestoreJobList listRestoreJobs(String paginationToken) throws ApiException {
return manageIndexesApi.listRestoreJobs(10, paginationToken);
}

/**
* List restore jobs
* List all restore jobs for a project.
*
* @param limit The number of results to return per page. (optional, default to 10)
* @param paginationToken The token to use to retrieve the next page of results. (optional)
* @return RestoreJobList
*/
public RestoreJobList listRestoreJobs(Integer limit, String paginationToken) throws ApiException {
return manageIndexesApi.listRestoreJobs(limit, paginationToken);
}

/**
* Creates a new collection from a source index.
* <p>
Expand Down
Loading