restic/cmd/restic/cmd_cache.go

49 lines
770 B
Go
Raw Normal View History

2015-02-21 23:09:57 +00:00
package main
import (
"fmt"
"github.com/restic/restic"
)
type CmdCache struct{}
func init() {
_, err := parser.AddCommand("cache",
"manage cache",
"The cache command creates and manages the local cache",
&CmdCache{})
if err != nil {
panic(err)
}
}
func (cmd CmdCache) Usage() string {
return "[update|clear]"
}
func (cmd CmdCache) Execute(args []string) error {
// if len(args) == 0 || len(args) > 2 {
// return fmt.Errorf("wrong number of parameters, Usage: %s", cmd.Usage())
// }
s, err := OpenRepo()
if err != nil {
return err
}
2015-03-14 11:30:47 +00:00
cache, err := restic.NewCache(s)
2015-02-21 23:09:57 +00:00
if err != nil {
return err
}
2015-03-14 11:30:47 +00:00
fmt.Printf("clear cache for old snapshots\n")
err = cache.Clear(s)
2015-02-21 23:09:57 +00:00
if err != nil {
return err
}
2015-03-14 11:30:47 +00:00
fmt.Printf("done\n")
2015-02-21 23:09:57 +00:00
return nil
}