Documentation ¶
Index ¶
- Constants
- type Arg
- type ArgType
- type Args
- func (a *Args) AddArg(arg string, argType ArgType)
- func (a *Args) AddArgs(args []string, argType ArgType)
- func (a *Args) AddFlag(key, value string, argType ArgType)
- func (a *Args) AddFlags(key string, values []string, argType ArgType)
- func (a *Args) Clone() *Args
- func (a *Args) Get(name string) ([]Arg, bool)
- func (a *Args) GetAll() []string
- func (a *Args) Remove(name string) ([]Arg, bool)
- func (a *Args) RemoveArg(name string) (removed []Arg)
- func (a *Args) Rename(oldName, newName string) bool
- func (a *Args) SetLegacyArg(legacy bool) *Args
- func (a *Args) ToMap() map[string][]string
- func (a *Args) Walk(callback func(name string, arg *Arg) *Arg)
- type Command
- type OutputAnalyser
- func (a OutputAnalyser) AnalyseLines(output io.Reader) (err error)
- func (a OutputAnalyser) AnalyseStringLines(output string) error
- func (a OutputAnalyser) ContainsRemoteLockFailure() bool
- func (a OutputAnalyser) GetRemoteLockedBy() (string, bool)
- func (a OutputAnalyser) GetRemoteLockedSince() (time.Duration, bool)
- func (a *OutputAnalyser) Reset() *OutputAnalyser
- func (a *OutputAnalyser) SetCallback(name, pattern string, minCount, maxCalls int, stopOnError bool, ...) error
- type ResticJsonSummary
- type ScanOutput
- type SetPID
Constants ¶
const ArgTypeCount = 4
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArgType ¶ added in v0.15.0
type ArgType int
const ( ArgConfigEscape ArgType = iota // escape each special character but don't add quotes ArgConfigKeepGlobQuote // use double quotes around argument when needed so the shell doesn't resolve glob patterns ArgCommandLineEscape // same as ArgConfigEscape but argument is coming from the command line ArgConfigBackupSource // same as ArgConfigEscape but represents the folders to add at the end of a backup command ArgLegacyEscape ArgLegacyKeepGlobQuote ArgLegacyCommandLineEscape ArgLegacyConfigBackupSource )
type Args ¶ added in v0.15.0
type Args struct {
// contains filtered or unexported fields
}
func (*Args) GetAll ¶ added in v0.15.0
GetAll return a clean list of arguments to send on the command line
func (*Args) SetLegacyArg ¶ added in v0.15.0
SetLegacyArg is used to activate the legacy (broken) mode of sending arguments on the restic command line
type Command ¶
type Command struct { Command string Arguments []string Environ []string Shell []string Dir string Stdin io.Reader Stdout io.Writer Stderr io.Writer SetPID SetPID ScanStdout ScanOutput // contains filtered or unexported fields }
Command holds the configuration to run a shell command
func NewCommand ¶
NewCommand instantiate a default Command without receiving OS signals (SIGTERM, etc.)
func NewSignalledCommand ¶ added in v0.6.1
NewSignalledCommand instantiate a default Command receiving OS signals (SIGTERM, etc.)
func (*Command) GetShellCommand ¶ added in v0.18.0
GetShellCommand transforms the command line and arguments to be launched via a shell (sh or cmd.exe)
type OutputAnalyser ¶ added in v0.14.0
type OutputAnalyser struct {
// contains filtered or unexported fields
}
func NewOutputAnalyser ¶ added in v0.14.0
func NewOutputAnalyser() *OutputAnalyser
func (OutputAnalyser) AnalyseLines ¶ added in v0.14.0
func (a OutputAnalyser) AnalyseLines(output io.Reader) (err error)
func (OutputAnalyser) AnalyseStringLines ¶ added in v0.14.0
func (a OutputAnalyser) AnalyseStringLines(output string) error
func (OutputAnalyser) ContainsRemoteLockFailure ¶ added in v0.14.0
func (a OutputAnalyser) ContainsRemoteLockFailure() bool
func (OutputAnalyser) GetRemoteLockedBy ¶ added in v0.14.0
func (a OutputAnalyser) GetRemoteLockedBy() (string, bool)
func (OutputAnalyser) GetRemoteLockedSince ¶ added in v0.14.0
func (a OutputAnalyser) GetRemoteLockedSince() (time.Duration, bool)
func (*OutputAnalyser) Reset ¶ added in v0.17.0
func (a *OutputAnalyser) Reset() *OutputAnalyser
func (*OutputAnalyser) SetCallback ¶ added in v0.17.0
func (a *OutputAnalyser) SetCallback(name, pattern string, minCount, maxCalls int, stopOnError bool, callback func(line string) error) error
SetCallback registers a custom callback that is invoked when pattern (regex) matches a line.
type ResticJsonSummary ¶ added in v0.12.0
type ResticJsonSummary struct { MessageType string `json:"message_type"` FilesNew int `json:"files_new"` FilesChanged int `json:"files_changed"` FilesUnmodified int `json:"files_unmodified"` DirsNew int `json:"dirs_new"` DirsChanged int `json:"dirs_changed"` DirsUnmodified int `json:"dirs_unmodified"` DataBlobs int `json:"data_blobs"` TreeBlobs int `json:"tree_blobs"` DataAdded uint64 `json:"data_added"` TotalFilesProcessed int `json:"total_files_processed"` TotalBytesProcessed uint64 `json:"total_bytes_processed"` TotalDuration float64 `json:"total_duration"` SnapshotID string `json:"snapshot_id"` }
type ScanOutput ¶ added in v0.12.0
ScanOutput is a callback to scan the default output of the command The implementation is expected to send everything read from the reader back to the writer
var ScanBackupJson ScanOutput = func(r io.Reader, summary *monitor.Summary, w io.Writer) error { bogusPrefix := []byte("\r\x1b[2K") jsonPrefix := []byte(`{"message_type":"`) summaryPrefix := []byte(`{"message_type":"summary",`) jsonSuffix := []byte("}") eol := "\n" if runtime.GOOS == "windows" { eol = "\r\n" } scanner := bufio.NewScanner(r) for scanner.Scan() { line := scanner.Bytes() line = bytes.TrimPrefix(line, bogusPrefix) if bytes.HasPrefix(line, jsonPrefix) && bytes.HasSuffix(line, jsonSuffix) { if bytes.HasPrefix(line, summaryPrefix) { jsonSummary := ResticJsonSummary{} err := json.Unmarshal(line, &jsonSummary) if err != nil { continue } summary.FilesNew = jsonSummary.FilesNew summary.FilesChanged = jsonSummary.FilesChanged summary.FilesUnmodified = jsonSummary.FilesUnmodified summary.DirsNew = jsonSummary.DirsNew summary.DirsChanged = jsonSummary.DirsChanged summary.DirsUnmodified = jsonSummary.DirsUnmodified summary.FilesTotal = jsonSummary.TotalFilesProcessed summary.BytesAdded = jsonSummary.DataAdded summary.BytesTotal = jsonSummary.TotalBytesProcessed } continue } _, _ = w.Write(line) _, _ = w.Write([]byte(eol)) } if err := scanner.Err(); err != nil { return err } return nil }
ScanBackupJson should populate the backup summary values from the output of the --json flag
var ScanBackupPlain ScanOutput = func(r io.Reader, summary *monitor.Summary, w io.Writer) error { eol := "\n" if runtime.GOOS == "windows" { eol = "\r\n" } rawBytes, unit, duration := 0.0, "", "" scanner := bufio.NewScanner(r) for scanner.Scan() { w.Write([]byte(scanner.Text() + eol)) _, _ = fmt.Sscanf(scanner.Text(), "Files: %d new, %d changed, %d unmodified", &summary.FilesNew, &summary.FilesChanged, &summary.FilesUnmodified) _, _ = fmt.Sscanf(scanner.Text(), "Dirs: %d new, %d changed, %d unmodified", &summary.DirsNew, &summary.DirsChanged, &summary.DirsUnmodified) n, err := fmt.Sscanf(scanner.Text(), "Added to the repo: %f %3s", &rawBytes, &unit) if n == 2 && err == nil { summary.BytesAdded = unformatBytes(rawBytes, unit) } n, err = fmt.Sscanf(scanner.Text(), "processed %d files, %f %3s in %s", &summary.FilesTotal, &rawBytes, &unit, &duration) if n == 4 && err == nil { summary.BytesTotal = unformatBytes(rawBytes, unit) } } if err := scanner.Err(); err != nil { return err } return nil }
ScanBackupPlain should populate the backup summary values from the standard output