bm

package
v0.0.0-...-7f4d6aa Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HomeFileVersion = "0.0.1"
	SuffixInc       = '+'
	SuffixDec       = '-'
)
View Source
const (
	OPLOG_DIR  = "oplog/"
	OPLOG_FILE = "oplog.bson"
)
View Source
const (
	OpBackup  = 0
	OpRestore = 1
	OpList    = 4
	OpDelete  = 8

	DefaultKind = "backup"
	DefaultDir  = "mongo-backup"
)
View Source
const (
	LockFileName = "backup.lock"
)

Variables

This section is empty.

Functions

func PrintHelp

func PrintHelp()

Types

type BackupEntry

type BackupEntry struct {
	Id         string              `json:"id"`
	Ts         time.Time           `json:"ts"`
	Source     string              `json:"source"`
	Dest       string              `json:"dest"`
	Kind       string              `json:"kind"`
	Type       string              `json:"type"`
	Compress   bool                `json:"compress"`
	FirstOplog bson.MongoTimestamp `json:"firstOplog"`
	LastOplog  bson.MongoTimestamp `json:"lastOplog"`
}

Home file backup entry json representation

type BackupEnv

type BackupEnv struct {
	// represent command line option
	Options Options
	// contains filtered or unexported fields
}

global variable containing options & context informations

func (*BackupEnv) BackupOplogToDir

func (e *BackupEnv) BackupOplogToDir(cursor *mgo.Iter, dir string) (error, float32, bson.MongoTimestamp, bson.MongoTimestamp)

dump the cursor to a directory if compress option is specified, use lz4 while dumping return the error if any, the number of byte restored, the first & last oplog dumped

func (*BackupEnv) CleanupBackupEnv

func (e *BackupEnv) CleanupBackupEnv()

cleanup the environment variable in case of failover

func (*BackupEnv) CopyDir

func (e *BackupEnv) CopyDir(source string, dest string) (err error, backedByte int64)

Copy a directory into another and compress all files if required

func (*BackupEnv) CopyFile

func (e *BackupEnv) CopyFile(source string, dest string) (err error, backedByte int64)

Copy a file to another destination if the compress flag is present, compress the file while copying using lz4

func (*BackupEnv) DeleteEntries

func (e *BackupEnv) DeleteEntries(criteria, kind string) error

Remove & delete a range of backups

func (*BackupEnv) DeleteEntry

func (e *BackupEnv) DeleteEntry(id string) error

Remove & delete a specific backup

func (*BackupEnv) DumpOplogsToDir

func (e *BackupEnv) DumpOplogsToDir(from, to *BackupEntry) error

dump the oplog between the entries to the requested output directory

func (*BackupEnv) GetDirSize

func (e *BackupEnv) GetDirSize(source string) int64

Return the total size of the directory in byte

func (*BackupEnv) List

func (e *BackupEnv) List(kind string)

List all backups, if kinf is specified, list only backup with this kind

func (*BackupEnv) PerformBackup

func (e *BackupEnv) PerformBackup()

perform an incremental or full backup check the documentation of the performFullBackup, perforIncrementalBackup for more information

func (*BackupEnv) PerformDeletion

func (e *BackupEnv) PerformDeletion() error

Perform deletion according to the command line options

func (*BackupEnv) PerformRestore

func (e *BackupEnv) PerformRestore()

perform the restore & dump the oplog if required oplog is not automatically replayed (futur impprovment?) to restore incremental backup or point in time, mongorestore has to be used

func (*BackupEnv) RestoreCopyDir

func (e *BackupEnv) RestoreCopyDir(entry *BackupEntry, source string, dest string, restoredByte int64, totalRestored int64, pb *utils.ProgressBar) (error, int64)

restore & uncompress a backup to a specific location

func (*BackupEnv) RestoreCopyFile

func (e *BackupEnv) RestoreCopyFile(source string, dest string, entry *BackupEntry) (error, int64)

Copy & Uncompress a specific file if required

func (*BackupEnv) SetupBackupEnvironment

func (e *BackupEnv) SetupBackupEnvironment(o Options) error

initialize the environment object

type BackupHistoryFile

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

Represent a home file

func (*BackupHistoryFile) AddNewEntry

func (b *BackupHistoryFile) AddNewEntry(in BackupEntry) error

add a new entry and flush it to disk

func (*BackupHistoryFile) CheckIncrementalConsistency

func (b *BackupHistoryFile) CheckIncrementalConsistency(entry *BackupEntry) error

check that that incremental restoration of this backup will be consistent

func (*BackupHistoryFile) Create

func (b *BackupHistoryFile) Create(writer *os.File) error

create a new homelogfile and write it to the disk

func (*BackupHistoryFile) FindEntries

func (b *BackupHistoryFile) FindEntries(criteria, kind string) (error, []BackupEntry)

return entries according to a criteria (string0 TODO should we use a lexer/parser?

func (*BackupHistoryFile) FindEntriesFromCriteria

func (b *BackupHistoryFile) FindEntriesFromCriteria(criteria string, input []BackupEntry) (error, []BackupEntry)

Find entries according to a criteria

func (*BackupHistoryFile) FindEntriesFromKind

func (b *BackupHistoryFile) FindEntriesFromKind(kind string, input []BackupEntry) (error, []BackupEntry)

return all entries from this kind

func (*BackupHistoryFile) Flush

func (b *BackupHistoryFile) Flush() error

flush the homelogfile to disk

func (*BackupHistoryFile) GetBackupEntry

func (b *BackupHistoryFile) GetBackupEntry(id string) *BackupEntry

return a backup associated to this speicifc id

func (*BackupHistoryFile) GetIncEntriesBetween

func (b *BackupHistoryFile) GetIncEntriesBetween(from, to *BackupEntry) []BackupEntry

get all incremental BackupEntry between two specific entry used to realize point in time recovery and recreate the oplog

func (*BackupHistoryFile) GetLastEntryAfter

func (b *BackupHistoryFile) GetLastEntryAfter(ts time.Time) *BackupEntry

get the last entry before the requested date used to determine which snapshots to recover for pit

func (*BackupHistoryFile) GetLastFullBackup

func (b *BackupHistoryFile) GetLastFullBackup(etr BackupEntry) *BackupEntry

return the last full backup realized before a specific entry

func (*BackupHistoryFile) GetNextBackup

func (b *BackupHistoryFile) GetNextBackup(etr BackupEntry) BackupEntry

return the next entry after the one provided

func (*BackupHistoryFile) Read

func (b *BackupHistoryFile) Read(reader *os.File) error

Read & Populate the homefile structure from a file

func (*BackupHistoryFile) RemoveEntry

func (b *BackupHistoryFile) RemoveEntry(rm BackupEntry) error

remove an entry and flush it to disk

type HomeLog

type HomeLog struct {
	Version  string        `json:"version"`
	Entries  []BackupEntry `json:"entries"`
	Sequence int           `json:"seq"`
}

Home file json representation

type Options

type Options struct {
	// general options
	Operation int
	Directory string
	Kind      string
	Stepdown  bool
	Position  string
	Debug     bool
	// backup options
	Fsynclock   bool
	Incremental bool
	Compress    bool
	// mongo options
	Mongohost string
	Mongouser string
	Mongopwd  string
	// restore options
	Output   string
	Pit      string
	Snapshot string
}

abstract structure standing for command line options

func ParseOptions

func ParseOptions() Options

parse the command line and create the Options struct

Jump to

Keyboard shortcuts

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