Skip to content

Commit 3c8242d

Browse files
Implement Backups/Restore (#109)
## Problem Backups/Restore are a part of the `2025-04` spec and need to be implemented in the Go client. ## Solution Add new types for working with `Backups` and `RestoreJob` methods on `Client`: - `Backup` - `BackupList` - `RestoreJob` - `RestoreJobList` - `CreateBackupParams` - `CreateIndexFromBackupParams` - `CreateIndexFromBackupResponse` - `ListBackupsParams` - `ListRestoreJobsParams` Add new methods for working with backups as a part of `Client`: - `CreateBackup` - `CreateIndexFromBackup` - `DescribeBackup` - `DeleteBackup` - `DescribeRestoreJob` - `ListBackups` - `ListRestoreJobs` ## Type of Change - [ ] Bug fix (non-breaking change which fixes an issue) - [X] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update - [ ] Infrastructure change (CI configs, etc) - [ ] Non-code change (docs, etc) - [ ] None of the above: (explain here) ## Test Plan CI - unit & integration tests New integration tests have been added to validate the create backup -> list/describe backups -> create index from backup -> list/describe restore jobs flow. You can also test using the `README` or the integration tests themselves as example code: ```go package main import ( "context" "fmt" "log" "os" "time" "github.com/pinecone-io/go-pinecone/v3/pinecone" ) ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: os.Getenv("PINECONE_API_KEY"), } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %w", err) } indexName := "my-index" backupName := fmt.Sprintf("backup-%s", ) backupDesc := fmt.Sprintf("Backup created for index %s", indexName) fmt.Printf("Creating backup: %s for index: %s\n", backupName, indexName) backup, err := pc.CreateBackup(ctx, &pinecone.CreateBackupParams{ IndexName: indexName, Name: &backupName, Description: &backupDesc, }) if err != nil { log.Fatalf("Failed to create backup: %w", err) } backup, err = pc.DescribeBackup(ctx, backup.BackupId) if err != nil { log.Fatalf("Failed to describe backup: %w", err) } // wait for backup to be "Complete" before triggering a restore job log.Printf("Backup status: %v", backup.Status) limit := 10 backups, err := pc.ListBackups(ctx, &pinecone.ListBackupsParams{ Limit: &limit, IndexName: &indexName, }) if err != nil { log.Fatalf("Failed to list backups: %w", err) } // create a new serverless index from the backup restoredIndexName := indexName + "-from-backup" restoredIndexTags := IndexTags{"restored_on": time.Now().Format("2006-01-02 15:04")} createIndexFromBackupResp, err := pc.CreateIndexFromBackup(context.Background(), &CreateIndexFromBackupParams{ BackupId: ts.backupId, Name: restoredIndexName, Tags: &restoredIndexTags, }) // check the status of the index restoration restoreJob, err := pc.DescribeRestoreJob(ctx, restoreJob.RestoreJobId) if err != nil { log.Fatalf("Failed to describe restore job: %w", err) } ``` --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1209571416750587
1 parent 2034fed commit 3c8242d

File tree

6 files changed

+875
-75
lines changed

6 files changed

+875
-75
lines changed

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,69 @@ func main() {
16301630
}
16311631
```
16321632

1633+
## Backups
1634+
1635+
A backup is a static copy of a serverless index that only consumes storage. It is a non-queryable representation of a set of records. You can create a backup of a serverless index, and you can create a new serverless index from a backup. You can optionally apply new `Tags` and `DeletionProtection` configurations for the index when calling `CreateIndexFromBackup`. You can read more about [backups here](https://docs.pinecone.io/guides/manage-data/backups-overview).
1636+
1637+
```go
1638+
ctx := context.Background()
1639+
1640+
clientParams := pinecone.NewClientParams{
1641+
ApiKey: os.Getenv("PINECONE_API_KEY"),
1642+
}
1643+
1644+
pc, err := pinecone.NewClient(clientParams)
1645+
if err != nil {
1646+
log.Fatalf("Failed to create Client: %w", err)
1647+
}
1648+
1649+
indexName := "my-index"
1650+
backupName := fmt.Sprintf("backup-%s", )
1651+
backupDesc := fmt.Sprintf("Backup created for index %s", indexName)
1652+
fmt.Printf("Creating backup: %s for index: %s\n", backupName, indexName)
1653+
1654+
backup, err := pc.CreateBackup(ctx, &pinecone.CreateBackupParams{
1655+
IndexName: indexName,
1656+
Name: &backupName,
1657+
Description: &backupDesc,
1658+
})
1659+
if err != nil {
1660+
log.Fatalf("Failed to create backup: %w", err)
1661+
}
1662+
1663+
backup, err = pc.DescribeBackup(ctx, backup.BackupId)
1664+
if err != nil {
1665+
log.Fatalf("Failed to describe backup: %w", err)
1666+
}
1667+
1668+
// wait for backup to be "Complete" before triggering a restore job
1669+
log.Printf("Backup status: %v", backup.Status)
1670+
1671+
limit := 10
1672+
backups, err := pc.ListBackups(ctx, &pinecone.ListBackupsParams{
1673+
Limit: &limit,
1674+
IndexName: &indexName,
1675+
})
1676+
if err != nil {
1677+
log.Fatalf("Failed to list backups: %w", err)
1678+
}
1679+
1680+
// create a new serverless index from the backup
1681+
restoredIndexName := indexName + "-from-backup"
1682+
restoredIndexTags := pinecone.IndexTags{"restored_on": time.Now().Format("2006-01-02 15:04")}
1683+
createIndexFromBackupResp, err := pc.CreateIndexFromBackup(context.Background(), &pinecone.CreateIndexFromBackupParams{
1684+
BackupId: ts.backupId,
1685+
Name: restoredIndexName,
1686+
Tags: &restoredIndexTags,
1687+
})
1688+
1689+
// check the status of the index restoration
1690+
restoreJob, err := pc.DescribeRestoreJob(ctx, restoreJob.RestoreJobId)
1691+
if err != nil {
1692+
log.Fatalf("Failed to describe restore job: %w", err)
1693+
}
1694+
```
1695+
16331696
## Inference
16341697

16351698
The `Client` object has an `Inference` namespace which exposes an `InferenceService` pointer which allows interacting with Pinecone's [Inference API](https://docs.pinecone.io/guides/inference/generate-embeddings).

0 commit comments

Comments
 (0)