mongodump

package
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2021 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package mongodump creates BSON data from the contents of a MongoDB instance.

Index

Constants

View Source
const (
	DefaultWaitTime = 3 * time.Second
)

############################################################################################## * 重写返回 bar

Variables

View Source
var Usage = `` /* 325-byte string literal not displayed */

Functions

func NewMgoDump added in v1.0.3

func NewMgoDump(ip string, port int, user string, pwd string) *mgoDump

Types

type CusBar added in v1.0.2

type CusBar struct {
	Name      string
	BarLength int
	IsBytes   bool

	Watching progress.Progressor
	WaitTime time.Duration
	// contains filtered or unexported fields
}

func (*CusBar) Start added in v1.0.2

func (pb *CusBar) Start()

func (*CusBar) Stop added in v1.0.2

func (pb *CusBar) Stop()

type CusBarWriter added in v1.0.2

type CusBarWriter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

重写进度########################################################

func NewCusBarWriter added in v1.0.2

func NewCusBarWriter(w io.Writer, waitTime time.Duration, barLength int, isBytes bool, processListener CusProcessListener) *CusBarWriter

NewBarWriter returns an initialized BarWriter with the given bar length and byte-formatting toggle, waiting the given duration between writes

func (*CusBarWriter) Attach added in v1.0.2

func (manager *CusBarWriter) Attach(name string, progressor progress.Progressor)

Attach registers the given progressor with the manager

func (*CusBarWriter) Detach added in v1.0.2

func (manager *CusBarWriter) Detach(name string)

Detach removes the progressor with the given name from the manager. Insert order is maintained for consistent ordering of the printed bars.

func (*CusBarWriter) Start added in v1.0.2

func (manager *CusBarWriter) Start()

Start kicks of the timed batch writing of progress bars.

func (*CusBarWriter) Stop added in v1.0.2

func (manager *CusBarWriter) Stop()

Stop ends the main manager goroutine, stopping the manager's bars from being rendered.

type CusProcessListener added in v1.0.2

type CusProcessListener interface {
	Start(name string, Collection string)                 //任务开始
	StartNode(nodeName string)                            //节点开始
	Pending(nodeName string, percent float64)             //节点执行
	NodeComplete(nodeName string)                         //任务节点完成
	Complete(name string, Collection string)              //任务完成
	Error(message string, name string, Collection string) //任务错误
	NodeError(nodeName string, message string)            //节点错误
}

type IndexDocumentFromDB

type IndexDocumentFromDB struct {
	Options bson.M `bson:",inline"`
	Key     bson.D `bson:"key"`
}

IndexDocumentFromDB is used internally to preserve key ordering.

type InputOptions

type InputOptions struct {
	Query          string `long:"query" short:"q" description:"query filter, as a v2 Extended JSON string, e.g., '{\"x\":{\"$gt\":1}}'"`
	QueryFile      string `long:"queryFile" description:"path to a file containing a query filter (v2 Extended JSON)"`
	ReadPreference string `` /* 220-byte string literal not displayed */
	TableScan      bool   `` /* 146-byte string literal not displayed */
}

InputOptions defines the set of options to use in retrieving data from the server.

func (*InputOptions) GetQuery

func (inputOptions *InputOptions) GetQuery() ([]byte, error)

func (*InputOptions) HasQuery

func (inputOptions *InputOptions) HasQuery() bool

func (*InputOptions) Name

func (*InputOptions) Name() string

Name returns a human-readable group name for input options.

type Metadata

type Metadata struct {
	Options        bson.M   `bson:"options,omitempty"`
	Indexes        []bson.D `bson:"indexes"`
	UUID           string   `bson:"uuid,omitempty"`
	CollectionName string   `bson:"collectionName"`
	Type           string   `bson:"type,omitempty"`
}

Metadata holds information about a collection's options and indexes.

type MgoBack added in v1.0.3

type MgoBack struct {
	// contains filtered or unexported fields
}

* mgo命令

func (*MgoBack) Handler added in v1.0.3

func (c *MgoBack) Handler(processListener CusProcessListener)

* @param outPath string 备份路径

func (*MgoBack) SetNode added in v1.0.3

func (c *MgoBack) SetNode(node *MgoBackNode) MgoHandler

type MgoBackNode added in v1.0.3

type MgoBackNode struct {
	Ip         string
	Port       int
	User       string
	Pwd        string
	DataBase   string
	AuthSource string
	Collection string
	Out        string //备份目录
}

* 备份数据

type MgoHandler added in v1.0.3

type MgoHandler interface {
	SetNode(node *MgoBackNode) MgoHandler
	Handler(processListener CusProcessListener)
}

* 单个备份数据 用法

out:= fmt.Sprintf("mgoBack/%s", Time.GetNowTimeDate())
mgoNode:=&mongoback.MgoBackNode{
	Ip:         mm.ip,
	Port:       mm.port,
	User:       mm.user,
	Pwd:        mm.pwd,
	DataBase:   mm.dataBase,
	Collection: "",
	Out:        out,
}
mongoback.NewMgoBack().SetNode(mgoNode).Handler(new(MgoBackListener))

func NewMgoBack added in v1.0.3

func NewMgoBack() MgoHandler

type MongoDump

