backup

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2018 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MsgRsyncInfo  = "RsyncInfo"
	MsgGolangInfo = "GolangInfo"

	MsgFolderBackupTypeSkipDescription      = "FolderBackupTypeSkipDescription"
	MsgFolderBackupTypeRecursiveDescription = "FolderBackupTypeRecursiveDescription"
	MsgFolderBackupTypeContentDescription   = "FolderBackupTypeContentDescription"

	MsgLogPlanStageStarting                  = "LogPlanStageStarting"
	MsgLogPlanStageStartTime                 = "LogPlanStageStartTime"
	MsgLogPlanStageEndTime                   = "LogPlanStageEndTime"
	MsgLogPlanStartIterateViaNSources        = "LogPlanStartIterateViaNSources"
	MsgLogPlanStageInquirySource             = "LogPlanStageInquirySource"
	MsgLogPlanStageSourceFolderCountInfo     = "LogPlanStageSourceFolderCountInfo"
	MsgLogPlanStageSourceSkipFolderCountInfo = "LogPlanStageSourceSkipFolderCountInfo"
	MsgLogPlanStageSourceTotalSizeInfo       = "LogPlanStageSourceTotalSizeInfo"
	MsgLogPlanStageUseTemporaryFolder        = "LogPlanStageUseTemporaryFolder"
	MsgLogPlanStageBuildFolderError          = "LogPlanStageBuildFolderError"

	MsgLogBackupStageStarting                               = "LogBackupStageStarting"
	MsgLogBackupStageStartTime                              = "LogBackupStageStartTime"
	MsgLogBackupStageEndTime                                = "LogBackupStageEndTime"
	MsgLogBackupStageBackupToDestination                    = "LogBackupStageBackupToDestination"
	MsgLogBackupStagePreviousBackupDiscoveryPermissionError = "LogBackupStagePreviousBackupDiscoveryPermissionError"
	MsgLogBackupStagePreviousBackupDiscoveryOtherError      = "LogBackupStagePreviousBackupDiscoveryOtherError"
	MsgLogBackupStagePreviousBackupFoundAndWillBeUsed       = "LogBackupStagePreviousBackupFoundAndWillBeUsed"
	MsgLogBackupStagePreviousBackupFoundButDisabled         = "LogBackupStagePreviousBackupFoundButDisabled"
	MsgLogBackupStagePreviousBackupNotFound                 = "LogBackupStagePreviousBackupNotFound"
	MsgLogBackupStageStartToBackupFromSource                = "LogBackupStageStartToBackupFromSource"
	MsgLogBackupStageRenameDestination                      = "LogBackupStageRenameDestination"
	MsgLogBackupStageFailedToCreateFolder                   = "LogBackupStageFailedToCreateFolder"
	MsgLogBackupDetectedTotalBackupSizeGetChanged           = "LogBackupDetectedTotalBackupSizeGetChanged"
	MsgLogBackupStageProgressBackupSuccess                  = "LogBackupStageProgressBackupSuccess"
	MsgLogBackupStageProgressBackupError                    = "LogBackupStageProgressBackupError"
	MsgLogBackupStageProgressSkipBackupError                = "LogBackupStageProgressSkipBackupError"
	MsgLogBackupStageCriticalError                          = "LogBackupStageCriticalError"
	MsgLogBackupStageDiscoveringPreviousBackups             = "LogBackupStageDiscoveringPreviousBackups"
	MsgLogBackupStageRecoveredFromError                     = "LogBackupStageRecoveredFromError"
	MsgLogBackupStageSaveRsyncExtraLogTo                    = "LogBackupStageSaveRsyncExtraLogTo"
	MsgLogBackupStageSaveLogTo                              = "LogBackupStageSaveLogTo"
	MsgLogBackupStageExitMessage                            = "LogBackupStageExitMessage"

	MsgLogStatisticsSummaryCaption                            = "LogStatisticsSummaryCaption"
	MsgLogStatisticsEnvironmentCaption                        = "LogStatisticsEnvironmentCaption"
	MsgLogStatisticsResultsCaption                            = "LogStatisticsResultsCaption"
	MsgLogStatisticsStatusCaption                             = "LogStatisticsStatusCaption"
	MsgLogStatisticsStatusSuccessfullyCompleted               = "LogStatisticsStatusSuccessfullyCompleted"
	MsgLogStatisticsStatusCompletedWithErrors                 = "LogStatisticsStatusCompletedWithErrors"
	MsgLogStatisticsPlanStageCaption                          = "LogStatisticsPlanStageCaption"
	MsgLogStatisticsPlanStageSourceToBackup                   = "LogStatisticsPlanStageSourceToBackup"
	MsgLogStatisticsPlanStageTotalSize                        = "LogStatisticsPlanStageTotalSize"
	MsgLogStatisticsPlanStageFolderCount                      = "LogStatisticsPlanStageFolderCount"
	MsgLogStatisticsPlanStageFolderSkipCount                  = "LogStatisticsPlanStageFolderSkipCount"
	MsgLogStatisticsPlanStageTimeTaken                        = "LogStatisticsPlanStageTimeTaken"
	MsgLogStatisticsBackupStageCaption                        = "LogStatisticsBackupStageCaption"
	MsgLogStatisticsBackupStageDestinationPath                = "LogStatisticsBackupStageDestinationPath"
	MsgLogStatisticsBackupStagePreviousBackupFound            = "LogStatisticsBackupStagePreviousBackupFound"
	MsgLogStatisticsBackupStagePreviousBackupFoundButDisabled = "LogStatisticsBackupStagePreviousBackupFoundButDisabled"
	MsgLogStatisticsBackupStageNoValidPreviousBackupFound     = "LogStatisticsBackupStageNoValidPreviousBackupFound"
	MsgLogStatisticsBackupStageTotalSize                      = "LogStatisticsBackupStageTotalSize"
	MsgLogStatisticsBackupStageSkippedSize                    = "LogStatisticsBackupStageSkippedSize"
	MsgLogStatisticsBackupStageFailedToBackupSize             = "LogStatisticsBackupStageFailedToBackupSize"
	MsgLogStatisticsBackupStageTimeTaken                      = "LogStatisticsBackupStageTimeTaken"
)
View Source
const MaxInt = int(MaxUint >> 1)
View Source
const MaxUint = ^uint(0)
View Source
const MinInt = -MaxInt - 1
View Source
const (
	TAB_RUNE = '\t'
)

