package main import ( "encoding/json" "os/exec" "time" ) type List struct { Archives []struct { Time string } } func (list *List) LastArchiveUnix() float64 { if len(list.Archives) == 0 { return 0 } last, err := time.Parse("2006-01-02T15:04:05.999999", list.Archives[len(list.Archives)-1].Time) if err != nil { return 0 } return float64(last.Unix()) } func GetList(path string) (*List, error) { cmd := exec.Command("borg", "list", "--json", path) cmd.Env = append(cmd.Env, "BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=yes") stdout, err := cmd.Output() if err != nil { return nil, err } data := &List{} err = json.Unmarshal([]byte(stdout), data) if err != nil { return nil, err } return data, nil }