Files
kopia/cli/command_maintenance_info.go
Jarek Kowalski fa7976599c repo: refactored repository interfaces (#780)
- `repo.Repository` is now read-only and only has methods that can be supported over kopia server
- `repo.RepositoryWriter` has read-write methods that can be supported over kopia server
- `repo.DirectRepository` is read-only and contains all methods of `repo.Repository` plus some low-level methods for data inspection
- `repo.DirectRepositoryWriter` contains write methods for `repo.DirectRepository`

- `repo.Reader` removed and merged with `repo.Repository`
- `repo.Writer` became `repo.RepositoryWriter`
- `*repo.DirectRepository` struct became `repo.DirectRepository`
  interface

Getting `{Direct}RepositoryWriter` requires using `NewWriter()` or `NewDirectWriter()` on a read-only repository and multiple simultaneous writers are supported at the same time, each writing to their own indexes and pack blobs.

`repo.Open` returns `repo.Repository` (which is also `repo.RepositoryWriter`).

* content: removed implicit flush on content manager close
* repo: added tests for WriteSession() and implicit flush behavior
* invalidate manifest manager after write session

* cli: disable maintenance in 'kopia server start'
  Server will close the repository before completing.

* repo: unconditionally close RepositoryWriter in {Direct,}WriteSession
* repo: added panic in case somebody tries to create RepositoryWriter after closing repository
  - used atomic to manage SharedManager.closed

* removed stale example
* linter: fixed spurious failures

Co-authored-by: Julio López <julio+gh@kasten.io>
2021-01-20 11:41:47 -08:00

88 lines
2.0 KiB
Go

package cli
import (
"context"
"encoding/json"
"os"
"time"
"github.com/pkg/errors"
"github.com/kopia/kopia/internal/clock"
"github.com/kopia/kopia/repo"
"github.com/kopia/kopia/repo/maintenance"
)
var (
maintenanceInfoCommand = maintenanceCommands.Command("info", "Display maintenance information").Alias("status")
maintenanceInfoJSON = maintenanceInfoCommand.Flag("json", "Show raw JSON data").Short('j').Bool()
)
func runMaintenanceInfoCommand(ctx context.Context, rep repo.DirectRepository) error {
p, err := maintenance.GetParams(ctx, rep)
if err != nil {
return errors.Wrap(err, "unable to get maintenance params")
}
s, err := maintenance.GetSchedule(ctx, rep)
if err != nil {
return errors.Wrap(err, "unable to get maintenance schedule")
}
if *maintenanceInfoJSON {
e := json.NewEncoder(os.Stdout)
e.SetIndent("", " ")
e.Encode(s) //nolint:errcheck
return nil
}
printStdout("Owner: %v\n", p.Owner)
printStdout("Quick Cycle:\n")
displayCycleInfo(&p.QuickCycle, s.NextQuickMaintenanceTime, rep)
printStdout("Full Cycle:\n")
displayCycleInfo(&p.FullCycle, s.NextFullMaintenanceTime, rep)
printStdout("Recent Maintenance Runs:\n")
for run, timings := range s.Runs {
printStdout(" %v:\n", run)
for _, t := range timings {
errInfo := ""
if t.Success {
errInfo = "SUCCESS"
} else {
errInfo = "ERROR: " + t.Error
}
printStdout(
" %v (%v) %v\n",
formatTimestamp(t.Start),
t.End.Sub(t.Start).Truncate(time.Second),
errInfo)
}
}
return nil
}
func displayCycleInfo(c *maintenance.CycleParams, t time.Time, rep repo.DirectRepository) {
printStdout(" scheduled: %v\n", c.Enabled)
if c.Enabled {
printStdout(" interval: %v\n", c.Interval)
if rep.Time().Before(t) {
printStdout(" next run: %v (in %v)\n", formatTimestamp(t), clock.Until(t).Truncate(time.Second))
} else {
printStdout(" next run: now\n")
}
}
}
func init() {
maintenanceInfoCommand.Action(directRepositoryReadAction(runMaintenanceInfoCommand))
}