mongorestore

package
v0.0.0-...-462fb9d Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2016 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package mongorestore writes BSON data to a MongoDB instance.

Index

Constants

View Source
const (
	Users = "users"
	Roles = "roles"
)

Specially treated restore collection types.

Variables

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

Usage describes basic usage of mongorestore

Functions

func ParseTimestampFlag

func ParseTimestampFlag(ts string) (bson.MongoTimestamp, error)

ParseTimestampFlag takes in a string the form of <time_t>:<ordinal>, where <time_t> is the seconds since the UNIX epoch, and <ordinal> represents a counter of operations in the oplog that occurred in the specified second. It parses this timestamp string and returns a bson.MongoTimestamp type.

Types

type FileType

type FileType uint

FileType describes the various types of restore documents.

const (
	UnknownFileType FileType = iota
	BSONFileType
	MetadataFileType
)

File types constants used by mongorestore.

type IndexDocument

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

IndexDocument holds information about a collection's index.

type InputOptions

type InputOptions struct {
	Objcheck               bool   `long:"objcheck" description:"validate all objects before inserting"`
	OplogReplay            bool   `long:"oplogReplay" description:"replay oplog for point-in-time restore"`
	OplogLimit             string `long:"oplogLimit" value-name:"<seconds>[:ordinal]" description:"only include oplog entries before the provided Timestamp"`
	OplogFile              string `long:"oplogFile" value-name:"<filename>" description:"oplog file to use for replay of oplog"`
	Archive                string `` /* 199-byte string literal not displayed */
	RestoreDBUsersAndRoles bool   `long:"restoreDbUsersAndRoles" description:"restore user and role definitions for the given database"`
	Directory              string `long:"dir" value-name:"<directory-name>" description:"input directory, use '-' for stdin"`
	Gzip                   bool   `long:"gzip" description:"decompress gzipped input"`
}

InputOptions defines the set of options to use in configuring the restore process.

func (*InputOptions) Name

func (*InputOptions) Name() string

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

type Metadata

type Metadata struct {
	Options bson.D          `json:"options,omitempty"`
	Indexes []IndexDocument `json:"indexes"`
}

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

type MongoRestore

type MongoRestore struct {
	ToolOptions   *options.ToolOptions
	InputOptions  *InputOptions
	OutputOptions *OutputOptions

	SessionProvider *db.SessionProvider

	TargetDirectory string
	// contains filtered or unexported fields
}

MongoRestore is a container for the user-specified options and internal state used for running mongorestore.

func (*MongoRestore) ApplyOps

func (restore *MongoRestore) ApplyOps(session *mgo.Session, entries []interface{}) error

ApplyOps is a wrapper for the applyOps database command, we pass in a session to avoid opening a new connection for a few inserts at a time.

func (*MongoRestore) CollectionExists

func (restore *MongoRestore) CollectionExists(intent *intents.Intent) (bool, error)

CollectionExists returns true if the given intent's collection exists.

func (*MongoRestore) CreateAllIntents

func (restore *MongoRestore) CreateAllIntents(dir archive.DirLike, filterDB string, filterCollection string) error

CreateAllIntents drills down into a dump folder, creating intents for all of the databases and collections it finds.

func (*MongoRestore) CreateCollection

func (restore *MongoRestore) CreateCollection(intent *intents.Intent, options bson.D) error

CreateCollection creates the collection specified in the intent with the given options.

func (*MongoRestore) CreateIndexes

func (restore *MongoRestore) CreateIndexes(intent *intents.Intent, indexes []IndexDocument) error

CreateIndexes takes in an intent and an array of index documents and attempts to create them using the createIndexes command. If that command fails, we fall back to individual index creation.

func (*MongoRestore) CreateIntentForCollection

func (restore *MongoRestore) CreateIntentForCollection(db string, collection string, dir archive.DirLike) error

CreateIntentForCollection builds an intent for the given database and collection name along with a path to a .bson collection file. It searches the file's parent directory for a matching metadata file.

This method is not called by CreateIntentsForDB, it is only used in the case where --db and --collection flags are set.

func (*MongoRestore) CreateIntentForOplog

func (restore *MongoRestore) CreateIntentForOplog() error

CreateIntentForOplog creates an intent for a file that we want to treat as an oplog.

func (*MongoRestore) CreateIntentsForDB

func (restore *MongoRestore) CreateIntentsForDB(db string, filterCollection string, dir archive.DirLike, mute bool) (err error)

CreateIntentsForDB drills down into the dir folder, creating intents for all of the collection dump files it finds for the db database.

func (*MongoRestore) CreateStdinIntentForCollection

func (restore *MongoRestore) CreateStdinIntentForCollection(db string, collection string) error

CreateStdinIntentForCollection builds an intent for the given database and collection name that is to be read from standard input

func (*MongoRestore) DropCollection

func (restore *MongoRestore) DropCollection(intent *intents.Intent) error

