restic/cmd/restic/cmd_cache.go

57 lines
948 B
Go
Raw Normal View History

2015-02-21 18:09:57 -05:00
package main
import (
"fmt"
"github.com/restic/restic"
)
type CmdCache struct {
global *GlobalOptions
}
2015-02-21 18:09:57 -05:00
func init() {
_, err := parser.AddCommand("cache",
"manage cache",
"The cache command creates and manages the local cache",
&CmdCache{global: &globalOpts})
2015-02-21 18:09:57 -05:00
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())
// }
repo, err := cmd.global.OpenRepository()
2015-02-21 18:09:57 -05:00
if err != nil {
return err
}
lock, err := lockRepo(repo)
defer unlockRepo(lock)
2015-06-27 08:40:18 -04:00
if err != nil {
return err
}
cache, err := restic.NewCache(repo, cmd.global.CacheDir)
2015-02-21 18:09:57 -05:00
if err != nil {
return err
}
2015-03-14 07:30:47 -04:00
fmt.Printf("clear cache for old snapshots\n")
err = cache.Clear(repo)
2015-02-21 18:09:57 -05:00
if err != nil {
return err
}
2015-03-14 07:30:47 -04:00
fmt.Printf("done\n")
2015-02-21 18:09:57 -05:00
return nil
}