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: 1 addition & 2 deletions Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ FROM golang:$GOLANG_DOCKERHUB_TAG
WORKDIR /go/src/github.com/percona/mongodb-backup
COPY . .

RUN go get ./... && \
go vet ./...
RUN go get ./...
CMD make test-race
8 changes: 4 additions & 4 deletions internal/cluster/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func NewShard(shard *mdbstructs.Shard) *Shard {
}

// Return shards within a sharded cluster using the MongoDB 'listShards'
// server command. This command will only succeed on a mongos or config
// server.
// server command. This command will only succeed on a mongos, use
// .GetConfigsvrShards() to get shards from a config server.
//
// https://docs.mongodb.com/manual/reference/command/listShards/
//
Expand All @@ -53,8 +53,8 @@ func GetListShards(session *mgo.Session) (*mdbstructs.ListShards, error) {

// Return shards within a sharded cluster using the 'config.shards'
// collection on a config server. This is needed because config servers
// do not have the 'listShards' command. Use .GetListShards() to query
// shards from a mongos.
// do not have the 'listShards' command. Use .GetListShards() to get
// shards from a mongos instead.
//
// https://docs.mongodb.com/manual/reference/config-database/#config.shards
//
Expand Down
24 changes: 17 additions & 7 deletions internal/dumper/dumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ import (
)

type MongodumpInput struct {
Archive string
Host string
Port string
Gzip bool
Oplog bool
Threads int
Writer io.WriteCloser
Archive string
Host string
Port string
Username string
Password string
AuthDB string
Gzip bool
Oplog bool
Threads int
Writer io.WriteCloser
}

type Mongodump struct {
Expand Down Expand Up @@ -49,6 +52,13 @@ func NewMongodump(i *MongodumpInput) (*Mongodump, error) {
Auth: &options.Auth{},
Namespace: &options.Namespace{},
}
if i.Username != "" && i.Password != "" {
toolOpts.Auth.Username = i.Username
toolOpts.Auth.Password = i.Password
if i.AuthDB != "" {
toolOpts.Auth.Source = i.AuthDB
}
}

outputOpts := &mongodump.OutputOptions{
// Archive = "-" means, for mongodump, use the provider Writer
Expand Down
16 changes: 10 additions & 6 deletions internal/dumper/dumper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"log"
"os"
"testing"

"github.com/percona/mongodb-backup/internal/testutils"
)

var (
Expand All @@ -28,12 +30,14 @@ func TestWriteToFile(t *testing.T) {
diag("Using temporary file %q", tmpFile.Name())

mi := &MongodumpInput{
Host: "localhost",
Port: "17001",
Gzip: false,
Oplog: false,
Threads: 1,
Writer: tmpFile,
Host: testutils.MongoDBHost,
Port: testutils.MongoDBPrimaryPort,
Username: testutils.MongoDBUser,
Password: testutils.MongoDBPassword,
Gzip: false,
Oplog: false,
Threads: 1,
Writer: tmpFile,
}

mdump, err := NewMongodump(mi)
Expand Down
26 changes: 18 additions & 8 deletions internal/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ import (
)

type MongoRestoreInput struct {
Archive string
DryRun bool // Used only for testing
Host string
Port string
Gzip bool
Oplog bool
Threads int
Reader io.ReadCloser
Archive string
DryRun bool // Used only for testing
Host string
Port string
Username string
Password string
AuthDB string
Gzip bool
Oplog bool
Threads int
Reader io.ReadCloser
}

type MongoRestore struct {
Expand Down Expand Up @@ -52,6 +55,13 @@ func NewMongoRestore(i *MongoRestoreInput) (*MongoRestore, error) {
Namespace: &options.Namespace{},
URI: &options.URI{},
}
if i.Username != "" && i.Password != "" {
toolOpts.Auth.Username = i.Username
toolOpts.Auth.Password = i.Password
if i.AuthDB != "" {
toolOpts.Auth.Source = i.AuthDB
}
}

inputOpts := &mongorestore.InputOptions{
Gzip: i.Gzip,
Expand Down
20 changes: 12 additions & 8 deletions internal/restore/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@ package restore

import (
"testing"

"github.com/percona/mongodb-backup/internal/testutils"
)

func TestRestore(t *testing.T) {

input := &MongoRestoreInput{
// this file was generated with the dump pkg
Archive: "testdata/dump_test.000622955",
DryRun: true,
Host: "localhost",
Port: "17001",
Gzip: false,
Oplog: false,
Threads: 1,
Reader: nil,
Archive: "testdata/dump_test.000622955",
DryRun: true,
Host: testutils.MongoDBHost,
Port: testutils.MongoDBPrimaryPort,
Username: testutils.MongoDBUser,
Password: testutils.MongoDBPassword,
Gzip: false,
Oplog: false,
Threads: 1,
Reader: nil,
}

r, err := NewMongoRestore(input)
Expand Down
3 changes: 2 additions & 1 deletion scripts/init-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ for MONGODB_PORT in ${TEST_MONGODB_PRIMARY_PORT} ${TEST_MONGODB_CONFIGSVR1_PORT}
roles: [
{ db: "admin", role: "backup" },
{ db: "admin", role: "clusterMonitor" },
{ db: "admin", role: "restore" }
{ db: "admin", role: "restore" },
{ db: "test", role: "readWrite" }
]
})' \
admin
Expand Down