Files
kopia/cli/command_server_status.go
Jarek Kowalski 2e9a57f0b4 server: support for server control APIs and tooling (#1644)
This adds new set of APIs `/api/v1/control/*` which can be used to administratively control a running server.

Once the server is started, the administrative user can control it
using CLI commands:

export KOPIA_SERVER_ADDRESS=...
export KOPIA_SERVER_CERT_FINGERPRINT=...
export KOPIA_SERVER_PASSWORD=...

* `kopia server status` - displays status of sources managed by the server
* `kopia server snapshot` - triggers server-side upload of snapshots for managed sources
* `kopia server cancel` - cancels upload of snapshots for managed sources
* `kopia server pause` - pauses scheduled snapshots for managed sources
* `kopia server resume` - resumes scheduled snapshots for managed sources
* `kopia server refresh` - causes server to resynchronize with externally-made changes, such as policies or new sources
* `kopia server flush` - causes server to flush all pending writes
* `kopia server shutdown` - graceful shutdown of the server

Authentication uses new user `server-control` and is disabled
by default. To enable it when starting the server, provide the password
using one of the following methods:

* `--server-control-password`
* `--random-server-control-password`
* `.htpasswd` file
* `KOPIA_SERVER_CONTROL_PASSWORD` environment variable

This change allows us to tighten the API security and remove some
methods that UI user was able to call, but which were not needed.
2022-01-03 18:48:38 -08:00

47 lines
981 B
Go

package cli
import (
"context"
"github.com/pkg/errors"
"github.com/kopia/kopia/internal/apiclient"
"github.com/kopia/kopia/internal/serverapi"
)
type commandServerStatus struct {
sf serverClientFlags
out textOutput
remote bool
}
func (c *commandServerStatus) setup(svc appServices, parent commandParent) {
cmd := parent.Command("status", "Status of Kopia server")
cmd.Flag("remote", "Show remote sources").BoolVar(&c.remote)
c.sf.setup(cmd)
c.out.setup(svc)
cmd.Action(svc.serverAction(&c.sf, c.runServerStatus))
}
func (c *commandServerStatus) runServerStatus(ctx context.Context, cli *apiclient.KopiaAPIClient) error {
var status serverapi.SourcesResponse
if err := cli.Get(ctx, "control/sources", nil, &status); err != nil {
return errors.Wrap(err, "unable to list sources")
}
for _, src := range status.Sources {
if src.Status == "REMOTE" && !c.remote {
continue
}
c.out.printStdout("%v: %v\n", src.Status, src.Source)
}
return nil
}