fix: check report bug

This commit is contained in:
Urko 2023-08-29 11:40:07 +02:00
parent ed63ededf1
commit ecc3d7fa64
5 changed files with 23 additions and 19 deletions

View File

@ -122,11 +122,11 @@ var Check = &cobra.Command{
} }
} }
if countNotInCloud > 0 { if countNotInLocal > 0 {
reportBuilder.WriteString("\n") reportBuilder.WriteString("\n")
reportBuilder.WriteString(cloudBuilder.String()) reportBuilder.WriteString(cloudBuilder.String())
} }
if countNotInLocal > 0 { if countNotInCloud > 0 {
reportBuilder.WriteString("\n") reportBuilder.WriteString("\n")
reportBuilder.WriteString(localBuilder.String()) reportBuilder.WriteString(localBuilder.String())
} }

View File

@ -5,6 +5,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io/fs" "io/fs"
"path"
"path/filepath" "path/filepath"
"sync" "sync"
@ -56,8 +57,10 @@ func (b *BackBlaze) b2BucketFiles(ctx context.Context, bucketName string, fileCh
if bucketIter.Object() == nil { if bucketIter.Object() == nil {
return errors.New("bucketIter Object is nil") return errors.New("bucketIter Object is nil")
} }
b.logger.Debug("bucket file: ", bucketIter.Object().Name())
fileChan <- bucketIter.Object().Name() // Retrieve just filename
b.logger.Debugln("bucket file: ", path.Base(bucketIter.Object().Name()))
fileChan <- path.Base(bucketIter.Object().Name())
} }
return nil return nil
@ -93,7 +96,7 @@ func (b *BackBlaze) CompareConcurrent(ctx context.Context, backupDir, bucketName
if _, ok := localFiles[f]; ok { if _, ok := localFiles[f]; ok {
panic(fmt.Errorf("local file already exists in map: %s", f)) panic(fmt.Errorf("local file already exists in map: %s", f))
} }
b.logger.Debug("local file ", f) b.logger.Debugln("local file ", f)
localFiles[f]++ localFiles[f]++
} }
}() }()
@ -114,7 +117,7 @@ func (b *BackBlaze) CompareConcurrent(ctx context.Context, backupDir, bucketName
if _, ok := cloudFiles[f]; ok { if _, ok := cloudFiles[f]; ok {
panic(fmt.Errorf("cloud file already exists in map: %s", f)) panic(fmt.Errorf("cloud file already exists in map: %s", f))
} }
b.logger.Debug("B2 file ", f) b.logger.Debugln("B2 file ", f)
cloudFiles[f]++ cloudFiles[f]++
} }
}() }()
@ -143,6 +146,7 @@ func (b *BackBlaze) CompareConcurrent(ctx context.Context, backupDir, bucketName
go func() { go func() {
defer wg.Done() defer wg.Done()
for cloudFile := range cloudFiles { for cloudFile := range cloudFiles {
b.logger.Debugln("cloudFile ", cloudFile)
if _, exists := localFiles[cloudFile]; !exists { if _, exists := localFiles[cloudFile]; !exists {
msgChan <- B2Local{File: cloudFile, Err: ErrCloudNotInLocal} msgChan <- B2Local{File: cloudFile, Err: ErrCloudNotInLocal}
} }

View File

@ -34,7 +34,7 @@ func (b *BackBlaze) CleanUp(ctx context.Context, cancel context.CancelFunc, buck
smpl.Set("account", b.bbID) smpl.Set("account", b.bbID)
smpl.Set("key", b.bbKey) smpl.Set("key", b.bbKey)
smpl.Set("chunk_size", strconv.FormatInt(int64(9600), 10)) smpl.Set("chunk_size", strconv.FormatInt(int64(9600), 10))
b.logger.Info("duplicates", len(dups)) b.logger.Infoln("duplicates", len(dups))
for _, d := range dups { for _, d := range dups {
f, err := b2.NewFs(ctx, "B2", d.dir(), smpl) f, err := b2.NewFs(ctx, "B2", d.dir(), smpl)
if err != nil { if err != nil {
@ -43,7 +43,7 @@ func (b *BackBlaze) CleanUp(ctx context.Context, cancel context.CancelFunc, buck
if err := operations.CleanUp(ctx, f); err != nil { if err := operations.CleanUp(ctx, f); err != nil {
return fmt.Errorf("operations.CleanUp %w", err) return fmt.Errorf("operations.CleanUp %w", err)
} }
b.logger.Info(d.dir(), "cleaned up") b.logger.Infoln(d.dir(), "cleaned up")
} }
return nil return nil

View File

@ -72,20 +72,20 @@ func (b *BackBlaze) listDuplicates(ctx context.Context, cancel context.CancelFun
bucketIter := bc.List(ctx, b2.ListHidden()) bucketIter := bc.List(ctx, b2.ListHidden())
if bucketIter == nil { if bucketIter == nil {
b.logger.Error("bucket list cannot be nil") b.logger.Errorln("bucket list cannot be nil")
return return
} }
for { for {
if !bucketIter.Next() { if !bucketIter.Next() {
if bucketIter.Err() != nil { if bucketIter.Err() != nil {
b.logger.Error("bucketIter err %w", bucketIter.Err()) b.logger.Errorf("bucketIter err %s", bucketIter.Err())
return return
} }
break break
} }
if bucketIter.Object() == nil { if bucketIter.Object() == nil {
b.logger.Error("bucketIter Object is nil") b.logger.Errorln("bucketIter Object is nil")
continue continue
} }
files[bucketIter.Object().Name()]++ files[bucketIter.Object().Name()]++

View File

@ -50,9 +50,9 @@ func (b *BackBlaze) Sync(ctx context.Context) error {
if err != nil { if err != nil {
return fmt.Errorf("bucketFiles %w", err) return fmt.Errorf("bucketFiles %w", err)
} }
b.logger.Debug(strings.Repeat("*", 40)) b.logger.Debugln(strings.Repeat("*", 40))
b.logger.Debug("oldFiles to clean:\n\t\t" + strings.Join(oldFiles, "\n\t\t")) b.logger.Debugln("oldFiles to clean:\n\t\t" + strings.Join(oldFiles, "\n\t\t"))
b.logger.Debug(strings.Repeat("*", 40)) b.logger.Debugln(strings.Repeat("*", 40))
fileChan := make(chan string) fileChan := make(chan string)
@ -95,7 +95,7 @@ func (b *BackBlaze) Sync(ctx context.Context) error {
} }
} }
b.logger.Info("copied successfully") b.logger.Infoln("copied successfully")
return nil return nil
} }
@ -112,7 +112,7 @@ func (b *BackBlaze) copyFile(ctx context.Context, bucket *b2.Bucket, src string)
w := bucket.Object(fi.Name()).NewWriter(ctx) w := bucket.Object(fi.Name()).NewWriter(ctx)
w.ConcurrentUploads = writers w.ConcurrentUploads = writers
w.UseFileBuffer = true w.UseFileBuffer = true
b.logger.Info("start copying", fi.Name()) b.logger.Infoln("start copying ", fi.Name())
if _, err := io.Copy(w, f); err != nil { if _, err := io.Copy(w, f); err != nil {
w.Close() w.Close()
return err return err
@ -121,7 +121,7 @@ func (b *BackBlaze) copyFile(ctx context.Context, bucket *b2.Bucket, src string)
return err return err
} }
b.logger.Info("end copying", fi.Name()) b.logger.Infoln("end copying ", fi.Name())
return nil return nil
} }
@ -130,7 +130,7 @@ func (b *BackBlaze) cleanBucket(ctx context.Context, bucket *b2.Bucket, files []
for _, v := range files { for _, v := range files {
obj := bucket.Object(v) obj := bucket.Object(v)
if obj == nil { if obj == nil {
b.logger.Error("bucket.Object is nil", v) b.logger.Errorln("bucket.Object is nil", v)
continue continue
} }
if err := obj.Delete(ctx); err != nil { if err := obj.Delete(ctx); err != nil {
@ -160,7 +160,7 @@ func (b *BackBlaze) bucketFiles(ctx context.Context, bucket *b2.Bucket) ([]strin
break break
} }
if bucketIter.Object() == nil { if bucketIter.Object() == nil {
b.logger.Error("bucketIter Object is nil") b.logger.Errorln("bucketIter Object is nil")
continue continue
} }
files = append(files, bucketIter.Object().Name()) files = append(files, bucketIter.Object().Name())