forked from TrueCloudLab/restic
check: removing orphaned packs is handled in 'optimize'
This commit is contained in:
parent
c4fc7b52ae
commit
43e2c9837e
1 changed files with 2 additions and 22 deletions
|
@ -5,14 +5,12 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/restic/restic/backend"
|
|
||||||
"github.com/restic/restic/checker"
|
"github.com/restic/restic/checker"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CmdCheck struct {
|
type CmdCheck struct {
|
||||||
ReadData bool `long:"read-data" description:"Read data blobs" default:"false"`
|
ReadData bool `long:"read-data" description:"Read data blobs" default:"false"`
|
||||||
RemoveOrphaned bool `long:"remove" description:"Remove data that isn't used" default:"false"`
|
CheckUnused bool `long:"check-unused" description:"Check for unused blobs" default:"false"`
|
||||||
CheckUnused bool `long:"check-unused" description:"Check for unused blobs" default:"false"`
|
|
||||||
|
|
||||||
global *GlobalOptions
|
global *GlobalOptions
|
||||||
}
|
}
|
||||||
|
@ -81,14 +79,9 @@ func (cmd CmdCheck) Execute(args []string) error {
|
||||||
cmd.global.Verbosef("Check all packs\n")
|
cmd.global.Verbosef("Check all packs\n")
|
||||||
go chkr.Packs(errChan, done)
|
go chkr.Packs(errChan, done)
|
||||||
|
|
||||||
foundOrphanedPacks := false
|
|
||||||
for err := range errChan {
|
for err := range errChan {
|
||||||
errorsFound = true
|
errorsFound = true
|
||||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||||
|
|
||||||
if e, ok := err.(checker.PackError); ok && e.Orphaned {
|
|
||||||
foundOrphanedPacks = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.global.Verbosef("Check snapshots, trees and blobs\n")
|
cmd.global.Verbosef("Check snapshots, trees and blobs\n")
|
||||||
|
@ -114,19 +107,6 @@ func (cmd CmdCheck) Execute(args []string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if foundOrphanedPacks && cmd.RemoveOrphaned {
|
|
||||||
IDs := chkr.OrphanedPacks()
|
|
||||||
cmd.global.Verbosef("Remove %d orphaned packs... ", len(IDs))
|
|
||||||
|
|
||||||
for _, id := range IDs {
|
|
||||||
if err := repo.Backend().Remove(backend.Data, id.String()); err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.global.Verbosef("done\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
if errorsFound {
|
if errorsFound {
|
||||||
return errors.New("repository contains errors")
|
return errors.New("repository contains errors")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue