backup

package
v1.8.1-0...-0157f87 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: Apache-2.0 Imports: 39 Imported by: 3

Documentation

Index

Constants

View Source
const FilelistName = "filelist.pbm"

FilelistName is filename that is used to store list of files for physical backup

View Source
const SelectiveBackup defs.BackupType = "selective"

Variables

View Source
var (
	ErrBackupInProgress     = errors.New("backup is in progress")
	ErrIncrementalBackup    = errors.New("backup is incremental")
	ErrNonIncrementalBackup = errors.New("backup is not incremental")
	ErrNotBaseIncrement     = errors.New("backup is not base increment")
	ErrBaseForPITR          = errors.New("cannot delete the last PITR base snapshot while PITR is enabled")
)
View Source
var ErrInvalidDeleteBackupType = errors.New("invalid backup type")

Functions

func AddRSMeta

func AddRSMeta(ctx context.Context, conn connect.Client, bcpName string, rs BackupReplset) error

func BackupHB

func BackupHB(ctx context.Context, conn connect.Client, bcpName string) error

func CanDeleteBackup

func CanDeleteBackup(ctx context.Context, conn connect.Client, bcp *BackupMeta) error

func CanDeleteIncrementalChain

func CanDeleteIncrementalChain(
	ctx context.Context,
	conn connect.Client,
	base *BackupMeta,
	increments [][]*BackupMeta,
) error

func ChangeBackupState

func ChangeBackupState(conn connect.Client, bcpName string, s defs.Status, msg string) error

func ChangeBackupStateOPID

func ChangeBackupStateOPID(conn connect.Client, opid string, s defs.Status, msg string) error

func ChangeBackupStateWithUnixTime

func ChangeBackupStateWithUnixTime(
	ctx context.Context,
	conn connect.Client,
	bcpName string,
	s defs.Status,
	unix int64,
	msg string,
) error

func ChangeRSState

func ChangeRSState(conn connect.Client, bcpName, rsName string, s defs.Status, msg string) error

func CheckBackupDataFiles

func CheckBackupDataFiles(ctx context.Context, stg storage.Storage, bcp *BackupMeta) error

func CheckBackupFiles

func CheckBackupFiles(ctx context.Context, stg storage.Storage, name string) error

func DeleteBackup

func DeleteBackup(ctx context.Context, conn connect.Client, name, node string) error

DeleteBackup deletes backup with the given name from the current storage and pbm database

func DeleteBackupBefore

func DeleteBackupBefore(
	ctx context.Context,
	conn connect.Client,
	t time.Time,
	bcpType defs.BackupType,
	node string,
) error

DeleteBackupBefore deletes backups which are older than given time

func DeleteBackupFiles

func DeleteBackupFiles(stg storage.Storage, backupName string) error

DeleteBackupFiles removes backup's artifacts from storage

func FetchAllIncrements

func FetchAllIncrements(
	ctx context.Context,
	conn connect.Client,
	base *BackupMeta,
) ([][]*BackupMeta, error)

func FindBaseSnapshotLWAfter

func FindBaseSnapshotLWAfter(
	ctx context.Context,
	conn connect.Client,
	lw primitive.Timestamp,
) (primitive.Timestamp, error)

func FindBaseSnapshotLWBefore

func FindBaseSnapshotLWBefore(
	ctx context.Context,
	conn connect.Client,
	lw primitive.Timestamp,
	exclude primitive.Timestamp,
) (primitive.Timestamp, error)

func FormatChunkName

func FormatChunkName(start, end primitive.Timestamp, cmp compress.CompressionType) string

func IncBackupSize

func IncBackupSize(ctx context.Context, conn connect.Client, bcpName string, size int64) error

func NewDBManager

func NewDBManager(conn connect.Client) *dbMangerImpl

func ParseChunkName

func ParseChunkName(filename string) (
	start primitive.Timestamp,
	end primitive.Timestamp,
	comp compress.CompressionType,
	err error,
)

func ParseDeleteBackupType

func ParseDeleteBackupType(s string) (defs.BackupType, error)

func ReadArchiveNamespaces

func ReadArchiveNamespaces(stg storage.Storage, metafile string) ([]*archive.Namespace, error)

func SetFirstWrite

func SetFirstWrite(ctx context.Context, conn connect.Client, bcpName string, first primitive.Timestamp) error

func SetLastWrite

func SetLastWrite(ctx context.Context, conn connect.Client, bcpName string, last primitive.Timestamp) error

