Documentation ¶
Index ¶
- Constants
- Variables
- func ConfKeys() []string
- func ValidateConfigKey(k string) bool
- type AuthInfo
- type AuthUser
- type AuthUserRoles
- type BackupCmd
- type BackupMeta
- type BackupReplset
- type ClusterTime
- type Cmd
- type Command
- type CompressionType
- type Condition
- type Config
- type ConfigServerState
- type ConnectionStatus
- type ErrConcurrentOp
- type ErrorCursor
- type IsMaster
- type IsMasterLastWrite
- type Lock
- type LockData
- type LockHeader
- type MongoVersion
- type Node
- func (n *Node) ConnURI() string
- func (n *Node) Connect() error
- func (n *Node) CurrentUser() (*AuthInfo, error)
- func (n *Node) GetIsMaster() (*IsMaster, error)
- func (n *Node) GetMongoVersion() (*MongoVersion, error)
- func (n *Node) GetReplsetStatus() (*ReplsetStatus, error)
- func (n *Node) IsSharded() (bool, error)
- func (n *Node) Name() (string, error)
- func (n *Node) ReplicationLag() (int, error)
- func (n *Node) Session() *mongo.Client
- func (n *Node) Status() (*NodeStatus, error)
- type NodeHealth
- type NodeState
- type NodeStatus
- type OpTime
- type Operation
- type PBM
- func (p *PBM) AddRSMeta(bcpName string, rs BackupReplset) error
- func (p *PBM) AddRestoreRSMeta(name string, rs RestoreReplset) error
- func (p *PBM) BackupHB(bcpName string) error
- func (p *PBM) BackupsList(limit int64) ([]BackupMeta, error)
- func (p *PBM) ChangeBackupState(bcpName string, s Status, msg string) error
- func (p *PBM) ChangeRSState(bcpName string, rsName string, s Status, msg string) error
- func (p *PBM) ChangeRestoreRSState(name string, rsName string, s Status, msg string) error
- func (p *PBM) ChangeRestoreState(name string, s Status, msg string) error
- func (p *PBM) ClusterTime() (primitive.Timestamp, error)
- func (p *PBM) Context() context.Context
- func (p *PBM) DeleteBackup(name string) error
- func (p *PBM) DeleteBackupFiles(meta *BackupMeta, stg storage.Storage) (err error)
- func (p *PBM) DeleteOlderThan(t time.Time) error
- func (p *PBM) GetBackupMeta(name string) (*BackupMeta, error)
- func (p *PBM) GetConfig() (Config, error)
- func (p *PBM) GetConfigVar(key string) (string, error)
- func (p *PBM) GetConfigYaml(fieldRedaction bool) ([]byte, error)
- func (p *PBM) GetIsMaster() (*IsMaster, error)
- func (p *PBM) GetLockData(lh *LockHeader) (LockData, error)
- func (p *PBM) GetLocks(lh *LockHeader) ([]LockData, error)
- func (p *PBM) GetRestoreMeta(name string) (*RestoreMeta, error)
- func (p *PBM) GetShards() ([]Shard, error)
- func (p *PBM) GetStorage() (storage.Storage, error)
- func (p *PBM) ListenCmd() (<-chan Cmd, <-chan error, error)
- func (p *PBM) NewLock(h LockHeader) *Lock
- func (p *PBM) RestoreHB(name string) error
- func (p *PBM) RestoresList(limit int64) ([]RestoreMeta, error)
- func (p *PBM) ResyncBackupList() error
- func (p *PBM) SendCmd(cmd Cmd) error
- func (p *PBM) SetBackupMeta(m *BackupMeta) error
- func (p *PBM) SetConfig(cfg Config) error
- func (p *PBM) SetConfigByte(buf []byte) error
- func (p *PBM) SetConfigVar(key, val string) error
- func (p *PBM) SetLastWrite(bcpName string, ts primitive.Timestamp) error
- func (p *PBM) SetRSLastWrite(bcpName string, rsName string, ts primitive.Timestamp) error
- func (p *PBM) SetRestoreMeta(m *RestoreMeta) error
- type ReplRole
- type ReplsetStatus
- type RestoreCmd
- type RestoreMeta
- type RestoreReplset
- type Shard
- type Status
- type StatusOpTimes
- type StorageConf
- type StorageType
Constants ¶
const ( ReplRoleUnknown = "unknown" ReplRoleShard = "shard" ReplRoleConfigSrv = "configsrv" )
const ( // DB is a name of the PBM database DB = "admin" // LogCollection is the name of the mongo collection that contains PBM logs LogCollection = "pbmLog" // ConfigCollection is the name of the mongo collection that contains PBM configs ConfigCollection = "pbmConfig" // LockCollection is the name of the mongo collection that is used // by agents to coordinate operations (e.g. locks) LockCollection = "pbmLock" // BcpCollection is a collection for backups metadata BcpCollection = "pbmBackups" // BcpOldCollection contains a backup of backups metadata BcpOldCollection = "pbmBackups.old" // RestoresCollection is a collection for restores metadata RestoresCollection = "pbmRestores" // CmdStreamCollection is the name of the mongo collection that contains backup/restore commands stream CmdStreamCollection = "pbmCmd" // NoReplset is the name of a virtual replica set of the standalone node NoReplset = "pbmnoreplicaset" // MetadataFileSuffix is a suffix for the metadata file on a storage MetadataFileSuffix = ".pbm.json" )
const StaleFrameSec uint32 = 30
Variables ¶
var ErrStorageUndefined = errors.New("storage undefined")
ErrStorageUndefined is an error for undefined storage
var WaitActionStart = time.Second * 15
Functions ¶
func ConfKeys ¶ added in v1.1.0
func ConfKeys() []string
ConfKeys returns valid config keys (option names)
func ValidateConfigKey ¶ added in v1.1.0
ValidateConfigKey checks if a config key valid
Types ¶
type AuthInfo ¶ added in v1.1.3
type AuthInfo struct { Users []AuthUser `bson:"authenticatedUsers" json:"authenticatedUsers"` UserRoles []AuthUserRoles `bson:"authenticatedUserRoles" json:"authenticatedUserRoles"` }
type AuthUserRoles ¶ added in v1.1.3
type BackupCmd ¶
type BackupCmd struct { Name string `bson:"name"` Compression CompressionType `bson:"compression"` }
type BackupMeta ¶
type BackupMeta struct { Name string `bson:"name" json:"name"` Replsets []BackupReplset `bson:"replsets" json:"replsets"` Compression CompressionType `bson:"compression" json:"compression"` Store StorageConf `bson:"store" json:"store"` MongoVersion string `bson:"mongodb_version" json:"mongodb_version,omitempty"` StartTS int64 `bson:"start_ts" json:"start_ts"` LastTransitionTS int64 `bson:"last_transition_ts" json:"last_transition_ts"` LastWriteTS primitive.Timestamp `bson:"last_write_ts" json:"last_write_ts"` Hb primitive.Timestamp `bson:"hb" json:"hb"` Status Status `bson:"status" json:"status"` Conditions []Condition `bson:"conditions" json:"conditions"` Error string `bson:"error,omitempty" json:"error,omitempty"` }
BackupMeta is a backup's metadata
type BackupReplset ¶
type BackupReplset struct { Name string `bson:"name" json:"name"` DumpName string `bson:"dump_name" json:"backup_name" ` OplogName string `bson:"oplog_name" json:"oplog_name"` StartTS int64 `bson:"start_ts" json:"start_ts"` Status Status `bson:"status" json:"status"` LastTransitionTS int64 `bson:"last_transition_ts" json:"last_transition_ts"` LastWriteTS primitive.Timestamp `bson:"last_write_ts" json:"last_write_ts"` Error string `bson:"error,omitempty" json:"error,omitempty"` Conditions []Condition `bson:"conditions" json:"conditions"` }
type ClusterTime ¶
type Cmd ¶
type Cmd struct { Cmd Command `bson:"cmd"` Backup BackupCmd `bson:"backup,omitempty"` Restore RestoreCmd `bson:"restore,omitempty"` TS int64 `bson:"ts"` }
type CompressionType ¶
type CompressionType string
const ( CompressionTypeNone CompressionType = "none" CompressionTypeGZIP CompressionType = "gzip" CompressionTypePGZIP CompressionType = "pgzip" CompressionTypeSNAPPY CompressionType = "snappy" CompressionTypeLZ4 CompressionType = "lz4" CompressionTypeS2 CompressionType = "s2" )
type Config ¶ added in v1.1.0
type Config struct {
Storage StorageConf `bson:"storage" json:"storage" yaml:"storage"`
}
Config is a pbm config
type ConfigServerState ¶
type ConfigServerState struct {
OpTime *OpTime `bson:"opTime"`
}
type ConnectionStatus ¶ added in v1.1.3
type ConnectionStatus struct {
AuthInfo AuthInfo `bson:"authInfo" json:"authInfo"`
}
type ErrConcurrentOp ¶ added in v1.1.0
type ErrConcurrentOp struct {
Lock LockHeader
}
func (ErrConcurrentOp) Error ¶ added in v1.1.0
func (e ErrConcurrentOp) Error() string
type ErrorCursor ¶
type ErrorCursor struct {
// contains filtered or unexported fields
}
func (ErrorCursor) Error ¶
func (c ErrorCursor) Error() string
type IsMaster ¶
type IsMaster struct { Hosts []string `bson:"hosts,omitempty"` Msg string `bson:"msg"` MaxBsonObjectSise int64 `bson:"maxBsonObjectSize"` MaxMessageSizeBytes int64 `bson:"maxMessageSizeBytes"` MaxWriteBatchSize int64 `bson:"maxWriteBatchSize"` LocalTime time.Time `bson:"localTime"` LogicalSessionTimeoutMinutes int64 `bson:"logicalSessionTimeoutMinutes"` MaxWireVersion int64 `bson:"maxWireVersion"` MinWireVersion int64 `bson:"minWireVersion"` OK int `bson:"ok"` SetName string `bson:"setName,omitempty"` Primary string `bson:"primary,omitempty"` SetVersion int32 `bson:"setVersion,omitempty"` IsMaster bool `bson:"ismaster"` Secondary bool `bson:"secondary,omitempty"` Hidden bool `bson:"hidden,omitempty"` ConfigSvr int `bson:"configsvr,omitempty"` Me string `bson:"me"` LastWrite IsMasterLastWrite `bson:"lastWrite"` ClusterTime *ClusterTime `bson:"$clusterTime,omitempty"` ConfigServerState *ConfigServerState `bson:"$configServerState,omitempty"` // GleStats *GleStats `bson:"$gleStats,omitempty"` OperationTime *primitive.Timestamp `bson:"operationTime,omitempty"` }
IsMaster represents the document returned by db.runCommand( { isMaster: 1 } )
func (*IsMaster) IsLeader ¶ added in v1.1.0
IsLeader returns true if node can act as backup leader (it's configsrv or non shareded rs)
func (*IsMaster) IsStandalone ¶ added in v1.1.0
IsStandalone returns true if node is not a part of replica set
func (*IsMaster) ReplsetRole ¶
ReplsetRole returns replset role in sharded clister
type IsMasterLastWrite ¶
type IsMasterLastWrite struct { OpTime OpTime `bson:"opTime"` LastWriteDate time.Time `bson:"lastWriteDate"` MajorityOpTime OpTime `bson:"majorityOpTime"` MajorityWriteDate time.Time `bson:"majorityWriteDate"` }
IsMasterLastWrite represents the last write to the MongoDB server
type Lock ¶
type Lock struct { LockData // contains filtered or unexported fields }
Lock is a lock for the PBM operation (e.g. backup, restore)
func (*Lock) Acquire ¶ added in v1.1.0
Acquire tries to acquire the lock. It returns true in case of success and false if there is lock already acquired by another process or some error happened. In case there is already concurrent lock exists, it checks if the concurrent lock isn't stale and clear the rot and tries again if it's happened to be so.
type LockData ¶ added in v1.1.0
type LockData struct { LockHeader `bson:",inline"` Heartbeat primitive.Timestamp `bson:"hb"` // separated in order the lock can be searchable by the header }
type LockHeader ¶ added in v1.1.0
type LockHeader struct { Type Command `bson:"type,omitempty"` Replset string `bson:"replset,omitempty"` Node string `bson:"node,omitempty"` BackupName string `bson:"backup,omitempty"` }
LockHeader describes the lock. This data will be serialased into the mongo document.
type MongoVersion ¶
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
func (*Node) CurrentUser ¶ added in v1.1.3
func (*Node) GetIsMaster ¶
func (*Node) GetMongoVersion ¶
func (n *Node) GetMongoVersion() (*MongoVersion, error)
func (*Node) GetReplsetStatus ¶
func (n *Node) GetReplsetStatus() (*ReplsetStatus, error)
func (*Node) IsSharded ¶
IsSharded return true if node is part of the sharded cluster (in shard or configsrv replset).
func (*Node) ReplicationLag ¶
ReplicationLag returns node replication lag in seconds
func (*Node) Status ¶
func (n *Node) Status() (*NodeStatus, error)
type NodeStatus ¶
type NodeStatus struct { ID int `bson:"_id" json:"_id"` Name string `bson:"name" json:"name"` Health NodeHealth `bson:"health" json:"health"` State NodeState `bson:"state" json:"state"` StateStr string `bson:"stateStr" json:"stateStr"` Uptime int64 `bson:"uptime" json:"uptime"` Optime *OpTime `bson:"optime" json:"optime"` OptimeDate time.Time `bson:"optimeDate" json:"optimeDate"` ConfigVersion int `bson:"configVersion" json:"configVersion"` ElectionTime primitive.Timestamp `bson:"electionTime,omitempty" json:"electionTime,omitempty"` ElectionDate time.Time `bson:"electionDate,omitempty" json:"electionDate,omitempty"` InfoMessage string `bson:"infoMessage,omitempty" json:"infoMessage,omitempty"` OptimeDurable *OpTime `bson:"optimeDurable,omitempty" json:"optimeDurable,omitempty"` OptimeDurableDate time.Time `bson:"optimeDurableDate,omitempty" json:"optimeDurableDate,omitempty"` LastHeartbeat time.Time `bson:"lastHeartbeat,omitempty" json:"lastHeartbeat,omitempty"` LastHeartbeatRecv time.Time `bson:"lastHeartbeatRecv,omitempty" json:"lastHeartbeatRecv,omitempty"` PingMs int64 `bson:"pingMs,omitempty" json:"pingMs,omitempty"` Self bool `bson:"self,omitempty" json:"self,omitempty"` SyncingTo string `bson:"syncingTo,omitempty" json:"syncingTo,omitempty"` }
type PBM ¶
func New ¶
New creates a new PBM object. In the sharded cluster both agents and ctls should have a connection to ConfigServer replica set in order to communicate via PBM collections. If agent's or ctl's local node is not a member of CongigServer, after discovering current topology connection will be established to ConfigServer.
func (*PBM) AddRSMeta ¶ added in v1.1.0
func (p *PBM) AddRSMeta(bcpName string, rs BackupReplset) error
func (*PBM) AddRestoreRSMeta ¶ added in v1.1.2
func (p *PBM) AddRestoreRSMeta(name string, rs RestoreReplset) error
func (*PBM) BackupsList ¶
func (p *PBM) BackupsList(limit int64) ([]BackupMeta, error)
func (*PBM) ChangeBackupState ¶ added in v1.1.0
func (*PBM) ChangeRSState ¶ added in v1.1.0
func (*PBM) ChangeRestoreRSState ¶ added in v1.1.2
func (*PBM) ChangeRestoreState ¶ added in v1.1.2
func (*PBM) ClusterTime ¶ added in v1.1.0
ClusterTime returns mongo's current cluster time
func (*PBM) DeleteBackup ¶ added in v1.2.0
DeleteBackup deletes backup with the given name from the current storage and pbm database
func (*PBM) DeleteBackupFiles ¶ added in v1.2.0
func (p *PBM) DeleteBackupFiles(meta *BackupMeta, stg storage.Storage) (err error)
DeleteBackupFiles removes backup's artefacts from storage
func (*PBM) DeleteOlderThan ¶ added in v1.2.0
DeleteOlderThan deletes backups which older than Time
func (*PBM) GetBackupMeta ¶
func (p *PBM) GetBackupMeta(name string) (*BackupMeta, error)
func (*PBM) GetConfigVar ¶ added in v1.1.0
GetConfigVar returns value of given config vaiable
func (*PBM) GetConfigYaml ¶ added in v1.1.0
func (*PBM) GetIsMaster ¶
GetIsMaster returns IsMaster object encapsulating respective MongoDB structure
func (*PBM) GetLockData ¶ added in v1.1.0
func (p *PBM) GetLockData(lh *LockHeader) (LockData, error)
func (*PBM) GetRestoreMeta ¶ added in v1.1.2
func (p *PBM) GetRestoreMeta(name string) (*RestoreMeta, error)
func (*PBM) GetStorage ¶
GetStorage reads current storage config and creates and returns respective storage.Storage object
func (*PBM) NewLock ¶ added in v1.1.0
func (p *PBM) NewLock(h LockHeader) *Lock
NewLock creates a new Lock object from geven header. Returned lock has no state. So Acquire() and Release() methods should be called.
func (*PBM) RestoresList ¶ added in v1.1.2
func (p *PBM) RestoresList(limit int64) ([]RestoreMeta, error)
func (*PBM) ResyncBackupList ¶ added in v1.1.0
func (*PBM) SetBackupMeta ¶ added in v1.1.0
func (p *PBM) SetBackupMeta(m *BackupMeta) error
func (*PBM) SetConfigByte ¶ added in v1.1.0
func (*PBM) SetConfigVar ¶ added in v1.1.0
func (*PBM) SetLastWrite ¶ added in v1.1.0
func (*PBM) SetRSLastWrite ¶ added in v1.1.0
func (*PBM) SetRestoreMeta ¶ added in v1.1.2
func (p *PBM) SetRestoreMeta(m *RestoreMeta) error
type ReplsetStatus ¶
type ReplsetStatus struct { Set string `bson:"set" json:"set"` Date time.Time `bson:"date" json:"date"` MyState NodeState `bson:"myState" json:"myState"` Members []NodeStatus `bson:"members" json:"members"` Term int64 `bson:"term,omitempty" json:"term,omitempty"` HeartbeatIntervalMillis int64 `bson:"heartbeatIntervalMillis,omitempty" json:"heartbeatIntervalMillis,omitempty"` Optimes *StatusOpTimes `bson:"optimes,omitempty" json:"optimes,omitempty"` Errmsg string `bson:"errmsg,omitempty" json:"errmsg,omitempty"` Ok int `bson:"ok" json:"ok"` ClusterTime *ClusterTime `bson:"$clusterTime,omitempty" json:"$clusterTime,omitempty"` ConfigServerState *ConfigServerState `bson:"$configServerState,omitempty" json:"$configServerState,omitempty"` // GleStats *GleStats `bson:"$gleStats,omitempty" json:"$gleStats,omitempty"` OperationTime *primitive.Timestamp `bson:"operationTime,omitempty" json:"operationTime,omitempty"` }
type RestoreCmd ¶
type RestoreMeta ¶ added in v1.1.2
type RestoreMeta struct { Name string `bson:"name" json:"name"` Backup string `bson:"backup" json:"backup"` Replsets []RestoreReplset `bson:"replsets" json:"replsets"` Hb primitive.Timestamp `bson:"hb" json:"hb"` StartTS int64 `bson:"start_ts" json:"start_ts"` LastTransitionTS int64 `bson:"last_transition_ts" json:"last_transition_ts"` Status Status `bson:"status" json:"status"` Conditions []Condition `bson:"conditions" json:"conditions"` Error string `bson:"error,omitempty" json:"error,omitempty"` }
type RestoreReplset ¶ added in v1.1.2
type RestoreReplset struct { Name string `bson:"name" json:"name"` StartTS int64 `bson:"start_ts" json:"start_ts"` Status Status `bson:"status" json:"status"` LastTransitionTS int64 `bson:"last_transition_ts" json:"last_transition_ts"` LastWriteTS primitive.Timestamp `bson:"last_write_ts" json:"last_write_ts"` Error string `bson:"error,omitempty" json:"error,omitempty"` Conditions []Condition `bson:"conditions" json:"conditions"` }
type Shard ¶
Shard represent config.shard https://docs.mongodb.com/manual/reference/config-database/#config.shards
type StatusOpTimes ¶
type StatusOpTimes struct { LastCommittedOpTime *OpTime `bson:"lastCommittedOpTime" json:"lastCommittedOpTime"` ReadConcernMajorityOpTime *OpTime `bson:"readConcernMajorityOpTime" json:"readConcernMajorityOpTime"` AppliedOpTime *OpTime `bson:"appliedOpTime" json:"appliedOpTime"` DurableOptime *OpTime `bson:"durableOpTime" json:"durableOpTime"` }
type StorageConf ¶ added in v1.2.0
type StorageConf struct { Type StorageType `bson:"type" json:"type" yaml:"type"` S3 s3.Conf `bson:"s3,omitempty" json:"s3,omitempty" yaml:"s3,omitempty"` Filesystem fs.Conf `bson:"filesystem,omitempty" json:"filesystem,omitempty" yaml:"filesystem,omitempty"` }
type StorageType ¶
type StorageType string
const ( StorageUndef StorageType = "" StorageS3 StorageType = "s3" StorageFilesystem StorageType = "filesystem" StorageBlackHole StorageType = "blackhole" )