Merge pull request #3728 from MichaelEischer/debug-examine-upload
Add support to reupload blobs in `debug examine`
This commit is contained in:
commit
fb5b9370f3
1 changed files with 29 additions and 7 deletions
|
@ -53,12 +53,14 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
|
||||||
var tryRepair bool
|
var tryRepair bool
|
||||||
var repairByte bool
|
var repairByte bool
|
||||||
var extractPack bool
|
var extractPack bool
|
||||||
|
var reuploadBlobs bool
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cmdRoot.AddCommand(cmdDebug)
|
cmdRoot.AddCommand(cmdDebug)
|
||||||
cmdDebug.AddCommand(cmdDebugDump)
|
cmdDebug.AddCommand(cmdDebugDump)
|
||||||
cmdDebug.AddCommand(cmdDebugExamine)
|
cmdDebug.AddCommand(cmdDebugExamine)
|
||||||
cmdDebugExamine.Flags().BoolVar(&extractPack, "extract-pack", false, "write blobs to the current directory")
|
cmdDebugExamine.Flags().BoolVar(&extractPack, "extract-pack", false, "write blobs to the current directory")
|
||||||
|
cmdDebugExamine.Flags().BoolVar(&reuploadBlobs, "reupload-blobs", false, "reupload blobs to the repository")
|
||||||
cmdDebugExamine.Flags().BoolVar(&tryRepair, "try-repair", false, "try to repair broken blobs with single bit flips")
|
cmdDebugExamine.Flags().BoolVar(&tryRepair, "try-repair", false, "try to repair broken blobs with single bit flips")
|
||||||
cmdDebugExamine.Flags().BoolVar(&repairByte, "repair-byte", false, "try to repair broken blobs by trying bytes")
|
cmdDebugExamine.Flags().BoolVar(&repairByte, "repair-byte", false, "try to repair broken blobs by trying bytes")
|
||||||
}
|
}
|
||||||
|
@ -383,6 +385,20 @@ func loadBlobs(ctx context.Context, repo restic.Repository, pack restic.ID, list
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if reuploadBlobs {
|
||||||
|
_, _, err := repo.SaveBlob(ctx, blob.Type, plaintext, id, true)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
Printf(" uploaded %v %v\n", blob.Type, id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if reuploadBlobs {
|
||||||
|
err := repo.Flush(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -411,12 +427,23 @@ func storePlainBlob(id restic.ID, prefix string, plain []byte) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func runDebugExamine(gopts GlobalOptions, args []string) error {
|
func runDebugExamine(gopts GlobalOptions, args []string) error {
|
||||||
|
repo, err := OpenRepository(gopts)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
ids := make([]restic.ID, 0)
|
ids := make([]restic.ID, 0)
|
||||||
for _, name := range args {
|
for _, name := range args {
|
||||||
id, err := restic.ParseID(name)
|
id, err := restic.ParseID(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Warnf("error: %v\n", err)
|
name, err = restic.Find(gopts.ctx, repo.Backend(), restic.PackFile, name)
|
||||||
continue
|
if err == nil {
|
||||||
|
id, err = restic.ParseID(name)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
Warnf("error: %v\n", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ids = append(ids, id)
|
ids = append(ids, id)
|
||||||
}
|
}
|
||||||
|
@ -425,11 +452,6 @@ func runDebugExamine(gopts GlobalOptions, args []string) error {
|
||||||
return errors.Fatal("no pack files to examine")
|
return errors.Fatal("no pack files to examine")
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := OpenRepository(gopts)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !gopts.NoLock {
|
if !gopts.NoLock {
|
||||||
lock, err := lockRepo(gopts.ctx, repo)
|
lock, err := lockRepo(gopts.ctx, repo)
|
||||||
defer unlockRepo(lock)
|
defer unlockRepo(lock)
|
||||||
|
|
Loading…
Reference in a new issue