func SetRSLastWrite

func SetRSLastWrite(conn connect.Client, bcpName, rsName string, ts primitive.Timestamp) error

func SetRSNomination

func SetRSNomination(ctx context.Context, conn connect.Client, bcpName, rs string) error

func SetRSNomineeACK

func SetRSNomineeACK(ctx context.Context, conn connect.Client, bcpName, rsName, node string) error

func SetRSNominees

func SetRSNominees(ctx context.Context, conn connect.Client, bcpName, rsName string, nodes []string) error

func SetSrcBackup

func SetSrcBackup(ctx context.Context, conn connect.Client, bcpName, srcName string) error

Types

type BCoplogTS added in v1.7.0

type BCoplogTS struct {
	TS primitive.Timestamp `bson:"ts"`
	T  int64               `bson:"t"`
}

type Backup

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

func New

func New(leadConn connect.Client, conn *mongo.Client, brief topo.NodeBrief, dumpConns int) *Backup

func NewExternal

func NewExternal(leadConn connect.Client, conn *mongo.Client, brief topo.NodeBrief) *Backup

func NewIncremental

func NewIncremental(leadConn connect.Client, conn *mongo.Client, brief topo.NodeBrief, base bool) *Backup

func NewPhysical added in v1.7.0

func NewPhysical(leadConn connect.Client, conn *mongo.Client, brief topo.NodeBrief) *Backup

func (*Backup) Init added in v1.5.0

func (b *Backup) Init(
	ctx context.Context,
	bcp *ctrl.BackupCmd,
	opid ctrl.OPID,
	balancer topo.BalancerMode,
) error

func (*Backup) Run

func (b *Backup) Run(ctx context.Context, bcp *ctrl.BackupCmd, opid ctrl.OPID, l log.LogEvent) (err error)

Run runs backup. TODO: describe flow

func (*Backup) SetConfig

func (b *Backup) SetConfig(cfg *config.Config)

func (*Backup) SetMongoVersion

func (b *Backup) SetMongoVersion(v string)

func (*Backup) SetSlicerInterval

func (b *Backup) SetSlicerInterval(d time.Duration)

func (*Backup) SetTimeouts

func (b *Backup) SetTimeouts(t *config.BackupTimeouts)

func (*Backup) SlicerInterval

func (b *Backup) SlicerInterval() time.Duration

type BackupCursor added in v1.7.0

type BackupCursor struct {
	CustomThisID string
	// contains filtered or unexported fields
}

func NewBackupCursor added in v1.7.0

func NewBackupCursor(conn *mongo.Client, l log.LogEvent, opts bson.D) *BackupCursor

func (*BackupCursor) Close added in v1.7.0

func (bc *BackupCursor) Close()

func (*BackupCursor) Data added in v1.7.0

func (bc *BackupCursor) Data(ctx context.Context) (_ *BackupCursorData, err error)

func (*BackupCursor) Journals added in v1.7.0

func (bc *BackupCursor) Journals(upto primitive.Timestamp) ([]File, error)

type BackupMeta

type BackupMeta struct {
	Type defs.BackupType `bson:"type" json:"type"`
	OPID string          `bson:"opid" json:"opid"`
	Name string          `bson:"name" json:"name"`

	// SrcBackup is the source for the incremental backups. The souce might be
	// incremental as well.
	// Empty means this is a full backup (and a base for further incremental bcps).
	SrcBackup string `bson:"src_backup,omitempty" json:"src_backup,omitempty"`

	// Increments is a list of all increments, including failed or canceled.
	// Each top-level slice cell contains the list of the next incremental backup attempts.
	// If the value is nil, increments have not been fetched.
	// If the value is an empty non-nil slice, no increment exists.
	Increments [][]*BackupMeta `bson:"-" json:"-"`

	// ShardRemap is map of replset to shard names.
	// If shard name is different from replset name, it will be stored in the map.
	// If all shard names are the same as their replset names, the map is nil.
	ShardRemap map[string]string `bson:"shardRemap,omitempty" json:"shardRemap,omitempty"`

	Namespaces       []string                 `bson:"nss,omitempty" json:"nss,omitempty"`
	Replsets         []BackupReplset          `bson:"replsets" json:"replsets"`
	Compression      compress.CompressionType `bson:"compression" json:"compression"`
	Store            Storage                  `bson:"store" json:"store"`
	Size             int64                    `bson:"size" json:"size"`
	MongoVersion     string                   `bson:"mongodb_version" json:"mongodb_version"`
	FCV              string                   `bson:"fcv" json:"fcv"`
	StartTS          int64                    `bson:"start_ts" json:"start_ts"`
	LastTransitionTS int64                    `bson:"last_transition_ts" json:"last_transition_ts"`
	FirstWriteTS     primitive.Timestamp      `bson:"first_write_ts" json:"first_write_ts"`
	LastWriteTS      primitive.Timestamp      `bson:"last_write_ts" json:"last_write_ts"`
	Hb               primitive.Timestamp      `bson:"hb" json:"hb"`
	Status           defs.Status              `bson:"status" json:"status"`
	Conditions       []Condition              `bson:"conditions" json:"conditions"`
	Nomination       []BackupRsNomination     `bson:"n" json:"n"`
	Err              string                   `bson:"error,omitempty" json:"error,omitempty"`
	PBMVersion       string                   `bson:"pbm_version" json:"pbm_version"`
	BalancerStatus   topo.BalancerMode        `bson:"balancer" json:"balancer"`
	// contains filtered or unexported fields
}

