2017-10-12 20:14:48 +02:00
|
|
|
// +build debug
|
2015-05-16 14:24:24 +02:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-06-06 00:37:25 +02:00
|
|
|
"context"
|
2015-05-16 14:24:24 +02:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
2018-09-28 14:30:43 +02:00
|
|
|
"os"
|
2018-09-29 14:16:01 +02:00
|
|
|
"runtime"
|
2018-09-28 14:30:43 +02:00
|
|
|
"sort"
|
2018-09-29 14:16:01 +02:00
|
|
|
"time"
|
2015-05-16 14:24:24 +02:00
|
|
|
|
2016-09-17 12:36:05 +02:00
|
|
|
"github.com/spf13/cobra"
|
2018-09-29 14:16:01 +02:00
|
|
|
"golang.org/x/sync/errgroup"
|
2016-09-17 12:36:05 +02:00
|
|
|
|
2018-09-29 14:40:48 +02:00
|
|
|
"github.com/restic/restic/internal/backend"
|
2018-09-29 14:16:01 +02:00
|
|
|
"github.com/restic/restic/internal/crypto"
|
2017-07-23 14:21:03 +02:00
|
|
|
"github.com/restic/restic/internal/errors"
|
|
|
|
"github.com/restic/restic/internal/pack"
|
|
|
|
"github.com/restic/restic/internal/repository"
|
2017-07-24 17:42:25 +02:00
|
|
|
"github.com/restic/restic/internal/restic"
|
2015-05-16 14:24:24 +02:00
|
|
|
)
|
|
|
|
|
2017-10-12 20:18:45 +02:00
|
|
|
var cmdDebug = &cobra.Command{
|
|
|
|
Use: "debug",
|
|
|
|
Short: "Debug commands",
|
|
|
|
}
|
|
|
|
|
2017-10-14 13:55:00 +02:00
|
|
|
var cmdDebugDump = &cobra.Command{
|
2017-10-01 08:04:52 -07:00
|
|
|
Use: "dump [indexes|snapshots|all|packs]",
|
2017-09-11 09:32:44 -07:00
|
|
|
Short: "Dump data structures",
|
2016-09-17 12:36:05 +02:00
|
|
|
Long: `
|
2017-02-13 16:05:25 +01:00
|
|
|
The "dump" command dumps data structures from the repository as JSON objects. It
|
2019-11-04 22:03:38 -08:00
|
|
|
is used for debugging purposes only.
|
|
|
|
|
|
|
|
EXIT STATUS
|
|
|
|
===========
|
|
|
|
|
|
|
|
Exit status is 0 if the command was successful, and non-zero if there was any error.
|
|
|
|
`,
|
2017-08-06 21:02:16 +02:00
|
|
|
DisableAutoGenTag: true,
|
2016-09-17 12:36:05 +02:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2017-10-14 13:55:00 +02:00
|
|
|
return runDebugDump(globalOptions, args)
|
2016-09-17 12:36:05 +02:00
|
|
|
},
|
2015-06-21 13:02:56 +02:00
|
|
|
}
|
2015-05-16 14:24:24 +02:00
|
|
|
|
2018-09-29 14:16:01 +02:00
|
|
|
var tryRepair bool
|
2018-09-29 18:28:39 +02:00
|
|
|
var repairByte bool
|
2018-09-29 14:16:01 +02:00
|
|
|
|
2015-05-16 14:24:24 +02:00
|
|
|
func init() {
|
2017-10-12 20:18:45 +02:00
|
|
|
cmdRoot.AddCommand(cmdDebug)
|
2017-10-14 13:55:00 +02:00
|
|
|
cmdDebug.AddCommand(cmdDebugDump)
|
2018-09-28 14:30:43 +02:00
|
|
|
cmdDebug.AddCommand(cmdDebugExamine)
|
2018-09-29 14:16:01 +02:00
|
|
|
cmdDebugExamine.Flags().BoolVar(&tryRepair, "try-repair", false, "try to repair broken blobs with single bit flips")
|
2018-09-29 18:28:39 +02:00
|
|
|
cmdDebugExamine.Flags().BoolVar(&repairByte, "repair-byte", false, "try to repair broken blobs by trying bytes")
|
2015-05-16 14:24:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func prettyPrintJSON(wr io.Writer, item interface{}) error {
|
|
|
|
buf, err := json.MarshalIndent(item, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = wr.Write(append(buf, '\n'))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-04-10 11:34:37 +02:00
|
|
|
func debugPrintSnapshots(ctx context.Context, repo *repository.Repository, wr io.Writer) error {
|
2020-11-28 08:59:12 +01:00
|
|
|
return restic.ForAllSnapshots(ctx, repo, nil, func(id restic.ID, snapshot *restic.Snapshot, err error) error {
|
2015-05-16 14:24:24 +02:00
|
|
|
if err != nil {
|
2018-01-21 17:25:36 +01:00
|
|
|
return err
|
2015-05-16 14:24:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(wr, "snapshot_id: %v\n", id)
|
|
|
|
|
2018-01-21 17:25:36 +01:00
|
|
|
return prettyPrintJSON(wr, snapshot)
|
|
|
|
})
|
2015-05-16 14:24:24 +02:00
|
|
|
}
|
|
|
|
|
2016-02-04 19:37:48 +01:00
|
|
|
// Pack is the struct used in printPacks.
|
|
|
|
type Pack struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
|
|
|
Blobs []Blob `json:"blobs"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Blob is the struct used in printPacks.
|
|
|
|
type Blob struct {
|
2016-09-01 16:04:29 +02:00
|
|
|
Type restic.BlobType `json:"type"`
|
|
|
|
Length uint `json:"length"`
|
|
|
|
ID restic.ID `json:"id"`
|
|
|
|
Offset uint `json:"offset"`
|
2016-02-04 19:37:48 +01:00
|
|
|
}
|
|
|
|
|
2020-04-10 11:34:37 +02:00
|
|
|
func printPacks(ctx context.Context, repo *repository.Repository, wr io.Writer) error {
|
2016-02-04 19:37:48 +01:00
|
|
|
|
2020-04-10 11:34:37 +02:00
|
|
|
return repo.List(ctx, restic.PackFile, func(id restic.ID, size int64) error {
|
2020-08-16 11:16:38 +02:00
|
|
|
h := restic.Handle{Type: restic.PackFile, Name: id.String()}
|
2016-02-04 19:37:48 +01:00
|
|
|
|
2020-11-29 18:44:36 +01:00
|
|
|
blobs, _, err := pack.List(repo.Key(), restic.ReaderAt(ctx, repo.Backend(), h), size)
|
2016-02-04 19:37:48 +01:00
|
|
|
if err != nil {
|
2020-04-04 19:41:24 +02:00
|
|
|
Warnf("error for pack %v: %v\n", id.Str(), err)
|
2018-01-21 17:25:36 +01:00
|
|
|
return nil
|
2016-02-04 19:37:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
p := Pack{
|
2018-01-21 17:25:36 +01:00
|
|
|
Name: id.String(),
|
|
|
|
Blobs: make([]Blob, len(blobs)),
|
2016-02-04 19:37:48 +01:00
|
|
|
}
|
2018-01-21 17:25:36 +01:00
|
|
|
for i, blob := range blobs {
|
2016-02-04 19:37:48 +01:00
|
|
|
p.Blobs[i] = Blob{
|
|
|
|
Type: blob.Type,
|
|
|
|
Length: blob.Length,
|
|
|
|
ID: blob.ID,
|
|
|
|
Offset: blob.Offset,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-02 22:45:20 +02:00
|
|
|
return prettyPrintJSON(wr, p)
|
2018-01-21 17:25:36 +01:00
|
|
|
})
|
2016-02-04 19:37:48 +01:00
|
|
|
}
|
|
|
|
|
2020-04-10 11:34:37 +02:00
|
|
|
func dumpIndexes(ctx context.Context, repo restic.Repository, wr io.Writer) error {
|
2020-11-07 18:19:25 +01:00
|
|
|
return repository.ForAllIndexes(ctx, repo, func(id restic.ID, idx *repository.Index, oldFormat bool, err error) error {
|
2020-04-04 19:41:24 +02:00
|
|
|
Printf("index_id: %v\n", id)
|
2015-08-08 17:04:06 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-04-02 22:45:20 +02:00
|
|
|
return idx.Dump(wr)
|
2018-01-21 17:25:36 +01:00
|
|
|
})
|
2015-08-08 17:04:06 +02:00
|
|
|
}
|
|
|
|
|
2017-10-14 13:55:00 +02:00
|
|
|
func runDebugDump(gopts GlobalOptions, args []string) error {
|
2015-05-16 14:24:24 +02:00
|
|
|
if len(args) != 1 {
|
2017-02-10 19:39:49 +01:00
|
|
|
return errors.Fatal("type not specified")
|
2015-05-16 14:24:24 +02:00
|
|
|
}
|
|
|
|
|
2016-09-17 12:36:05 +02:00
|
|
|
repo, err := OpenRepository(gopts)
|
2015-05-16 14:24:24 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-09-17 12:36:05 +02:00
|
|
|
if !gopts.NoLock {
|
2020-08-09 13:24:47 +02:00
|
|
|
lock, err := lockRepo(gopts.ctx, repo)
|
2016-09-17 12:36:05 +02:00
|
|
|
defer unlockRepo(lock)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-06-27 14:40:18 +02:00
|
|
|
}
|
|
|
|
|
2015-05-16 14:24:24 +02:00
|
|
|
tpe := args[0]
|
|
|
|
|
|
|
|
switch tpe {
|
2015-08-08 17:04:06 +02:00
|
|
|
case "indexes":
|
2020-04-10 11:34:37 +02:00
|
|
|
return dumpIndexes(gopts.ctx, repo, gopts.stdout)
|
2015-05-16 14:24:24 +02:00
|
|
|
case "snapshots":
|
2020-04-10 11:34:37 +02:00
|
|
|
return debugPrintSnapshots(gopts.ctx, repo, gopts.stdout)
|
2016-02-04 19:37:48 +01:00
|
|
|
case "packs":
|
2020-04-10 11:34:37 +02:00
|
|
|
return printPacks(gopts.ctx, repo, gopts.stdout)
|
2015-05-16 14:24:24 +02:00
|
|
|
case "all":
|
2020-04-04 19:41:24 +02:00
|
|
|
Printf("snapshots:\n")
|
2020-04-10 11:34:37 +02:00
|
|
|
err := debugPrintSnapshots(gopts.ctx, repo, gopts.stdout)
|
2015-05-16 14:24:24 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-04-04 19:41:24 +02:00
|
|
|
Printf("\nindexes:\n")
|
2020-04-10 11:34:37 +02:00
|
|
|
err = dumpIndexes(gopts.ctx, repo, gopts.stdout)
|
2015-08-08 17:04:06 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-05-16 14:24:24 +02:00
|
|
|
return nil
|
|
|
|
default:
|
2016-09-01 22:17:37 +02:00
|
|
|
return errors.Fatalf("no such type %q", tpe)
|
2015-05-16 14:24:24 +02:00
|
|
|
}
|
|
|
|
}
|
2018-09-28 14:30:43 +02:00
|
|
|
|
|
|
|
var cmdDebugExamine = &cobra.Command{
|
|
|
|
Use: "examine",
|
|
|
|
Short: "Examine a pack file",
|
|
|
|
DisableAutoGenTag: true,
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return runDebugExamine(globalOptions, args)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-09-29 18:28:39 +02:00
|
|
|
func tryRepairWithBitflip(ctx context.Context, key *crypto.Key, input []byte, bytewise bool) {
|
|
|
|
if bytewise {
|
|
|
|
fmt.Printf(" trying to repair blob by finding a broken byte\n")
|
|
|
|
} else {
|
|
|
|
fmt.Printf(" trying to repair blob with single bit flip\n")
|
|
|
|
}
|
2018-09-29 14:16:01 +02:00
|
|
|
|
|
|
|
ch := make(chan int)
|
|
|
|
var wg errgroup.Group
|
|
|
|
done := make(chan struct{})
|
|
|
|
|
|
|
|
fmt.Printf(" spinning up %d worker functions\n", runtime.NumCPU())
|
|
|
|
for i := 0; i < runtime.NumCPU(); i++ {
|
|
|
|
wg.Go(func() error {
|
|
|
|
// make a local copy of the buffer
|
|
|
|
buf := make([]byte, len(input))
|
|
|
|
copy(buf, input)
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
return nil
|
|
|
|
case i := <-ch:
|
2018-09-29 18:28:39 +02:00
|
|
|
if bytewise {
|
|
|
|
for j := 0; j < 255; j++ {
|
|
|
|
// flip bits
|
|
|
|
buf[i] ^= byte(j)
|
|
|
|
|
|
|
|
nonce, plaintext := buf[:key.NonceSize()], buf[key.NonceSize():]
|
|
|
|
plaintext, err := key.Open(plaintext[:0], nonce, plaintext, nil)
|
|
|
|
if err == nil {
|
|
|
|
fmt.Printf("\n")
|
|
|
|
fmt.Printf(" blob could be repaired by XORing byte %v with 0x%02x\n", i, j)
|
|
|
|
fmt.Printf(" hash is %v\n", restic.Hash(plaintext))
|
|
|
|
close(done)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// flip bits back
|
|
|
|
buf[i] ^= byte(j)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for j := 0; j < 7; j++ {
|
|
|
|
// flip bit
|
|
|
|
buf[i] ^= (1 << uint(j))
|
|
|
|
|
|
|
|
nonce, plaintext := buf[:key.NonceSize()], buf[key.NonceSize():]
|
|
|
|
plaintext, err := key.Open(plaintext[:0], nonce, plaintext, nil)
|
|
|
|
if err == nil {
|
|
|
|
fmt.Printf("\n")
|
|
|
|
fmt.Printf(" blob could be repaired by flipping bit %v in byte %v\n", j, i)
|
|
|
|
fmt.Printf(" hash is %v\n", restic.Hash(plaintext))
|
|
|
|
close(done)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// flip bit back
|
|
|
|
buf[i] ^= (1 << uint(j))
|
2018-09-29 14:16:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
start := time.Now()
|
|
|
|
info := time.Now()
|
|
|
|
outer:
|
|
|
|
for i := range input {
|
|
|
|
select {
|
|
|
|
case ch <- i:
|
|
|
|
case <-done:
|
|
|
|
fmt.Printf(" done after %v\n", time.Since(start))
|
|
|
|
break outer
|
|
|
|
}
|
|
|
|
|
|
|
|
if time.Since(info) > time.Second {
|
|
|
|
secs := time.Since(start).Seconds()
|
|
|
|
gps := float64(i) / secs
|
|
|
|
remaining := len(input) - i
|
|
|
|
eta := time.Duration(float64(remaining)/gps) * time.Second
|
|
|
|
|
2018-09-29 18:28:39 +02:00
|
|
|
fmt.Printf("\r%d byte of %d done (%.2f%%), %.0f byte per second, ETA %v",
|
2018-09-29 14:42:19 +02:00
|
|
|
i, len(input), float32(i)/float32(len(input)*100),
|
2018-09-29 14:16:01 +02:00
|
|
|
gps, eta)
|
|
|
|
info = time.Now()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var found bool
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
found = true
|
|
|
|
default:
|
|
|
|
close(done)
|
|
|
|
}
|
|
|
|
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
if !found {
|
|
|
|
fmt.Printf("\n blob could not be repaired by single bit flip\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func loadBlobs(ctx context.Context, repo restic.Repository, pack string, list []restic.Blob) error {
|
2018-09-28 14:30:43 +02:00
|
|
|
be := repo.Backend()
|
|
|
|
for _, blob := range list {
|
|
|
|
fmt.Printf(" loading blob %v at %v (length %v)\n", blob.ID, blob.Offset, blob.Length)
|
|
|
|
buf := make([]byte, blob.Length)
|
|
|
|
h := restic.Handle{
|
|
|
|
Name: pack,
|
|
|
|
Type: restic.PackFile,
|
|
|
|
}
|
|
|
|
err := be.Load(ctx, h, int(blob.Length), int64(blob.Offset), func(rd io.Reader) error {
|
|
|
|
n, err := io.ReadFull(rd, buf)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "read error after %d bytes: %v\n", n, err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "error read: %v\n", err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
key := repo.Key()
|
|
|
|
|
2018-09-29 14:16:01 +02:00
|
|
|
nonce, plaintext := buf[:key.NonceSize()], buf[key.NonceSize():]
|
|
|
|
plaintext, err = key.Open(plaintext[:0], nonce, plaintext, nil)
|
2018-09-28 14:30:43 +02:00
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "error decrypting blob: %v\n", err)
|
2018-09-29 18:28:39 +02:00
|
|
|
if tryRepair || repairByte {
|
|
|
|
tryRepairWithBitflip(ctx, key, buf, repairByte)
|
2018-09-29 14:16:01 +02:00
|
|
|
}
|
2018-09-28 14:30:43 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-09-29 14:16:01 +02:00
|
|
|
id := restic.Hash(plaintext)
|
2018-09-28 14:30:43 +02:00
|
|
|
if !id.Equal(blob.ID) {
|
2018-09-29 14:20:53 +02:00
|
|
|
fmt.Printf(" successfully decrypted blob (length %v), hash is %v, ID does not match, wanted %v\n", len(plaintext), id, blob.ID)
|
2018-09-28 14:30:43 +02:00
|
|
|
} else {
|
2018-09-29 14:20:53 +02:00
|
|
|
fmt.Printf(" successfully decrypted blob (length %v), hash is %v, ID matches\n", len(plaintext), id)
|
2018-09-28 14:30:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func runDebugExamine(gopts GlobalOptions, args []string) error {
|
|
|
|
repo, err := OpenRepository(gopts)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if !gopts.NoLock {
|
|
|
|
lock, err := lockRepo(gopts.ctx, repo)
|
|
|
|
defer unlockRepo(lock)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err = repo.LoadIndex(gopts.ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-09-29 14:16:01 +02:00
|
|
|
blobsLoaded := false
|
2018-09-28 14:30:43 +02:00
|
|
|
for _, name := range args {
|
|
|
|
fmt.Printf("examine %v\n", name)
|
|
|
|
id, err := restic.ParseID(name)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
h := restic.Handle{
|
|
|
|
Type: restic.PackFile,
|
|
|
|
Name: name,
|
|
|
|
}
|
|
|
|
fi, err := repo.Backend().Stat(gopts.ctx, h)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf(" file size is %v\n", fi.Size)
|
2018-09-29 14:40:48 +02:00
|
|
|
|
|
|
|
buf, err := backend.LoadAll(gopts.ctx, nil, repo.Backend(), h)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
gotID := restic.Hash(buf)
|
|
|
|
if !id.Equal(gotID) {
|
|
|
|
fmt.Printf(" wanted hash %v, got %v\n", id, gotID)
|
|
|
|
} else {
|
|
|
|
fmt.Printf(" hash for file content matches\n")
|
|
|
|
}
|
|
|
|
|
2018-09-29 14:16:01 +02:00
|
|
|
fmt.Printf(" ========================================\n")
|
|
|
|
fmt.Printf(" looking for info in the indexes\n")
|
2018-09-28 14:30:43 +02:00
|
|
|
|
|
|
|
// examine all data the indexes have for the pack file
|
|
|
|
for _, idx := range repo.Index().(*repository.MasterIndex).All() {
|
|
|
|
idxIDs, err := idx.IDs()
|
|
|
|
if err != nil {
|
|
|
|
idxIDs = restic.IDs{}
|
|
|
|
}
|
|
|
|
|
|
|
|
blobs := idx.ListPack(id)
|
|
|
|
if len(blobs) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf(" index %v:\n", idxIDs)
|
|
|
|
|
|
|
|
// track current size and offset
|
|
|
|
var size, offset uint64
|
|
|
|
|
|
|
|
sort.Slice(blobs, func(i, j int) bool {
|
|
|
|
return blobs[i].Offset < blobs[j].Offset
|
|
|
|
})
|
|
|
|
|
|
|
|
for _, pb := range blobs {
|
|
|
|
fmt.Printf(" %v blob %v, offset %-6d, raw length %-6d\n", pb.Type, pb.ID, pb.Offset, pb.Length)
|
|
|
|
if offset != uint64(pb.Offset) {
|
|
|
|
fmt.Printf(" hole in file, want offset %v, got %v\n", offset, pb.Offset)
|
|
|
|
}
|
|
|
|
offset += uint64(pb.Length)
|
|
|
|
size += uint64(pb.Length)
|
|
|
|
}
|
|
|
|
|
|
|
|
// compute header size, per blob: 1 byte type, 4 byte length, 32 byte id
|
|
|
|
size += uint64(restic.CiphertextLength(len(blobs) * (1 + 4 + 32)))
|
|
|
|
// length in uint32 little endian
|
|
|
|
size += 4
|
|
|
|
|
|
|
|
if uint64(fi.Size) != size {
|
|
|
|
fmt.Printf(" file sizes do not match: computed %v from index, file size is %v\n", size, fi.Size)
|
|
|
|
} else {
|
|
|
|
fmt.Printf(" file sizes match\n")
|
|
|
|
}
|
|
|
|
|
2018-09-29 14:16:01 +02:00
|
|
|
// convert list of blobs to []restic.Blob
|
|
|
|
var list []restic.Blob
|
|
|
|
for _, b := range blobs {
|
|
|
|
list = append(list, b.Blob)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = loadBlobs(gopts.ctx, repo, name, list)
|
2018-09-28 14:30:43 +02:00
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
2018-09-29 14:16:01 +02:00
|
|
|
} else {
|
|
|
|
blobsLoaded = true
|
2018-09-28 14:30:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-29 14:16:01 +02:00
|
|
|
fmt.Printf(" ========================================\n")
|
|
|
|
fmt.Printf(" inspect the pack itself\n")
|
|
|
|
|
2018-09-28 14:30:43 +02:00
|
|
|
blobs, _, err := pack.List(repo.Key(), restic.ReaderAt(gopts.ctx, repo.Backend(), h), fi.Size)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "error for pack %v: %v\n", id.Str(), err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// track current size and offset
|
|
|
|
var size, offset uint64
|
|
|
|
|
|
|
|
sort.Slice(blobs, func(i, j int) bool {
|
|
|
|
return blobs[i].Offset < blobs[j].Offset
|
|
|
|
})
|
|
|
|
|
|
|
|
for _, pb := range blobs {
|
|
|
|
fmt.Printf(" %v blob %v, offset %-6d, raw length %-6d\n", pb.Type, pb.ID, pb.Offset, pb.Length)
|
|
|
|
if offset != uint64(pb.Offset) {
|
|
|
|
fmt.Printf(" hole in file, want offset %v, got %v\n", offset, pb.Offset)
|
|
|
|
}
|
|
|
|
offset += uint64(pb.Length)
|
|
|
|
size += uint64(pb.Length)
|
|
|
|
}
|
|
|
|
|
|
|
|
// compute header size, per blob: 1 byte type, 4 byte length, 32 byte id
|
|
|
|
size += uint64(restic.CiphertextLength(len(blobs) * (1 + 4 + 32)))
|
|
|
|
// length in uint32 little endian
|
|
|
|
size += 4
|
|
|
|
|
|
|
|
if uint64(fi.Size) != size {
|
|
|
|
fmt.Printf(" file sizes do not match: computed %v from index, file size is %v\n", size, fi.Size)
|
|
|
|
} else {
|
|
|
|
fmt.Printf(" file sizes match\n")
|
|
|
|
}
|
2018-09-29 14:16:01 +02:00
|
|
|
|
|
|
|
if !blobsLoaded {
|
|
|
|
err = loadBlobs(gopts.ctx, repo, name, blobs)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
|
|
|
}
|
|
|
|
}
|
2018-09-28 14:30:43 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|