Log changed files after backup

This commit is contained in:
Mikei386
2026-07-10 11:32:48 +02:00
parent 99e2753c10
commit 5aa28cf43e
9 changed files with 193 additions and 8 deletions
+62
View File
@@ -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 {