BackupMeta is a backup's metadata

func BackupsDoneList

func BackupsDoneList(
	ctx context.Context,
	conn connect.Client,
	after *primitive.Timestamp,
	limit int64,
	order int,
) ([]BackupMeta, error)

func BackupsList

func BackupsList(ctx context.Context, conn connect.Client, limit int64) ([]BackupMeta, error)

func GetBackupByOPID

func GetBackupByOPID(ctx context.Context, conn connect.Client, opid string) (*BackupMeta, error)

func GetFirstBackup

func GetFirstBackup(ctx context.Context, conn connect.Client, after *primitive.Timestamp) (*BackupMeta, error)

func GetLastBackup

func GetLastBackup(ctx context.Context, conn connect.Client, before *primitive.Timestamp) (*BackupMeta, error)

GetLastBackup returns last successfully finished backup (non-selective and non-external) or nil if there is no such backup yet. If ts isn't nil it will search for the most recent backup that finished before specified timestamp

func LastIncrementalBackup

func LastIncrementalBackup(ctx context.Context, conn connect.Client) (*BackupMeta, error)

func ListDeleteBackupBefore

func ListDeleteBackupBefore(
	ctx context.Context,
	conn connect.Client,
	ts primitive.Timestamp,
	bcpType defs.BackupType,
) ([]BackupMeta, error)

func ReadMetadata

func ReadMetadata(stg storage.Storage, filename string) (*BackupMeta, error)

func (*BackupMeta) Error

func (b *BackupMeta) Error() error

func (*BackupMeta) RS

func (b *BackupMeta) RS(name string) *BackupReplset

RS returns the metadata of the replset with given name. It returns nil if no replset found.

func (*BackupMeta) SetRuntimeError

func (b *BackupMeta) SetRuntimeError(err error)

type BackupReplset

type BackupReplset struct {
	Name string `bson:"name" json:"name"`

	// Journal is not used. left for backward compatibility
	Journal          []File              `bson:"journal,omitempty" json:"journal,omitempty"`
	Files            []File              `bson:"files,omitempty" json:"files,omitempty"`
	DumpName         string              `bson:"dump_name,omitempty" json:"backup_name,omitempty"`
	OplogName        string              `bson:"oplog_name,omitempty" json:"oplog_name,omitempty"`
	StartTS          int64               `bson:"start_ts" json:"start_ts"`
	Status           defs.Status         `bson:"status" json:"status"`
	IsConfigSvr      *bool               `bson:"iscs,omitempty" json:"iscs,omitempty"`
	IsConfigShard    *bool               `bson:"configshard,omitempty" json:"configshard,omitempty"`
	LastTransitionTS int64               `bson:"last_transition_ts" json:"last_transition_ts"`
	FirstWriteTS     primitive.Timestamp `bson:"first_write_ts" json:"first_write_ts"`
	LastWriteTS      primitive.Timestamp `bson:"last_write_ts" json:"last_write_ts"`
	Node             string              `bson:"node" json:"node"` // node that performed backup
	Error            string              `bson:"error,omitempty" json:"error,omitempty"`
	Conditions       []Condition         `bson:"conditions" json:"conditions"`
	MongodOpts       *topo.MongodOpts    `bson:"mongod_opts,omitempty" json:"mongod_opts,omitempty"`

	// required for external backup (PBM-1252)
	PBMVersion   string `bson:"pbm_version,omitempty" json:"pbm_version,omitempty"`
	MongoVersion string `bson:"mongo_version,omitempty" json:"mongo_version,omitempty"`

	// CustomThisID is customized thisBackupName value for $backupCursor (in WT: "this_id").
	// If it is not set (empty), the default value was used.
	CustomThisID string `bson:"this_id,omitempty" json:"this_id,omitempty"`
}

