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
3 changes: 3 additions & 0 deletions cli/mongodb-backup-admin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type cliOptions struct {
destinationType *string
compressionAlgorithm *string
encryptionAlgorithm *string
description *string

restore *kingpin.CmdClause
restoreMetadata *string
Expand Down Expand Up @@ -127,6 +128,7 @@ func startBackup(apiClient pbapi.ApiClient, opts *cliOptions) error {
msg := &pbapi.RunBackupParams{
CompressionType: pbapi.CompressionType_NO_COMPRESSION,
Cypher: pbapi.Cypher_NO_CYPHER,
Description: *opts.description,
}

switch *opts.backupType {
Expand Down Expand Up @@ -176,6 +178,7 @@ func processCliArgs(args []string) (string, *cliOptions, error) {
destinationType: startBackupCmd.Flag("destination-type", "Backup destination type").Enum("file", "aws"),
compressionAlgorithm: startBackupCmd.Flag("compression-algorithm", "Compression algorithm used for the backup").String(),
encryptionAlgorithm: startBackupCmd.Flag("encryption-algorithm", "Encryption algorithm used for the backup").String(),
description: startBackupCmd.Flag("description", "Backup description").Required().String(),
}

cmd, err := app.Parse(args)
Expand Down
1 change: 1 addition & 0 deletions grpc/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func (a *ApiServer) RunBackup(ctx context.Context, opts *pbapi.RunBackupParams)
CompressionType: pb.CompressionType(opts.CompressionType),
Cypher: pb.Cypher(opts.Cypher),
NamePrefix: time.Now().UTC().Format(time.RFC3339),
Description: opts.Description,
// DBBackupName & OplogBackupName are going to be set in server.go
// We cannot set them here because the backup name will include the replicaset name so, it will
// be different for each client/MongoDB instance
Expand Down
3 changes: 0 additions & 3 deletions grpc/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -911,9 +911,6 @@ func (c *Client) restoreDBDump(opts *pb.RestoreBackup) (err error) {
}

func (c *Client) restoreOplog(opts *pb.RestoreBackup) error {
log.Infof("--> %s Restoring Oplog ...", c.id)
log.Infof("--> %s Oplog restore completed...", c.id)

var reader bsonfile.BSONReader
var err error
switch opts.SourceType {
Expand Down
1 change: 1 addition & 0 deletions grpc/server/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func NewBackupMetadata(opts *pb.StartBackup) *BackupMetadata {
DestinationDir: opts.GetDestinationDir(),
CompressionType: opts.GetCompressionType(),
Cypher: opts.GetCypher(),
Description: opts.GetDescription(),
Replicasets: make(map[string]*pb.ReplicasetMetadata),
},
lock: &sync.Mutex{},
Expand Down
3 changes: 2 additions & 1 deletion grpc/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ func (s *MessagesServer) StartBackup(opts *pb.StartBackup) error {
CompressionType: opts.GetCompressionType(),
Cypher: opts.GetCypher(),
OplogStartTime: opts.GetOplogStartTime(),
Description: opts.Description,
})
}

Expand Down Expand Up @@ -477,7 +478,7 @@ func (s *MessagesServer) RestoreCompleted(ctx context.Context, msg *pb.RestoreCo
if client == nil {
return nil, fmt.Errorf("Unknown client ID: %s", msg.GetClientID())
}
log.Infof("---> Received RestoreCompleted from client %v", msg.GetClientID())
log.Debugf("Received RestoreCompleted from client %v", msg.GetClientID())
client.setRestoreRunning(false)

replicasets := s.ReplicasetsRunningOplogBackup()
Expand Down
238 changes: 123 additions & 115 deletions proto/messages/messages.pb.go

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion proto/messages/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ message BackupMetadata {
string DestinationDir = 7;
Cypher Cypher = 8;
CompressionType CompressionType = 9;
map<string, ReplicasetMetadata> Replicasets = 10;
string Description = 10;
map<string, ReplicasetMetadata> Replicasets = 11;
}

message RestoreBackup {
Expand Down
18 changes: 16 additions & 2 deletions tests/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"context"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"

"github.com/percona/mongodb-backup/grpc/server"
"github.com/percona/mongodb-backup/internal/testutils"
pbapi "github.com/percona/mongodb-backup/proto/api"
log "github.com/sirupsen/logrus"
Expand All @@ -33,6 +35,7 @@ func TestApiWithDaemon(t *testing.T) {
DestinationType: pbapi.DestinationType_FILE,
CompressionType: pbapi.CompressionType_NO_COMPRESSION,
Cypher: pbapi.Cypher_NO_CYPHER,
Description: "test backup",
}

_, err = d.ApiServer.RunBackup(context.Background(), msg)
Expand Down Expand Up @@ -64,9 +67,11 @@ func TestApiWithDaemon(t *testing.T) {
}
prefix := p[0]

jsonFile := prefix + ".json"

metadataFound := false
for _, name := range names {
if name == prefix+".json" {
if name == jsonFile {
metadataFound = true
}
if !strings.HasPrefix(name, prefix) {
Expand All @@ -75,7 +80,16 @@ func TestApiWithDaemon(t *testing.T) {
}

if !metadataFound {
t.Errorf("Metadata file %s was not found", prefix+".json")
t.Errorf("Metadata file %s was not found", jsonFile)
}

md, err := server.LoadMetadataFromFile(filepath.Join(tmpDir, jsonFile))
if md.Metadata().Description == "" {
t.Errorf("Empty description in backup metadata")
}

if len(md.Metadata().Replicasets) < 3 {
t.Errorf("Invalid replicasets count in metadata. Want 3, got %d", len(md.Metadata().Replicasets))
}

d.Stop()
Expand Down