Rename restorepoint to backup (#314)

This commit is contained in:
Vaibhav Kamra 2022-07-11 09:06:04 -07:00 committed by GitHub
parent e5f5c38d4e
commit fa190da682
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 130 additions and 136 deletions

View File

@ -59,7 +59,7 @@ func handleCreateCmd(cmd *cobra.Command, args []string) {
var listCommand = "list"
var listCmd = &cobra.Command{
Use: listCommand,
Short: "List the history of restore points for a service",
Short: "List the history of backups for a service",
Run: handleListCmd,
Args: cobra.NoArgs,
}
@ -75,7 +75,7 @@ func handleListCmd(cmd *cobra.Command, args []string) {
var detailsCommand = "details"
var detailsCmd = &cobra.Command{
Use: detailsCommand,
Short: "Shows the details of a restore point for a service",
Short: "Shows the details of a backup for a service",
Run: handleDetailsCmd,
Args: cobra.NoArgs,
}

View File

@ -17,8 +17,8 @@ import (
// exchange bucket info from flags
var (
user string
rpID string
user string
backupDetailsID string
)
// called by backup.go to map parent subcommands to provider-specific handling.
@ -35,8 +35,8 @@ func addExchangeCommands(parent *cobra.Command) *cobra.Command {
c, _ = utils.AddCommand(parent, exchangeListCmd)
case detailsCommand:
c, fs = utils.AddCommand(parent, exchangeDetailsCmd)
fs.StringVar(&rpID, "restore-point-details", "", "ID of the restore point details to be shown.")
c.MarkFlagRequired("restore-point-details")
fs.StringVar(&backupDetailsID, "backup-details", "", "ID of the backup details to be shown.")
c.MarkFlagRequired("backup-details")
}
return c
}
@ -94,8 +94,8 @@ func createExchangeCmd(cmd *cobra.Command, args []string) error {
return errors.Wrap(err, "Failed to run Exchange backup")
}
// todo: revive when restorePoints are hooked up to backupOperation results
// fmt.Printf("Backed up restore point %s in %s for Exchange user %s.\n", result.SnapshotID, s.Provider, user)
// todo: revive when backups are hooked up to backupOperation results
// fmt.Printf("Created backup %s in %s for Exchange user %s.\n", result.SnapshotID, s.Provider, user)
return nil
}
@ -131,9 +131,9 @@ func listExchangeCmd(cmd *cobra.Command, args []string) error {
}
defer utils.CloseRepo(ctx, r)
rps, err := r.RestorePoints(ctx)
rps, err := r.Backups(ctx)
if err != nil {
return errors.Wrap(err, "Failed to list restorepoints in the repository")
return errors.Wrap(err, "Failed to list backups in the repository")
}
// TODO: Can be used to print in alternative forms (e.g. json)
@ -180,9 +180,9 @@ func detailsExchangeCmd(cmd *cobra.Command, args []string) error {
}
defer utils.CloseRepo(ctx, r)
rpd, err := r.RestorePointDetails(ctx, rpID)
rpd, err := r.BackupDetails(ctx, backupDetailsID)
if err != nil {
return errors.Wrap(err, "Failed to get restorepoint details in the repository")
return errors.Wrap(err, "Failed to get backup details in the repository")
}
// TODO: Can be used to print in alternative forms

View File

@ -15,10 +15,10 @@ import (
// exchange bucket info from flags
var (
folder string
mail string
restorePointID string
user string
folder string
mail string
backupID string
user string
)
// called by restore.go to map parent subcommands to provider-specific handling.
@ -33,8 +33,8 @@ func addExchangeCommands(parent *cobra.Command) *cobra.Command {
c, fs = utils.AddCommand(parent, exchangeRestoreCmd)
fs.StringVar(&folder, "folder", "", "Name of the mail folder being restored")
fs.StringVar(&mail, "mail", "", "ID of the mail message being restored")
fs.StringVar(&restorePointID, "restore-point", "", "ID of the backup restore point")
c.MarkFlagRequired("restore-point")
fs.StringVar(&backupID, "backup", "", "ID of the backup to restore")
c.MarkFlagRequired("backup")
fs.StringVar(&user, "user", "", "ID of the user whose exchange data will get restored")
}
return c
@ -58,7 +58,7 @@ func restoreExchangeCmd(cmd *cobra.Command, args []string) error {
return nil
}
if err := validateRestoreFlags(user, folder, mail, restorePointID); err != nil {
if err := validateRestoreFlags(user, folder, mail, backupID); err != nil {
return errors.Wrap(err, "Missing required flags")
}
@ -74,7 +74,7 @@ func restoreExchangeCmd(cmd *cobra.Command, args []string) error {
logger.Ctx(ctx).Debugw(
"Called - "+cmd.CommandPath(),
"restorePointID", restorePointID,
"backupID", backupID,
"tenantID", m365.TenantID,
"clientID", m365.ClientID,
"hasClientSecret", len(m365.ClientSecret) > 0)
@ -85,7 +85,7 @@ func restoreExchangeCmd(cmd *cobra.Command, args []string) error {
}
defer utils.CloseRepo(ctx, r)
ro, err := r.NewRestore(ctx, restorePointID, []string{m365.TenantID, user, "mail", folder, mail})
ro, err := r.NewRestore(ctx, backupID, []string{m365.TenantID, user, "mail", folder, mail})
if err != nil {
return errors.Wrap(err, "Failed to initialize Exchange restore")
}
@ -98,9 +98,9 @@ func restoreExchangeCmd(cmd *cobra.Command, args []string) error {
return nil
}
func validateRestoreFlags(u, f, m, rpid string) error {
if len(rpid) == 0 {
return errors.New("a restore point ID is requried")
func validateRestoreFlags(u, f, m, bID string) error {
if len(bID) == 0 {
return errors.New("a backup ID is requried")
}
lu, lf, lm := len(u), len(f), len(m)
if (lu == 0 || u == "*") && (lf+lm > 0) {

View File

@ -31,7 +31,7 @@ func (suite *ExchangeSuite) TestValidateRestoreFlags() {
{"mail missing user", "", "", "m", "rpid", assert.Error},
{"mail missing folder", "u", "", "m", "rpid", assert.Error},
{"mail with wildcard folder", "u", "*", "m", "rpid", assert.Error},
{"missing restore point id", "u", "f", "m", "", assert.Error},
{"missing backup id", "u", "f", "m", "", assert.Error},
{"all missing", "", "", "", "rpid", assert.NoError},
}
for _, test := range table {

View File

@ -3,11 +3,11 @@ package exchange
import (
"time"
"github.com/alcionai/corso/pkg/restorepoint"
"github.com/alcionai/corso/pkg/backup"
"github.com/microsoftgraph/msgraph-sdk-go/models"
)
func MessageInfo(msg models.Messageable) *restorepoint.ExchangeInfo {
func MessageInfo(msg models.Messageable) *backup.ExchangeInfo {
sender := ""
subject := ""
received := time.Time{}
@ -22,7 +22,7 @@ func MessageInfo(msg models.Messageable) *restorepoint.ExchangeInfo {
if msg.GetReceivedDateTime() != nil {
received = *msg.GetReceivedDateTime()
}
return &restorepoint.ExchangeInfo{
return &backup.ExchangeInfo{
Sender: sender,
Subject: subject,
Received: received,

View File

@ -4,7 +4,7 @@ import (
"testing"
"time"
"github.com/alcionai/corso/pkg/restorepoint"
"github.com/alcionai/corso/pkg/backup"
"github.com/microsoftgraph/msgraph-sdk-go/models"
"github.com/stretchr/testify/suite"
)
@ -20,17 +20,17 @@ func TestMessageSuite(t *testing.T) {
func (suite *MessageSuite) TestMessageInfo() {
tests := []struct {
name string
msgAndRP func() (models.Messageable, *restorepoint.ExchangeInfo)
msgAndRP func() (models.Messageable, *backup.ExchangeInfo)
}{
{
name: "Empty message",
msgAndRP: func() (models.Messageable, *restorepoint.ExchangeInfo) {
return models.NewMessage(), &restorepoint.ExchangeInfo{}
msgAndRP: func() (models.Messageable, *backup.ExchangeInfo) {
return models.NewMessage(), &backup.ExchangeInfo{}
},
},
{
name: "Just sender",
msgAndRP: func() (models.Messageable, *restorepoint.ExchangeInfo) {
msgAndRP: func() (models.Messageable, *backup.ExchangeInfo) {
sender := "foo@bar.com"
sr := models.NewRecipient()
sea := models.NewEmailAddress()
@ -38,30 +38,30 @@ func (suite *MessageSuite) TestMessageInfo() {
sea.SetAddress(&sender)
sr.SetEmailAddress(sea)
msg.SetSender(sr)
return msg, &restorepoint.ExchangeInfo{Sender: sender}
return msg, &backup.ExchangeInfo{Sender: sender}
},
},
{
name: "Just subject",
msgAndRP: func() (models.Messageable, *restorepoint.ExchangeInfo) {
msgAndRP: func() (models.Messageable, *backup.ExchangeInfo) {
subject := "Hello world"
msg := models.NewMessage()
msg.SetSubject(&subject)
return msg, &restorepoint.ExchangeInfo{Subject: subject}
return msg, &backup.ExchangeInfo{Subject: subject}
},
},
{
name: "Just receivedtime",
msgAndRP: func() (models.Messageable, *restorepoint.ExchangeInfo) {
msgAndRP: func() (models.Messageable, *backup.ExchangeInfo) {
now := time.Now()
msg := models.NewMessage()
msg.SetReceivedDateTime(&now)
return msg, &restorepoint.ExchangeInfo{Received: now}
return msg, &backup.ExchangeInfo{Received: now}
},
},
{
name: "All fields",
msgAndRP: func() (models.Messageable, *restorepoint.ExchangeInfo) {
msgAndRP: func() (models.Messageable, *backup.ExchangeInfo) {
sender := "foo@bar.com"
subject := "Hello world"
now := time.Now()
@ -73,7 +73,7 @@ func (suite *MessageSuite) TestMessageInfo() {
msg.SetSender(sr)
msg.SetSubject(&subject)
msg.SetReceivedDateTime(&now)
return msg, &restorepoint.ExchangeInfo{Sender: sender, Subject: subject, Received: now}
return msg, &backup.ExchangeInfo{Sender: sender, Subject: subject, Received: now}
},
}}
for _, tt := range tests {

View File

@ -4,7 +4,7 @@ import (
"bytes"
"io"
"github.com/alcionai/corso/pkg/restorepoint"
"github.com/alcionai/corso/pkg/backup"
)
const (
@ -40,7 +40,7 @@ type DataStream interface {
// DataStreamInfo is used to provide service specific
// information about the DataStream
type DataStreamInfo interface {
Info() restorepoint.ItemInfo
Info() backup.ItemInfo
}
var _ DataCollection = &ExchangeDataCollection{}
@ -101,7 +101,7 @@ type ExchangeData struct {
// going forward. Using []byte for now but I assume we'll have
// some structured type in here (serialization to []byte can be done in `Read`)
message []byte
info *restorepoint.ExchangeInfo
info *backup.ExchangeInfo
}
func (ed *ExchangeData) UUID() string {
@ -112,6 +112,6 @@ func (ed *ExchangeData) ToReader() io.ReadCloser {
return io.NopCloser(bytes.NewReader(ed.message))
}
func (ed *ExchangeData) Info() restorepoint.ItemInfo {
return restorepoint.ItemInfo{Exchange: ed.info}
func (ed *ExchangeData) Info() backup.ItemInfo {
return backup.ItemInfo{Exchange: ed.info}
}

View File

@ -8,7 +8,7 @@ import (
"github.com/google/uuid"
"github.com/alcionai/corso/internal/connector"
"github.com/alcionai/corso/pkg/restorepoint"
"github.com/alcionai/corso/pkg/backup"
)
// MockExchangeDataCollection represents a mock exchange mailbox
@ -69,6 +69,6 @@ func (med *MockExchangeData) ToReader() io.ReadCloser {
return med.Reader
}
func (med *MockExchangeData) Info() restorepoint.ItemInfo {
return restorepoint.ItemInfo{Exchange: &restorepoint.ExchangeInfo{Sender: "foo@bar.com", Subject: "Hello world!", Received: time.Now()}}
func (med *MockExchangeData) Info() backup.ItemInfo {
return backup.ItemInfo{Exchange: &backup.ExchangeInfo{Sender: "foo@bar.com", Subject: "Hello world!", Received: time.Now()}}
}

View File

@ -27,8 +27,8 @@ const (
UnknownModel = modelType(iota)
BackupOpModel
RestoreOpModel
RestorePointModel
RestorePointDetailsModel
BackupModel
BackupDetailsModel
)
func NewModelStore(c *conn) (*ModelStore, error) {

View File

@ -184,7 +184,7 @@ func (suite *ModelStoreIntegrationSuite) TestPutGet() {
hasErr: false,
},
{
t: RestorePointModel,
t: BackupModel,
check: require.NoError,
hasErr: false,
},
@ -272,7 +272,7 @@ func (suite *ModelStoreIntegrationSuite) TestPutGetOfType() {
hasErr: false,
},
{
t: RestorePointModel,
t: BackupModel,
check: require.NoError,
hasErr: false,
},

View File

@ -11,13 +11,13 @@ func _() {
_ = x[UnknownModel-0]
_ = x[BackupOpModel-1]
_ = x[RestoreOpModel-2]
_ = x[RestorePointModel-3]
_ = x[RestorePointDetailsModel-4]
_ = x[BackupModel-3]
_ = x[BackupDetailsModel-4]
}
const _modelType_name = "UnknownModelBackupOpModelRestoreOpModelRestorePointModelRestorePointDetailsModel"
const _modelType_name = "UnknownModelBackupOpModelRestoreOpModelBackupModelBackupDetailsModel"
var _modelType_index = [...]uint8{0, 12, 25, 39, 56, 80}
var _modelType_index = [...]uint8{0, 12, 25, 39, 50, 68}
func (i modelType) String() string {
if i < 0 || i >= modelType(len(_modelType_index)-1) {

View File

@ -14,7 +14,7 @@ import (
"github.com/pkg/errors"
"github.com/alcionai/corso/internal/connector"
"github.com/alcionai/corso/pkg/restorepoint"
"github.com/alcionai/corso/pkg/backup"
)
const (
@ -79,7 +79,7 @@ func (w *Wrapper) Close(ctx context.Context) error {
// DataCollection.
func getStreamItemFunc(
collection connector.DataCollection,
details *restorepoint.Details,
details *backup.Details,
) func(context.Context, func(context.Context, fs.Entry) error) error {
return func(ctx context.Context, cb func(context.Context, fs.Entry) error) error {
items := collection.Items()
@ -101,7 +101,7 @@ func getStreamItemFunc(
return errors.Wrap(err, "executing callback")
}
// Populate RestorePointDetails
// Populate BackupDetails
ep := append(collection.FullPath(), e.UUID())
details.Add(path.Join(ep...), ei.Info())
}
@ -112,7 +112,7 @@ func getStreamItemFunc(
// buildKopiaDirs recursively builds a directory hierarchy from the roots up.
// Returned directories are either virtualfs.StreamingDirectory or
// virtualfs.staticDirectory.
func buildKopiaDirs(dirName string, dir *treeMap, details *restorepoint.Details) (fs.Directory, error) {
func buildKopiaDirs(dirName string, dir *treeMap, details *backup.Details) (fs.Directory, error) {
// Don't support directories that have both a DataCollection and a set of
// static child directories.
if dir.collection != nil && len(dir.childDirs) > 0 {
@ -154,7 +154,7 @@ func newTreeMap() *treeMap {
// ancestor of the streams and uses virtualfs.StaticDirectory for internal nodes
// in the hierarchy. Leaf nodes are virtualfs.StreamingDirectory with the given
// DataCollections.
func inflateDirTree(ctx context.Context, collections []connector.DataCollection, details *restorepoint.Details) (fs.Directory, error) {
func inflateDirTree(ctx context.Context, collections []connector.DataCollection, details *backup.Details) (fs.Directory, error) {
roots := make(map[string]*treeMap)
for _, s := range collections {
@ -227,12 +227,12 @@ func inflateDirTree(ctx context.Context, collections []connector.DataCollection,
func (w Wrapper) BackupCollections(
ctx context.Context,
collections []connector.DataCollection,
) (*BackupStats, *restorepoint.Details, error) {
) (*BackupStats, *backup.Details, error) {
if w.c == nil {
return nil, nil, errNotConnected
}
details := &restorepoint.Details{}
details := &backup.Details{}
dirTree, err := inflateDirTree(ctx, collections, details)
if err != nil {
@ -250,7 +250,7 @@ func (w Wrapper) BackupCollections(
func (w Wrapper) makeSnapshotWithRoot(
ctx context.Context,
root fs.Directory,
details *restorepoint.Details,
details *backup.Details,
) (*BackupStats, error) {
si := snapshot.SourceInfo{
Host: kTestHost,
@ -275,9 +275,6 @@ func (w Wrapper) makeSnapshotWithRoot(
return nil, errors.Wrap(err, "uploading data")
}
// TODO: Persist RestorePointDetails here
// Create and store RestorePoint
if _, err := snapshot.SaveSnapshot(ctx, rw, man); err != nil {
return nil, errors.Wrap(err, "saving snapshot")
}
@ -286,8 +283,6 @@ func (w Wrapper) makeSnapshotWithRoot(
return nil, errors.Wrap(err, "flushing writer")
}
// TODO: Return RestorePoint ID in stats
res := manifestToStats(man)
return &res, nil
}

View File

@ -16,7 +16,7 @@ import (
"github.com/alcionai/corso/internal/connector"
"github.com/alcionai/corso/internal/connector/mockconnector"
ctesting "github.com/alcionai/corso/internal/testing"
"github.com/alcionai/corso/pkg/restorepoint"
"github.com/alcionai/corso/pkg/backup"
)
const (
@ -73,7 +73,7 @@ func (suite *KopiaUnitSuite) TestBuildDirectoryTree() {
user2: 42,
}
details := &restorepoint.Details{}
details := &backup.Details{}
collections := []connector.DataCollection{
mockconnector.NewMockExchangeDataCollection(
@ -136,7 +136,7 @@ func (suite *KopiaUnitSuite) TestBuildDirectoryTree_NoAncestorDirs() {
expectedFileCount := 42
details := &restorepoint.Details{}
details := &backup.Details{}
collections := []connector.DataCollection{
mockconnector.NewMockExchangeDataCollection(
[]string{emails},
@ -215,7 +215,7 @@ func (suite *KopiaUnitSuite) TestBuildDirectoryTree_Fails() {
ctx := context.Background()
suite.T().Run(test.name, func(t *testing.T) {
details := &restorepoint.Details{}
details := &backup.Details{}
_, err := inflateDirTree(ctx, test.layout, details)
assert.Error(t, err)
})

View File

@ -10,7 +10,7 @@ import (
"github.com/alcionai/corso/internal/connector/support"
"github.com/alcionai/corso/internal/kopia"
"github.com/alcionai/corso/pkg/account"
"github.com/alcionai/corso/pkg/restorepoint"
"github.com/alcionai/corso/pkg/backup"
"github.com/alcionai/corso/pkg/selectors"
)
@ -29,7 +29,7 @@ type BackupOperation struct {
type BackupResults struct {
summary
metrics
// todo: RestorePoint RestorePoint
// todo: Backup ID
}
// NewBackupOperation constructs and validates a backup operation.
@ -92,14 +92,14 @@ func (op *BackupOperation) Run(ctx context.Context) error {
stats.gc = gc.Status()
// hand the results to the consumer
var details *restorepoint.Details
var details *backup.Details
stats.k, details, err = op.kopia.BackupCollections(ctx, cs)
if err != nil {
stats.writeErr = err
return errors.Wrap(err, "backing up service data")
}
err = op.createRestorePoint(ctx, stats.k.SnapshotID, details)
err = op.createBackupModels(ctx, stats.k.SnapshotID, details)
if err != nil {
stats.writeErr = err
return err
@ -107,16 +107,16 @@ func (op *BackupOperation) Run(ctx context.Context) error {
return nil
}
func (op *BackupOperation) createRestorePoint(ctx context.Context, snapID string, details *restorepoint.Details) error {
err := op.modelStore.Put(ctx, kopia.RestorePointDetailsModel, details)
func (op *BackupOperation) createBackupModels(ctx context.Context, snapID string, details *backup.Details) error {
err := op.modelStore.Put(ctx, kopia.BackupDetailsModel, details)
if err != nil {
return errors.Wrap(err, "creating restorepointdetails model")
return errors.Wrap(err, "creating backupdetails model")
}
err = op.modelStore.Put(ctx, kopia.RestorePointModel,
restorepoint.New(snapID, string(details.ModelStoreID)))
err = op.modelStore.Put(ctx, kopia.BackupModel,
backup.New(snapID, string(details.ModelStoreID)))
if err != nil {
return errors.Wrap(err, "creating restorepoint model")
return errors.Wrap(err, "creating backup model")
}
return nil
}

View File

@ -16,10 +16,10 @@ import (
type RestoreOperation struct {
operation
RestorePointID string `json:"restorePointID"`
Results RestoreResults `json:"results"`
Targets []string `json:"selectors"` // todo: replace with Selectors
Version string `json:"bersion"`
BackupID string `json:"backupID"`
Results RestoreResults `json:"results"`
Targets []string `json:"selectors"` // todo: replace with Selectors
Version string `json:"bersion"`
account account.Account
}
@ -37,15 +37,15 @@ func NewRestoreOperation(
kw *kopia.Wrapper,
ms *kopia.ModelStore,
acct account.Account,
restorePointID string,
backupID string,
targets []string,
) (RestoreOperation, error) {
op := RestoreOperation{
operation: newOperation(opts, kw, ms),
RestorePointID: restorePointID,
Targets: targets,
Version: "v0",
account: acct,
operation: newOperation(opts, kw, ms),
BackupID: backupID,
Targets: targets,
Version: "v0",
account: acct,
}
if err := op.validate(); err != nil {
return RestoreOperation{}, err
@ -77,7 +77,7 @@ func (op *RestoreOperation) Run(ctx context.Context) error {
stats := restoreStats{}
defer op.persistResults(time.Now(), &stats)
dc, err := op.kopia.RestoreSingleItem(ctx, op.RestorePointID, op.Targets)
dc, err := op.kopia.RestoreSingleItem(ctx, op.BackupID, op.Targets)
if err != nil {
stats.readErr = err
return errors.Wrap(err, "retrieving service data")

View File

@ -111,7 +111,7 @@ func (suite *RestoreOpIntegrationSuite) TestNewRestoreOperation() {
test.kw,
test.ms,
test.acct,
"restore-point-id",
"backup-id",
nil)
test.errCheck(t, err)
})

View File

@ -1,4 +1,4 @@
package restorepoint
package backup
import (
"sync"
@ -7,9 +7,8 @@ import (
"github.com/alcionai/corso/internal/model"
)
// RestorePoint represents the result of a backup operation
// that can be restored
type RestorePoint struct {
// Backup represents the result of a backup operation
type Backup struct {
model.BaseModel
CreationTime time.Time `json:"creationTime"`
@ -24,15 +23,15 @@ type RestorePoint struct {
// - Backup "Specification"
}
func New(snapshotID, detailsID string) *RestorePoint {
return &RestorePoint{
func New(snapshotID, detailsID string) *Backup {
return &Backup{
CreationTime: time.Now(),
SnapshotID: snapshotID,
DetailsID: detailsID,
}
}
// Details describes what was stored in a RestorePoint
// Details describes what was stored in a Backup
type Details struct {
model.BaseModel
Entries []DetailsEntry `json:"entries"`
@ -41,7 +40,7 @@ type Details struct {
mu sync.Mutex `json:"-"`
}
// DetailsEntry describes a single item stored in a RestorePoint
// DetailsEntry describes a single item stored in a Backup
type DetailsEntry struct {
// TODO: `RepoRef` is currently the full path to the item in Kopia
// This can be optimized.

View File

@ -11,7 +11,7 @@ import (
"github.com/alcionai/corso/internal/kopia"
"github.com/alcionai/corso/internal/operations"
"github.com/alcionai/corso/pkg/account"
"github.com/alcionai/corso/pkg/restorepoint"
"github.com/alcionai/corso/pkg/backup"
"github.com/alcionai/corso/pkg/selectors"
"github.com/alcionai/corso/pkg/storage"
)
@ -126,7 +126,7 @@ func (r *Repository) Close(ctx context.Context) error {
return errors.Wrap(err, "closing corso ModelStore")
}
// NewBackup generates a backupOperation runner.
// NewBackup generates a BackupOperation runner.
func (r Repository) NewBackup(ctx context.Context, selector selectors.Selector) (operations.BackupOperation, error) {
return operations.NewBackupOperation(
ctx,
@ -138,27 +138,27 @@ func (r Repository) NewBackup(ctx context.Context, selector selectors.Selector)
}
// NewRestore generates a restoreOperation runner.
func (r Repository) NewRestore(ctx context.Context, restorePointID string, targets []string) (operations.RestoreOperation, error) {
func (r Repository) NewRestore(ctx context.Context, backupID string, targets []string) (operations.RestoreOperation, error) {
return operations.NewRestoreOperation(
ctx,
operations.Options{},
r.dataLayer,
r.modelStore,
r.Account,
restorePointID,
backupID,
targets)
}
// RestorePoints lists restorepoints in a respository
func (r Repository) RestorePoints(ctx context.Context) ([]*restorepoint.RestorePoint, error) {
bms, err := r.modelStore.GetIDsForType(ctx, kopia.RestorePointModel, nil)
// backups lists backups in a respository
func (r Repository) Backups(ctx context.Context) ([]*backup.Backup, error) {
bms, err := r.modelStore.GetIDsForType(ctx, kopia.BackupModel, nil)
if err != nil {
return nil, err
}
rps := make([]*restorepoint.RestorePoint, 0, len(bms))
rps := make([]*backup.Backup, 0, len(bms))
for _, bm := range bms {
rp := restorepoint.RestorePoint{}
err := r.modelStore.GetWithModelStoreID(ctx, kopia.RestorePointModel, bm.ModelStoreID, &rp)
rp := backup.Backup{}
err := r.modelStore.GetWithModelStoreID(ctx, kopia.BackupModel, bm.ModelStoreID, &rp)
if err != nil {
return nil, err
}
@ -167,10 +167,10 @@ func (r Repository) RestorePoints(ctx context.Context) ([]*restorepoint.RestoreP
return rps, nil
}
// RestorePoints lists restorepoints in a respository
func (r Repository) RestorePointDetails(ctx context.Context, rpDetailsID string) (*restorepoint.Details, error) {
rpd := restorepoint.Details{}
err := r.modelStore.GetWithModelStoreID(ctx, kopia.RestorePointDetailsModel, manifest.ID(rpDetailsID), &rpd)
// BackupDetails returns the specified backup details object
func (r Repository) BackupDetails(ctx context.Context, rpDetailsID string) (*backup.Details, error) {
rpd := backup.Details{}
err := r.modelStore.GetWithModelStoreID(ctx, kopia.BackupDetailsModel, manifest.ID(rpDetailsID), &rpd)
if err != nil {
return nil, err
}

View File

@ -190,7 +190,7 @@ func (suite *RepositoryIntegrationSuite) TestNewRestore() {
r, err := repository.Initialize(ctx, acct, st)
require.NoError(t, err)
ro, err := r.NewRestore(ctx, "restore-point-id", []string{})
ro, err := r.NewRestore(ctx, "backup-id", []string{})
require.NoError(t, err)
require.NotNil(t, ro)
}

View File

@ -47,10 +47,10 @@ func (s Selector) ToExchangeBackup() (*ExchangeBackup, error) {
}
// NewExchangeRestore produces a new Selector with the service set to ServiceExchange.
func NewExchangeRestore(restorePointID string) *ExchangeRestore {
func NewExchangeRestore(backupID string) *ExchangeRestore {
src := ExchangeRestore{
exchange{
newSelector(ServiceExchange, restorePointID),
newSelector(ServiceExchange, backupID),
},
}
return &src

View File

@ -20,7 +20,7 @@ func (suite *ExchangeSourceSuite) TestNewExchangeBackup() {
t := suite.T()
eb := NewExchangeBackup()
assert.Equal(t, eb.Service, ServiceExchange)
assert.Zero(t, eb.RestorePointID)
assert.Zero(t, eb.BackupID)
assert.NotZero(t, eb.Scopes())
}
@ -31,15 +31,15 @@ func (suite *ExchangeSourceSuite) TestToExchangeBackup() {
eb, err := s.ToExchangeBackup()
require.NoError(t, err)
assert.Equal(t, eb.Service, ServiceExchange)
assert.Zero(t, eb.RestorePointID)
assert.Zero(t, eb.BackupID)
assert.NotZero(t, eb.Scopes())
}
func (suite *ExchangeSourceSuite) TestNewExchangeRestore() {
t := suite.T()
er := NewExchangeRestore("rpid")
er := NewExchangeRestore("backupID")
assert.Equal(t, er.Service, ServiceExchange)
assert.Equal(t, er.RestorePointID, "rpid")
assert.Equal(t, er.BackupID, "backupID")
assert.NotZero(t, er.Scopes())
}
@ -50,7 +50,7 @@ func (suite *ExchangeSourceSuite) TestToExchangeRestore() {
eb, err := s.ToExchangeRestore()
require.NoError(t, err)
assert.Equal(t, eb.Service, ServiceExchange)
assert.Equal(t, eb.RestorePointID, "rpid")
assert.Equal(t, eb.BackupID, "rpid")
assert.NotZero(t, eb.Scopes())
}

View File

@ -44,19 +44,19 @@ const (
// The core selector. Has no api for setting or retrieving data.
// Is only used to pass along more specific selector instances.
type Selector struct {
RestorePointID string `json:"restorePointID,omitempty"` // A restore point id, used only by restore operations.
Service service `json:"service,omitempty"` // The service scope of the data. Exchange, Teams, Sharepoint, etc.
Excludes []map[string]string `json:"exclusions,omitempty"` // A slice of exclusions. Each exclusion applies to all inclusions.
Includes []map[string]string `json:"scopes,omitempty"` // A slice of inclusions. Expected to get cast to a service wrapper within each service handler.
BackupID string `json:"backupID,omitempty"` // A backup id, used only by restore operations.
Service service `json:"service,omitempty"` // The service scope of the data. Exchange, Teams, Sharepoint, etc.
Excludes []map[string]string `json:"exclusions,omitempty"` // A slice of exclusions. Each exclusion applies to all inclusions.
Includes []map[string]string `json:"scopes,omitempty"` // A slice of inclusions. Expected to get cast to a service wrapper within each service handler.
}
// helper for specific selector instance constructors.
func newSelector(s service, restorePointID string) Selector {
func newSelector(s service, backupID string) Selector {
return Selector{
RestorePointID: restorePointID,
Service: s,
Excludes: []map[string]string{},
Includes: []map[string]string{},
BackupID: backupID,
Service: s,
Excludes: []map[string]string{},
Includes: []map[string]string{},
}
}

View File

@ -17,10 +17,10 @@ func TestSelectorSuite(t *testing.T) {
func (suite *SelectorSuite) TestNewSelector() {
t := suite.T()
s := newSelector(ServiceUnknown, "rpid")
s := newSelector(ServiceUnknown, "backupID")
assert.NotNil(t, s)
assert.Equal(t, s.Service, ServiceUnknown)
assert.Equal(t, s.RestorePointID, "rpid")
assert.Equal(t, s.BackupID, "backupID")
assert.NotNil(t, s.Includes)
}