fix: count
This commit is contained in:
parent
f43fae8c3d
commit
ed63ededf1
2
License
2
License
|
@ -1,6 +1,6 @@
|
||||||
---- Definitions ----
|
---- Definitions ----
|
||||||
license means right to use
|
license means right to use
|
||||||
author means who had initial idea, who research about jurisprudence and the who who started, in this case : Urko: Bein.
|
author means who had initial idea, who research about jurisprudence and who started, in this case : Urko: Bein.
|
||||||
contributors means every man who has helped to improve this software
|
contributors means every man who has helped to improve this software
|
||||||
|
|
||||||
|
|
||||||
|
|
22
cmd/check.go
22
cmd/check.go
|
@ -76,17 +76,17 @@ var Check = &cobra.Command{
|
||||||
go b.CompareConcurrent(ctx, backupDir, bucketName, msgChan)
|
go b.CompareConcurrent(ctx, backupDir, bucketName, msgChan)
|
||||||
|
|
||||||
reportBuilder := strings.Builder{}
|
reportBuilder := strings.Builder{}
|
||||||
countLocalFiles := 0
|
countLocal := 0
|
||||||
countOK := 0
|
countOK := 0
|
||||||
reportBuilder.WriteString(fmt.Sprintf("Local files within `%s` path already in `%s` bucket:\n", backupDir, bucketName))
|
reportBuilder.WriteString(fmt.Sprintf("Local files within `%s` path already in `%s` bucket:\n", backupDir, bucketName))
|
||||||
|
|
||||||
cloudBuilder := strings.Builder{}
|
cloudBuilder := strings.Builder{}
|
||||||
cloudBuilder.WriteString(fmt.Sprintf("List of B2 files within `%s` bucket not found in local path `%s`\n", bucketName, backupDir))
|
cloudBuilder.WriteString(fmt.Sprintf("List of B2 files within `%s` bucket not found in local path `%s`\n", bucketName, backupDir))
|
||||||
countNotInLocalBuffer := 0
|
countNotInLocal := 0
|
||||||
|
|
||||||
localBuilder := strings.Builder{}
|
localBuilder := strings.Builder{}
|
||||||
localBuilder.WriteString(fmt.Sprintf("List of local files in `%s` not found in B2 bucket `%s`\n", backupDir, bucketName))
|
localBuilder.WriteString(fmt.Sprintf("List of local files in `%s` not found in B2 bucket `%s`\n", backupDir, bucketName))
|
||||||
countNotInCloudBuffer := 0
|
countNotInCloud := 0
|
||||||
|
|
||||||
loop:
|
loop:
|
||||||
for {
|
for {
|
||||||
|
@ -102,19 +102,19 @@ var Check = &cobra.Command{
|
||||||
break loop
|
break loop
|
||||||
case msg := <-msgChan:
|
case msg := <-msgChan:
|
||||||
if msg.Err == nil && msg.File == "" {
|
if msg.Err == nil && msg.File == "" {
|
||||||
countLocalFiles = msg.LocalCount
|
countLocal = msg.LocalCount
|
||||||
break loop
|
break loop
|
||||||
}
|
}
|
||||||
if errors.Is(msg.Err, backblaze.ErrCloudNotInLocal) {
|
if errors.Is(msg.Err, backblaze.ErrCloudNotInLocal) {
|
||||||
logger.Debug(msg.File + ": B2 file not found in local")
|
logger.Debug(msg.File + ": B2 file not found in local")
|
||||||
cloudBuilder.WriteString(msg.File + "\n")
|
cloudBuilder.WriteString(msg.File + "\n")
|
||||||
countNotInLocalBuffer++
|
countNotInLocal++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if errors.Is(msg.Err, backblaze.ErrLocalNotInCloud) {
|
if errors.Is(msg.Err, backblaze.ErrLocalNotInCloud) {
|
||||||
logger.Debug(msg.File + ": local file not found in B2")
|
logger.Debug(msg.File + ": local file not found in B2")
|
||||||
localBuilder.WriteString(msg.File + "\n")
|
localBuilder.WriteString(msg.File + "\n")
|
||||||
countNotInCloudBuffer++
|
countNotInCloud++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
reportBuilder.WriteString(msg.File + " OK" + "\n")
|
reportBuilder.WriteString(msg.File + " OK" + "\n")
|
||||||
|
@ -122,11 +122,11 @@ var Check = &cobra.Command{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if countNotInCloudBuffer > 0 {
|
if countNotInCloud > 0 {
|
||||||
reportBuilder.WriteString("\n")
|
reportBuilder.WriteString("\n")
|
||||||
reportBuilder.WriteString(cloudBuilder.String())
|
reportBuilder.WriteString(cloudBuilder.String())
|
||||||
}
|
}
|
||||||
if countNotInLocalBuffer > 0 {
|
if countNotInLocal > 0 {
|
||||||
reportBuilder.WriteString("\n")
|
reportBuilder.WriteString("\n")
|
||||||
reportBuilder.WriteString(localBuilder.String())
|
reportBuilder.WriteString(localBuilder.String())
|
||||||
}
|
}
|
||||||
|
@ -135,10 +135,10 @@ var Check = &cobra.Command{
|
||||||
To: cfg.MailTo,
|
To: cfg.MailTo,
|
||||||
Bucket: bucketName,
|
Bucket: bucketName,
|
||||||
BackupDir: backupDir,
|
BackupDir: backupDir,
|
||||||
CountLocal: countNotInLocalBuffer,
|
CountNotInLocal: countNotInLocal,
|
||||||
CountCloud: countNotInCloudBuffer,
|
CountNotInCloud: countNotInCloud,
|
||||||
CountOK: countOK,
|
CountOK: countOK,
|
||||||
CountLocalFiles: countLocalFiles,
|
CountLocal: countLocal,
|
||||||
Attachments: []email.EmailAttachment{{File: bytes.NewReader([]byte(reportBuilder.String())), Title: fmt.Sprintf("%s-check-report.txt", bucketName)}},
|
Attachments: []email.EmailAttachment{{File: bytes.NewReader([]byte(reportBuilder.String())), Title: fmt.Sprintf("%s-check-report.txt", bucketName)}},
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
panic(fmt.Errorf("error while send email: %w", err))
|
panic(fmt.Errorf("error while send email: %w", err))
|
||||||
|
|
|
@ -32,10 +32,10 @@ type EmailWithAttachments struct {
|
||||||
To string
|
To string
|
||||||
Bucket string
|
Bucket string
|
||||||
BackupDir string
|
BackupDir string
|
||||||
CountLocal int
|
CountNotInLocal int
|
||||||
CountOK int
|
CountOK int
|
||||||
CountCloud int
|
CountNotInCloud int
|
||||||
CountLocalFiles int
|
CountLocal int
|
||||||
Attachments []EmailAttachment
|
Attachments []EmailAttachment
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,10 +75,10 @@ func NewMailService(config MailServiceConfig) *EmailService {
|
||||||
func (e *EmailService) SendOK(emailData EmailWithAttachments) error {
|
func (e *EmailService) SendOK(emailData EmailWithAttachments) error {
|
||||||
template := strings.Replace(htmlTemplate, "{{bucket}}", emailData.Bucket, -1)
|
template := strings.Replace(htmlTemplate, "{{bucket}}", emailData.Bucket, -1)
|
||||||
template = strings.Replace(template, "{{local_backup_path}}", emailData.BackupDir, -1)
|
template = strings.Replace(template, "{{local_backup_path}}", emailData.BackupDir, -1)
|
||||||
template = strings.Replace(template, "{{count_ErrCloudNotInLocal}}", fmt.Sprint(emailData.CountCloud), -1)
|
template = strings.Replace(template, "{{count_ErrCloudNotInLocal}}", fmt.Sprint(emailData.CountNotInLocal), -1)
|
||||||
template = strings.Replace(template, "{{count_ErrLocalNotInCloud}}", fmt.Sprint(emailData.CountLocal), -1)
|
template = strings.Replace(template, "{{count_ErrLocalNotInCloud}}", fmt.Sprint(emailData.CountNotInCloud), -1)
|
||||||
template = strings.Replace(template, "{{count_ok}}", fmt.Sprint(emailData.CountOK), -1)
|
template = strings.Replace(template, "{{count_ok}}", fmt.Sprint(emailData.CountOK), -1)
|
||||||
template = strings.Replace(template, "{{count_local}}", fmt.Sprint(emailData.CountLocalFiles), -1)
|
template = strings.Replace(template, "{{count_local}}", fmt.Sprint(emailData.CountLocal), -1)
|
||||||
|
|
||||||
msg, err := newMessage(e.from, emailData.To, subjectReport).
|
msg, err := newMessage(e.from, emailData.To, subjectReport).
|
||||||
withAttachments(template, emailData.Attachments)
|
withAttachments(template, emailData.Attachments)
|
||||||
|
|
Loading…
Reference in New Issue