type BackupRsNomination

type BackupRsNomination struct {
	RS    string   `bson:"rs" json:"rs"`
	Nodes []string `bson:"n" json:"n"`
	Ack   string   `bson:"ack" json:"ack"`
}

BackupRsNomination is used to choose (nominate and elect) nodes for the backup within a replica set

func GetRSNominees

func GetRSNominees(
	ctx context.Context,
	conn connect.Client,
	bcpName, rsName string,
) (*BackupRsNomination, error)

type CleanupInfo

type CleanupInfo struct {
	Backups []BackupMeta       `json:"backups"`
	Chunks  []oplog.OplogChunk `json:"chunks"`
}

func MakeCleanupInfo

func MakeCleanupInfo(ctx context.Context, conn connect.Client, ts primitive.Timestamp) (CleanupInfo, error)

type Condition

type Condition struct {
	Timestamp int64       `bson:"timestamp" json:"timestamp"`
	Status    defs.Status `bson:"status" json:"status"`
	Error     string      `bson:"error,omitempty" json:"error,omitempty"`
}

type File

type File struct {
	Name    string      `bson:"filename" json:"filename"`
	Off     int64       `bson:"offset" json:"offset"` // offset for incremental backups
	Len     int64       `bson:"length" json:"length"` // length of chunk after the offset
	Size    int64       `bson:"fileSize" json:"fileSize"`
	StgSize int64       `bson:"stgSize" json:"stgSize"`
	Fmode   os.FileMode `bson:"fmode" json:"fmode"`
}

func (File) Path

func (f File) Path(c compress.CompressionType) string

func (File) String

func (f File) String() string

func (*File) WriteTo

func (f *File) WriteTo(w io.Writer) (int64, error)

type Filelist

type Filelist []File

Filelist represents a list of files.

func ReadFilelist

func ReadFilelist(r io.Reader) (Filelist, error)

func ReadFilelistForReplset

func ReadFilelistForReplset(stg storage.Storage, bcpName, rsName string) (Filelist, error)

func (Filelist) WriteTo

func (filelist Filelist) WriteTo(w io.Writer) (int64, error)

type Manager

type Manager interface {
	GetAllBackups(ctx context.Context) ([]BackupMeta, error)
	GetBackupByName(ctx context.Context, name string) (*BackupMeta, error)
	GetBackupByOpID(ctx context.Context, opid string) (*BackupMeta, error)
}

type Meta added in v1.7.0

type Meta struct {
	ID           UUID                `bson:"backupId"`
	DBpath       string              `bson:"dbpath"`
	OplogStart   BCoplogTS           `bson:"oplogStart"`
	OplogEnd     BCoplogTS           `bson:"oplogEnd"`
	CheckpointTS primitive.Timestamp `bson:"checkpointTimestamp"`
}

type Storage

type Storage struct {
	// Name is config profile name.
	Name string `bson:"name,omitempty" json:"name,omitempty"`
	// IsProfile is true when storage is non-main (external).
	IsProfile bool `bson:"profile,omitempty" json:"profile,omitempty"`

	config.StorageConf `bson:",inline" json:",inline"`
}

Storage keeps storage configuration used during backup.

If external configuration is used, IsProfile is `true` and Name is set.

type UUID added in v1.7.0

type UUID struct{ uuid.UUID }

UUID represents a UUID as saved in MongoDB

func (*UUID) IsZero added in v1.7.0

func (id *UUID) IsZero() bool

IsZero implements the bson.Zeroer interface.

func (UUID) MarshalBSONValue added in v1.7.0

func (id UUID) MarshalBSONValue() (bsontype.Type, []byte, error)

MarshalBSONValue implements the bson.ValueMarshaler interface.

func (*UUID) UnmarshalBSONValue added in v1.7.0

func (id *UUID) UnmarshalBSONValue(t bsontype.Type, raw []byte) error

UnmarshalBSONValue implements the bson.ValueUnmarshaler interface.

Jump to

Keyboard shortcuts

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