mirror of
https://github.com/octoleo/restic.git
synced 2024-05-30 07:30:50 +00:00
c55b6ee544
This is a new error which implements the restic.Fataler interface. Errors of this type are written to stderr, the restic exits. For all other errors, restic prints the stack trace (if available).
53 lines
805 B
Go
53 lines
805 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"restic"
|
|
)
|
|
|
|
type CmdCache struct {
|
|
global *GlobalOptions
|
|
}
|
|
|
|
func init() {
|
|
_, err := parser.AddCommand("cache",
|
|
"manage cache",
|
|
"The cache command creates and manages the local cache",
|
|
&CmdCache{global: &globalOpts})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func (cmd CmdCache) Usage() string {
|
|
return "[update|clear]"
|
|
}
|
|
|
|
func (cmd CmdCache) Execute(args []string) error {
|
|
repo, err := cmd.global.OpenRepository()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
lock, err := lockRepo(repo)
|
|
defer unlockRepo(lock)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
cache, err := restic.NewCache(repo, cmd.global.CacheDir)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Printf("clear cache for old snapshots\n")
|
|
err = cache.Clear(repo)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Printf("done\n")
|
|
|
|
return nil
|
|
}
|