mirror of
https://github.com/kopia/kopia.git
synced 2026-01-25 14:58:00 -05:00
40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
package cli
|
|
|
|
import (
|
|
"github.com/rs/zerolog/log"
|
|
|
|
"github.com/kopia/kopia/snapshot"
|
|
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
|
)
|
|
|
|
var (
|
|
policyRemoveCommand = policyCommands.Command("remove", "Remove snapshot policy for a single directory, user@host or a global policy.").Alias("rm").Alias("delete")
|
|
policyRemoveTargets = policyRemoveCommand.Arg("target", "Target of a policy ('global','user@host','@host') or a path").Strings()
|
|
policyRemoveGlobal = policyRemoveCommand.Flag("global", "Set global policy").Bool()
|
|
)
|
|
|
|
func init() {
|
|
policyRemoveCommand.Action(removePolicy)
|
|
}
|
|
|
|
func removePolicy(context *kingpin.ParseContext) error {
|
|
rep := mustOpenRepository(nil)
|
|
defer rep.Close() //nolint: errcheck
|
|
|
|
mgr := snapshot.NewPolicyManager(rep)
|
|
|
|
targets, err := policyTargets(policyRemoveGlobal, policyRemoveTargets)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, target := range targets {
|
|
log.Printf("Removing policy on %q...", target)
|
|
if err := mgr.RemovePolicy(target); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|