Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct {
Command string
Arguments []string
Environ []string
Dir string
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
SetPID SetPID
ScanStdout ScanOutput
UsePowershell bool
// 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.)
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 *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 *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
Source Files
¶
Click to show internal directories.
Click to hide internal directories.