Skip to content

Commit f689641

Browse files
authored
add support for backups and restore (#185)
## Problem Add support for backups and restore. ## Solution Added support for backups and restore. Following code exactly shows how to add a backup from an index and restore a serverless index from a backup. ```java import io.pinecone.clients.Pinecone; import org.openapitools.db_control.client.ApiException; import org.openapitools.db_control.client.model.*; public class restoreAndBackups { public static void main(String[] args) throws ApiException, InterruptedException { 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); } } ``` ## Type of Change - [X] New feature (non-breaking change which adds functionality) ## Test Plan Manually tested backups and restore by running the sample code above.
1 parent e2a7fc0 commit f689641

File tree

2 files changed

+207
-0
lines changed

2 files changed

+207
-0
lines changed

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,65 @@ AsyncIndex asyncIndex = pinecone.getAsyncIndexConnection("PINECONE_INDEX_NAME");
766766
// Cancel import
767767
asyncIndex.cancelImport("2");
768768
```
769+
# Backups and restore
770+
771+
The following example shows how to backup and restore from a serverless index.
772+
773+
```java
774+
import io.pinecone.clients.Pinecone;
775+
import org.openapitools.db_control.client.ApiException;
776+
import org.openapitools.db_control.client.model.*;
777+
778+
...
779+
780+
Pinecone pinecone = new Pinecone.Builder("PINECONE_API_KEY").build();
781+
782+
String indexName1 = "test-index-1";
783+
String indexName2 = "test-index-2";
784+
785+
// create a backup from index
786+
BackupModel backupModel1 = pinecone.createBackup(indexName1, "backup-id-1", "description-for-backup-1");
787+
System.out.println("backupModel1: " + backupModel1);
788+
789+
BackupModel backupModel2 = pinecone.createBackup(indexName2, "backup-id-2", "description-for-backup-2");
790+
System.out.println("backupModel2: " + backupModel2);
791+
792+
// list all backups for an index
793+
BackupList backupList = pinecone.listIndexBackups(indexName1);
794+
System.out.println("backupList for index1: " + backupList);
795+
796+
// list all backups for a project
797+
backupList = pinecone.listProjectBackups();
798+
System.out.println("backupList for project: " + backupList);
799+
800+
// describe backup
801+
backupModel1 = pinecone.describeBackup(backupModel1.getBackupId());
802+
System.out.println("describe backup for index1: " + backupModel1);
803+
804+
backupModel2 = pinecone.describeBackup(backupModel2.getBackupId());
805+
System.out.println("describe backup index2: " + backupModel2);
806+
807+
// delete backup
808+
pinecone.deleteBackup(backupModel1.getBackupId());
809+
810+
// wait for the backup to be ready
811+
Thread.sleep(10000);
812+
813+
// create index from a backup
814+
CreateIndexFromBackupResponse backupResponse = pinecone.createIndexFromBackup(backupModel1.getBackupId(), "test-index-3");
815+
System.out.println(backupResponse.getRestoreJobId());
816+
817+
// wait for index to be created
818+
Thread.sleep(5000);
819+
820+
// describeRestoreJob
821+
RestoreJobModel restoreJobModel = pinecone.describeRestoreJob(backupResponse.getRestoreJobId());
822+
System.out.println("restore model: " + restoreJobModel);
823+
824+
// listRestoreJobs
825+
RestoreJobList restoreJobList = pinecone.listRestoreJobs(2);
826+
System.out.println("restore job list: " + restoreJobList);
827+
```
769828

770829
## Examples
771830

src/main/java/io/pinecone/clients/Pinecone.java

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,154 @@ public void deleteIndex(String indexName) throws PineconeException {
874874
}
875875
}
876876

877+
/**
878+
* Create a backup of an index
879+
*
880+
* @param indexName Name of the index to backup (required)
881+
* @param backupName Name of the backup (optional)
882+
* @param description A description of the backup. (optional)
883+
* @return BackupModel
884+
*/
885+
public BackupModel createBackup(String indexName, String backupName, String description) throws ApiException {
886+
return manageIndexesApi.createBackup(indexName,
887+
new CreateBackupRequest().name(backupName).description(description));
888+
}
889+
890+
/**
891+
* Overload to list all backups for an index with default limit = 10 and pagination token = null.
892+
*
893+
* @param indexName Name of the backed up index (required)
894+
* limit which is the number of results to return per page is set to 10 by default.
895+
* paginationToken which is the token to use to retrieve the next page of results is set to null.
896+
* @return BackupList
897+
*/
898+
public BackupList listIndexBackups(String indexName) throws ApiException {
899+
return manageIndexesApi.listIndexBackups(indexName, 10, null);
900+
}
901+
902+
/**
903+
* List all backups for an index.
904+
*
905+
* @param indexName Name of the backed up index (required)
906+
* @param limit The number of results to return per page. (optional, default to 10)
907+
* @param paginationToken The token to use to retrieve the next page of results. (optional)
908+
* @return BackupList
909+
*/
910+
public BackupList listIndexBackups(String indexName, Integer limit, String paginationToken) throws ApiException {
911+
return manageIndexesApi.listIndexBackups(indexName, limit, paginationToken);
912+
}
913+
914+
/**
915+
* List backups for all indexes in a project
916+
* List all backups for a project.
917+
*
918+
* @return BackupList
919+
*/
920+
public BackupList listProjectBackups() throws ApiException {
921+
return manageIndexesApi.listProjectBackups();
922+
}
923+
924+
/**
925+
* Describe a backup
926+
* Get a description of a backup.
927+
*
928+
* @param backupId The ID of the backup to describe. (required)
929+
* @return BackupModel
930+
*/
931+
public BackupModel describeBackup(String backupId) throws ApiException {
932+
return manageIndexesApi.describeBackup(backupId);
933+
}
934+
935+
/**
936+
* Delete a backup
937+
*
938+
* @param backupId The ID of the backup to delete. (required)
939+
*/
940+
public void deleteBackup(String backupId) throws ApiException {
941+
manageIndexesApi.deleteBackup(backupId);
942+
}
943+
944+
/**
945+
* Create an index from a backup
946+
*
947+
* @param backupId The ID of the backup to create an index from. (required)
948+
* @param indexName The name of the index. Resource name must be 1-45 characters long, start and end with an
949+
* alphanumeric character, and consist only of lower case alphanumeric characters. (required)
950+
* @param tags Custom user tags added to an index. (optional)
951+
* @param deletionProtection Whether deletion protection is enabled for the index. If enabled, the index
952+
* cannot be deleted. Defaults to disabled if not provided.
953+
*/
954+
public void createIndexFromBackup(String backupId, String indexName, Map<String, String> tags, DeletionProtection deletionProtection) throws ApiException {
955+
CreateIndexFromBackupRequest createIndexFromBackupRequest = new CreateIndexFromBackupRequest()
956+
.name(indexName)
957+
.tags(tags);
958+
959+
if (deletionProtection != null) {
960+
createIndexFromBackupRequest.deletionProtection(deletionProtection);
961+
}
962+
manageIndexesApi.createIndexFromBackup(backupId, createIndexFromBackupRequest);
963+
}
964+
965+
/**
966+
* Overload to create an index from a backup with name and backupId.
967+
*
968+
* @param backupId The ID of the backup to create an index from. (required)
969+
* @param indexName The name of the index. Resource name must be 1-45 characters long, start and end with an
970+
* alphanumeric character, and consist only of lower case alphanumeric characters. (required)
971+
* cannot be deleted. Defaults to disabled if not provided.
972+
* @return CreateIndexFromBackupResponse
973+
*/
974+
public CreateIndexFromBackupResponse createIndexFromBackup(String backupId, String indexName) throws ApiException {
975+
CreateIndexFromBackupRequest createIndexFromBackupRequest = new CreateIndexFromBackupRequest()
976+
.name(indexName);
977+
return manageIndexesApi.createIndexFromBackup(backupId, createIndexFromBackupRequest);
978+
}
979+
980+
/**
981+
* Describe a restore job
982+
* Get a description of a restore job.
983+
*
984+
* @param jobId The ID of the restore job to describe. (required)
985+
* @return RestoreJobModel
986+
*/
987+
public RestoreJobModel describeRestoreJob(String jobId) throws ApiException {
988+
return manageIndexesApi.describeRestoreJob(jobId);
989+
}
990+
991+
/**
992+
* Overload to list restore jobs
993+
* List all restore jobs for a project.
994+
*
995+
* @param limit The number of results to return per page.
996+
* @return RestoreJobList
997+
*/
998+
public RestoreJobList listRestoreJobs(Integer limit) throws ApiException {
999+
return manageIndexesApi.listRestoreJobs(limit, null);
1000+
}
1001+
1002+
/**
1003+
* Overload to list restore jobs
1004+
* List all restore jobs for a project.
1005+
*
1006+
* @param paginationToken The token to use to retrieve the next page of results.
1007+
* @return RestoreJobList
1008+
*/
1009+
public RestoreJobList listRestoreJobs(String paginationToken) throws ApiException {
1010+
return manageIndexesApi.listRestoreJobs(10, paginationToken);
1011+
}
1012+
1013+
/**
1014+
* List restore jobs
1015+
* List all restore jobs for a project.
1016+
*
1017+
* @param limit The number of results to return per page. (optional, default to 10)
1018+
* @param paginationToken The token to use to retrieve the next page of results. (optional)
1019+
* @return RestoreJobList
1020+
*/
1021+
public RestoreJobList listRestoreJobs(Integer limit, String paginationToken) throws ApiException {
1022+
return manageIndexesApi.listRestoreJobs(limit, paginationToken);
1023+
}
1024+
8771025
/**
8781026
* Creates a new collection from a source index.
8791027
* <p>

0 commit comments

Comments
 (0)