Log changed files after backup
This commit is contained in:
@@ -98,6 +98,16 @@ type Stats struct {
|
||||
TotalBlobCount int64 `json:"total_blob_count"`
|
||||
}
|
||||
|
||||
type DiffEntry struct {
|
||||
Kind string
|
||||
Path string
|
||||
}
|
||||
|
||||
type DiffResult struct {
|
||||
Entries []DiffEntry
|
||||
Total int
|
||||
}
|
||||
|
||||
func (r *Runner) Init(ctx context.Context, repo model.Repository) error {
|
||||
return r.run(ctx, repo, []string{"init"}, nil, nil)
|
||||
}
|
||||
@@ -280,6 +290,58 @@ func (r *Runner) List(ctx context.Context, repo model.Repository, snapshot, path
|
||||
return items, scanner.Err()
|
||||
}
|
||||
|
||||
func (r *Runner) Diff(ctx context.Context, repo model.Repository, before, after string, limit int) (DiffResult, error) {
|
||||
var output []byte
|
||||
if err := r.run(ctx, repo, []string{"diff", "--metadata", before, after}, nil, &output); err != nil {
|
||||
return DiffResult{}, err
|
||||
}
|
||||
return parseDiffOutput(output, limit), nil
|
||||
}
|
||||
|
||||
func parseDiffOutput(output []byte, limit int) DiffResult {
|
||||
if limit <= 0 {
|
||||
limit = 50
|
||||
}
|
||||
result := DiffResult{}
|
||||
scanner := bufio.NewScanner(bytes.NewReader(output))
|
||||
scanner.Buffer(make([]byte, 0, 64*1024), 2*1024*1024)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
if len(line) < 2 {
|
||||
continue
|
||||
}
|
||||
kind := diffKind(line[0])
|
||||
if kind == "" {
|
||||
continue
|
||||
}
|
||||
path := strings.TrimSpace(line[1:])
|
||||
if path == "" || !strings.HasPrefix(path, "/") {
|
||||
continue
|
||||
}
|
||||
result.Total++
|
||||
if len(result.Entries) == limit {
|
||||
copy(result.Entries, result.Entries[1:])
|
||||
result.Entries[len(result.Entries)-1] = DiffEntry{Kind: kind, Path: path}
|
||||
continue
|
||||
}
|
||||
result.Entries = append(result.Entries, DiffEntry{Kind: kind, Path: path})
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func diffKind(marker byte) string {
|
||||
switch marker {
|
||||
case '+':
|
||||
return "new"
|
||||
case '-':
|
||||
return "removed"
|
||||
case 'M':
|
||||
return "modified"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Runner) Restore(ctx context.Context, repo model.Repository, task model.RestoreTask, progress ProgressCallback) error {
|
||||
args := []string{"restore", task.SnapshotID, "--target", task.Target, "--json"}
|
||||
for _, include := range task.Includes {
|
||||
|
||||
Reference in New Issue
Block a user