DropCollection drops the intent's collection.

func (*MongoRestore) GetDumpAuthVersion

func (restore *MongoRestore) GetDumpAuthVersion() (int, error)

GetDumpAuthVersion reads the admin.system.version collection in the dump directory to determine the authentication version of the files in the dump. If that collection is not present in the dump, we try to infer the authentication version based on its absence. Returns the authentication version number and any errors that occur.

func (*MongoRestore) LegacyInsertIndex

func (restore *MongoRestore) LegacyInsertIndex(intent *intents.Intent, index IndexDocument) error

LegacyInsertIndex takes in an intent and an index document and attempts to create the index on the "system.indexes" collection.

func (*MongoRestore) LoadIndexesFromBSON

func (restore *MongoRestore) LoadIndexesFromBSON() error

LoadIndexesFromBSON reads indexes from the index BSON files and caches them in the MongoRestore object.

func (*MongoRestore) MetadataFromJSON

func (restore *MongoRestore) MetadataFromJSON(jsonBytes []byte) (bson.D, []IndexDocument, error)

MetadataFromJSON takes a slice of JSON bytes and unmarshals them into usable collection options and indexes for restoring collections.

func (*MongoRestore) ParseAndValidateOptions

func (restore *MongoRestore) ParseAndValidateOptions() error

ParseAndValidateOptions returns a non-nil error if user-supplied options are invalid.

func (*MongoRestore) Restore

func (restore *MongoRestore) Restore() error

Restore runs the mongorestore program.

func (*MongoRestore) RestoreCollectionToDB

func (restore *MongoRestore) RestoreCollectionToDB(dbName, colName string,
	bsonSource *db.DecodedBSONSource, file PosReader, fileSize int64) (int64, error)

RestoreCollectionToDB pipes the given BSON data into the database. Returns the number of documents restored and any errors that occured.

func (*MongoRestore) RestoreIntent

func (restore *MongoRestore) RestoreIntent(intent *intents.Intent) error

RestoreIntent attempts to restore a given intent into MongoDB.

func (*MongoRestore) RestoreIntents

func (restore *MongoRestore) RestoreIntents() error

RestoreIntents iterates through all of the intents stored in the IntentManager, and restores them.

func (*MongoRestore) RestoreOplog

func (restore *MongoRestore) RestoreOplog() error

RestoreOplog attempts to restore a MongoDB oplog.

func (*MongoRestore) RestoreUsersOrRoles

func (restore *MongoRestore) RestoreUsersOrRoles(users, roles *intents.Intent) error

RestoreUsersOrRoles accepts a users intent and a roles intent, and restores them via _mergeAuthzCollections. Either or both can be nil. In the latter case nothing is done.

func (*MongoRestore) ShouldRestoreUsersAndRoles

func (restore *MongoRestore) ShouldRestoreUsersAndRoles() bool

ShouldRestoreUsersAndRoles returns true if mongorestore should go through through the process of restoring collections pertaining to authentication.

func (*MongoRestore) TimestampBeforeLimit

func (restore *MongoRestore) TimestampBeforeLimit(ts bson.MongoTimestamp) bool

TimestampBeforeLimit returns true if the given timestamp is allowed to be applied to mongorestore's target database.

func (*MongoRestore) ValidateAuthVersions

func (restore *MongoRestore) ValidateAuthVersions() error

ValidateAuthVersions compares the authentication version of the dump files and the authentication version of the target server, and returns an error if the versions are incompatible.

type OutputOptions

type OutputOptions struct {
	Drop                       bool     `long:"drop" description:"drop each collection before import"`
	WriteConcern               string   `` /* 236-byte string literal not displayed */
	NoIndexRestore             bool     `long:"noIndexRestore" description:"don't restore indexes"`
	NoOptionsRestore           bool     `long:"noOptionsRestore" description:"don't restore collection options"`
	KeepIndexVersion           bool     `long:"keepIndexVersion" description:"don't update index version"`
	MaintainInsertionOrder     bool     `long:"maintainInsertionOrder" description:"preserve order of documents during restoration"`
	NumParallelCollections     int      `` /* 142-byte string literal not displayed */
	NumInsertionWorkers        int      `` /* 160-byte string literal not displayed */
	StopOnError                bool     `long:"stopOnError" description:"stop restoring if an error is encountered on insert (off by default)"`
	ExcludedCollections        []string `` /* 176-byte string literal not displayed */
	ExcludedCollectionPrefixes []string `` /* 214-byte string literal not displayed */
	BypassDocumentValidation   bool     `long:"bypassDocumentValidation" description:"bypass document validation"`
}

OutputOptions defines the set of options for restoring dump data.

func (*OutputOptions) Name

func (*OutputOptions) Name() string

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

type PosReader

type PosReader interface {
	io.ReadCloser
	Pos() int64
}

Directories

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

Jump to

Keyboard shortcuts

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