Variables

View Source
var (
	DoubleSplitLine string = strings.Repeat("=", 100)
	SingleSplitLine string = strings.Repeat("-", 100)
)
View Source
var LocalLog = logger.NewPackageLogger("backup",

	logger.InfoLevel,
)

Functions

func BuildBackupPlan

func BuildBackupPlan(ctx context.Context, lg logger.PackageLog, config *Config,
	notifier Notifier) (*BackupPlan, *Progress, error)

func ChipherStr

func ChipherStr(str string) string

ChipherStr encode str with SHA256.

func CreateMetadataSignatureFile

func CreateMetadataSignatureFile(config *Config, destPath string) error

func EncodeSignatures

func EncodeSignatures(signs NodeSignatures) (string, error)

EncodeSignatures encode NodeSignatures object to self-describing binary format.

func GetBackupFolderName

func GetBackupFolderName(
	incomplete bool, date *time.Time) string

GetBackupFolderName return new folder name for ongoing backup process.

func GetBackupTypeDescription

func GetBackupTypeDescription(backupType core.FolderBackupType) string

func GetLogFileName

func GetLogFileName() string

GetLogFileName return the name of general backup process log.

func GetMetadataSignatureFileName

func GetMetadataSignatureFileName() string

GetMetadataSignatureFileName return the name of specific file which describe all sources used in backup process.

func GetRsyncLogFileName

func GetRsyncLogFileName() string

GetRsyncLogFileName return the name of specific low-level Rsync utility log.

func MeasureDir

func MeasureDir(ctx context.Context, dir *core.Dir, retryCount *int, log *rsync.Logging,
	blockSize *backupBlockSizeSettings) (int, error)

Types

type BackupNode

type BackupNode struct {
	SourceRsync string `toml:"src_rsync"`
	DestSubPath string `toml:"dst_subpath"`
}

type BackupNodePlan

type BackupNodePlan struct {
	BackupNode BackupNode
	RootDir    *core.Dir
}

BackupNodePlan contain information about single rsync source backup.

type BackupPlan

type BackupPlan struct {
	Config     *Config
	Nodes      []BackupNodePlan
	BackupSize core.FolderSize
}

BackupPlan keep all necessary information obtained from preferences and 1st backup pass to start backup process.

func (*BackupPlan) RunBackup

func (this *BackupPlan) RunBackup(progress *Progress, destPath string, errorHook rsync.ErrorHook) error

type Config

type Config struct {
	SigFileIgnoreBackup                string `toml:"sig_file_ignore_backup"`
	RsyncRetryCount                    *int   `toml:"retry_count"`
	AutoManageBackupBlockSize          *bool  `auto_manage_backup_block_size`
	MaxBackupBlockSizeMb               *int   `toml:"max_backup_block_size_mb"`
	UsePreviousBackup                  *bool  `toml:"use_previous_backup"`
	NumberOfPreviousBackupToUse        *int   `toml:"number_of_previous_backup_to_use"`
	EnableLowLevelLogForRsync          *bool  `toml:"enable_low_level_log_rsync"`
	EnableIntensiveLowLevelLogForRsync *bool  `toml:"enable_intensive_low_level_log_rsync"`
	// rsync --compress
	RsyncCompressFileTransfer *bool `toml:"rsync_compress_file_transfer"`
	// rsync --links
	RsyncRecreateSymlinks *bool `toml:"rsync_recreate_symlinks"`
	// rsync --perms
	RsyncTransferSourcePermissions *bool `toml:"rsync_transfer_source_permissions"`
	// rsync --group
	RsyncTransferSourceGroup *bool `toml:"rsync_transfer_source_group"`
	// rsync --owner
	RsyncTransferSourceOwner *bool `toml:"rsync_transfer_source_owner"`
	// rsync --devices
	RsyncTransferDeviceFiles *bool `toml:"rsync_transfer_device_files"`
	// rsync --specials
	RsyncTransferSpecialFiles *bool `toml:"rsync_transfer_special_files"`

	BackupNodes []BackupNode `toml:"backup_node"`
}

func NewConfig

func NewConfig(filePath string) (*Config, error)

type FilesSortedByDate

type FilesSortedByDate struct {
	Files []struct {
		// contains filtered or unexported fields
	}
}

func (FilesSortedByDate) Len

func (s FilesSortedByDate) Len() int

func (FilesSortedByDate) Less

func (s FilesSortedByDate) Less(i, j int) bool

func (FilesSortedByDate) Swap

func (s FilesSortedByDate) Swap(i, j int)

type LogFiles

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

func NewLogFiles

func NewLogFiles() *LogFiles

func (*LogFiles) ChangeRootPath

func (v *LogFiles) ChangeRootPath(newRootPath string) error

func (*LogFiles) Close

func (v *LogFiles) Close() error

func (*LogFiles) GetAppendFile

func (v *LogFiles) GetAppendFile(suffixPath string) (*os.File, error)

type NodeSignature

type NodeSignature struct {
	SourceRsyncCipher string
	DestSubPath       string
}

func GetSignature

func GetSignature(node BackupNode) NodeSignature

type NodeSignatures

type NodeSignatures struct {
	Signatures []NodeSignature
}

func DecodeSignatures

func DecodeSignatures(str string) (*NodeSignatures, error)

DecodeSignatures decode NodeSignatures object from self-describing binary format.

func GetNodeSignatures

func GetNodeSignatures(config *Config) NodeSignatures

func (NodeSignatures) FindFirstSignature

func (v NodeSignatures) FindFirstSignature(signature string) *NodeSignature

type Notifier

type Notifier interface {
	NotifyPlanStage_NodeStructureStartInquiry(sourceID int,
		sourceRsync string) error
	NotifyPlanStage_NodeStructureDoneInquiry(sourceID int,
		sourceRsync string, dir *core.Dir) error
	NotifyBackupStage_FolderStartBackup(rootDest string,
		paths core.SrcDstPath, backupType core.FolderBackupType,
		leftToBackup core.FolderSize,
		timePassed time.Duration, eta *time.Duration,
	) error
	NotifyBackupStage_FolderDoneBackup(rootDest string,
		paths core.SrcDstPath, backupType core.FolderBackupType,
		leftToBackup core.FolderSize, sizeDone core.SizeProgress,
		timePassed time.Duration, eta *time.Duration,
		sessionErr error) error
}

type PrevBackup

type PrevBackup struct {
	// Full path to signature file name
	SignatureFileName string
	Signature         NodeSignature
}

PrevBackup describe found previous backup, which contain same Rsync source. Such previous backups used for Rsync utility deduplication, which significantly decrease size and time for repeated backup sessions.

func (PrevBackup) GetDirPath

func (v PrevBackup) GetDirPath() string

type PrevBackups

type PrevBackups struct {
	Backups []PrevBackup
}

PrevBackups keeps list of previous backup found. See description of PrevBackup.

func FindPrevBackupPathsByNodeSignatures

func FindPrevBackupPathsByNodeSignatures(lg logger.PackageLog, destPath string,
	signs NodeSignatures, lastN int) (*PrevBackups, error)

func (*PrevBackups) GetDirPaths

func (v *PrevBackups) GetDirPaths() []string

type Progress

type Progress struct {
	Context  context.Context
	LogFiles *LogFiles
	Log      logger.PackageLog
	// LogBuffer      bytes.Buffer
	RsyncLog *rsync.Logging
	// RsyncLogBuffer bytes.Buffer
	Progress      *core.SizeProgress
	TotalProgress *core.SizeProgress
	// GlobalErrorCount int
	Notifier Notifier

	StartPlanTime   time.Time
	EndPlanTime     time.Time
	StartBackupTime time.Time
	EndBackupTime   time.Time
	PrevBackups     *PrevBackups

	RootDest     string
	BackupFolder string

	// Notify only once
	SizeChangedNotified bool
}

func (*Progress) CalcTimePassedAndETA

func (this *Progress) CalcTimePassedAndETA(plan *BackupPlan) (time.Duration, *time.Duration)

func (*Progress) Close

func (this *Progress) Close() error

func (*Progress) EventBackupStage_FolderDoneBackup

func (this *Progress) EventBackupStage_FolderDoneBackup(paths core.SrcDstPath,
	backupType core.FolderBackupType, plan *BackupPlan,
	sizeDone core.SizeProgress, sessionErr error) error

func (*Progress) EventBackupStage_FolderStartBackup

func (this *Progress) EventBackupStage_FolderStartBackup(paths core.SrcDstPath,
	backupType core.FolderBackupType, plan *BackupPlan) error

func (*Progress) EventPlanStage_NodeStructureDoneInquiry

func (this *Progress) EventPlanStage_NodeStructureDoneInquiry(sourceId int,
	sourceRsync string, dir *core.Dir) error

func (*Progress) EventPlanStage_NodeStructureStartInquiry

func (this *Progress) EventPlanStage_NodeStructureStartInquiry(sourceId int,
	sourceRsync string) error

func (*Progress) FinishBackupStage

func (this *Progress) FinishBackupStage()

func (*Progress) FinishPlanStage

func (this *Progress) FinishPlanStage()

func (*Progress) GetBackupFullPath

func (this *Progress) GetBackupFullPath(backupFolder string) string

func (*Progress) GetTotalStatistics

func (this *Progress) GetTotalStatistics(plan *BackupPlan) ([]string, error)

func (*Progress) GetTotalTimeTaken

func (this *Progress) GetTotalTimeTaken() time.Duration

func (*Progress) LeftToBackup

func (this *Progress) LeftToBackup(plan *BackupPlan) core.FolderSize

func (*Progress) PrevBackupsUsed

func (this *Progress) PrevBackupsUsed(prevBackups *PrevBackups)

func (*Progress) PrintTotalStatistics

func (this *Progress) PrintTotalStatistics(lg logger.PackageLog, plan *BackupPlan) error

func (*Progress) SayGoodbye

func (this *Progress) SayGoodbye(lg logger.PackageLog)

func (*Progress) SetBackupFolder

func (this *Progress) SetBackupFolder(backupFolder string) error

func (*Progress) SetRootDestination

func (this *Progress) SetRootDestination(rootDestPath string)

func (*Progress) SizeBackedUp

func (this *Progress) SizeBackedUp() core.FolderSize

func (*Progress) StartBackupStage

func (this *Progress) StartBackupStage()

func (*Progress) StartPlanStage

func (this *Progress) StartPlanStage()

Source Files

  • abstract.go
  • common.go
  • config.go
  • deduplication.go
  • heuristic.go
  • logfiles.go
  • messagekeys.go
  • process.go
  • progress.go
  • utils.go

Jump to

Keyboard shortcuts

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