type MongoDump struct {
	// basic mongo tool options
	ToolOptions   *options.ToolOptions
	InputOptions  *InputOptions
	OutputOptions *OutputOptions

	// Skip dumping users and roles, regardless of namespace, when true.
	SkipUsersAndRoles bool

	ProgressManager progress.Manager

	// useful internals that we don't directly expose as options
	SessionProvider *db.SessionProvider

	// Writer to take care of BSON output when not writing to the local filesystem.
	// This is initialized to os.Stdout if unset.
	OutputWriter io.Writer
	// contains filtered or unexported fields
}

MongoDump is a container for the user-specified options and internal state used for running mongodump.

func (*MongoDump) CreateAllIntents

func (dump *MongoDump) CreateAllIntents() error

CreateAllIntents iterates through all dbs and collections and builds dump intents for each collection.

func (*MongoDump) CreateCollectionIntent

func (dump *MongoDump) CreateCollectionIntent(dbName, colName string) error

CreateCollectionIntent builds an intent for a given collection and puts it into the intent manager. It should only be called when a specific collection is specified by --db and --collection.

func (*MongoDump) CreateIntentsForDatabase

func (dump *MongoDump) CreateIntentsForDatabase(dbName string) error

CreateIntentsForDatabase iterates through collections in a db and builds dump intents for each collection.

func (*MongoDump) CreateOplogIntents

func (dump *MongoDump) CreateOplogIntents() error

CreateOplogIntents creates an intents.Intent for the oplog and adds it to the manager

func (*MongoDump) CreateUsersRolesVersionIntentsForDB

func (dump *MongoDump) CreateUsersRolesVersionIntentsForDB(db string) error

CreateUsersRolesVersionIntentsForDB create intents to be written in to the specific database folder, for the users, roles and version admin database collections And then it adds the intents in to the manager

func (*MongoDump) Dump

func (dump *MongoDump) Dump() (err error)

Dump handles some final options checking and executes MongoDump.

func (*MongoDump) DumpIntent

func (dump *MongoDump) DumpIntent(intent *intents.Intent, buffer resettableOutputBuffer) error

DumpIntent dumps the specified database's collection.

func (*MongoDump) DumpIntents

func (dump *MongoDump) DumpIntents() error

DumpIntents iterates through the previously-created intents and dumps all of the found collections.

func (*MongoDump) DumpMetadata

func (dump *MongoDump) DumpMetadata() error

DumpMetadata dumps the metadata for each intent in the manager that has metadata

func (*MongoDump) DumpOplogBetweenTimestamps

func (dump *MongoDump) DumpOplogBetweenTimestamps(start, end primitive.Timestamp) error

DumpOplogBetweenTimestamps takes two timestamps and writer and dumps all oplog entries between the given timestamp to the writer. Returns any errors that occur.

func (*MongoDump) DumpUsersAndRoles

func (dump *MongoDump) DumpUsersAndRoles() error

DumpUsersAndRoles dumps all of the users and roles and versions TODO: This and DumpUsersAndRolesForDB should be merged, correctly

func (*MongoDump) DumpUsersAndRolesForDB

func (dump *MongoDump) DumpUsersAndRolesForDB(name string) error

DumpUsersAndRolesForDB queries and dumps the users and roles tied to the given database. Only works with an authentication schema version >= 3.

func (*MongoDump) HandleInterrupt

func (dump *MongoDump) HandleInterrupt()

func (*MongoDump) Init

func (dump *MongoDump) Init() error

Init performs preliminary setup operations for MongoDump.

func (*MongoDump) NewIntentFromOptions

func (dump *MongoDump) NewIntentFromOptions(dbName string, ci *db.CollectionInfo) (*intents.Intent, error)

func (*MongoDump) ValidateOptions

func (dump *MongoDump) ValidateOptions() error

ValidateOptions checks for any incompatible sets of options.

type NilPos

type NilPos struct{}

func (NilPos) Pos

func (NilPos) Pos() int64

type Options

type Options struct {
	*options.ToolOptions
	*InputOptions
	*OutputOptions
}

func ParseOptions

func ParseOptions(rawArgs []string, versionStr, gitCommit string) (Options, error)

type OutputOptions

type OutputOptions struct {
	Out                        string   `long:"out" value-name:"<directory-path>" short:"o" description:"output directory, or '-' for stdout (default: 'dump')"`
	Gzip                       bool     `long:"gzip" description:"compress archive or collection output with Gzip"`
	Oplog                      bool     `long:"oplog" description:"use oplog for taking a point-in-time snapshot"`
	Archive                    string   `` /* 197-byte string literal not displayed */
	DumpDBUsersAndRoles        bool     `long:"dumpDbUsersAndRoles" description:"dump user and role definitions for the specified database"`
	ExcludedCollections        []string `` /* 173-byte string literal not displayed */
	ExcludedCollectionPrefixes []string `` /* 212-byte string literal not displayed */
	NumParallelCollections     int      `long:"numParallelCollections" short:"j" description:"number of collections to dump in parallel" default:"4" default-mask:"-"`
	ViewsAsCollections         bool     `` /* 128-byte string literal not displayed */
}

OutputOptions defines the set of options for writing dump data.

func (*OutputOptions) Name

func (*OutputOptions) Name() string

Name returns a human-readable group name for output options.

Directories

Path Synopsis
Main package for the mongodump tool.
Main package for the mongodump tool.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL