From c89411cfa6aff510aca669da2724486d87f372f0 Mon Sep 17 00:00:00 2001 From: Jonas Kaninda Date: Tue, 10 Dec 2024 09:58:39 +0100 Subject: [PATCH 1/2] chore: add convert backup size from bytes to Mib --- pkg/azure.go | 2 +- pkg/backup.go | 2 +- pkg/remote.go | 4 ++-- pkg/s3.go | 2 +- templates/email-error.tmpl | 2 +- templates/email.tmpl | 2 +- templates/telegram.tmpl | 2 +- utils/config.go | 2 +- utils/utils.go | 4 ++++ 9 files changed, 13 insertions(+), 9 deletions(-) diff --git a/pkg/azure.go b/pkg/azure.go index da014ed..9df74ba 100644 --- a/pkg/azure.go +++ b/pkg/azure.go @@ -63,7 +63,7 @@ func azureBackup(db *dbConfig, config *BackupConfig) { // Send notification utils.NotifySuccess(&utils.NotificationData{ File: finalFileName, - BackupSize: backupSize, + BackupSize: utils.BytesToMb(uint64(backupSize)), Database: db.dbName, Storage: config.storage, BackupLocation: filepath.Join(config.remotePath, finalFileName), diff --git a/pkg/backup.go b/pkg/backup.go index 2f49de6..78b788f 100644 --- a/pkg/backup.go +++ b/pkg/backup.go @@ -290,7 +290,7 @@ func localBackup(db *dbConfig, config *BackupConfig) { // Send notification utils.NotifySuccess(&utils.NotificationData{ File: finalFileName, - BackupSize: backupSize, + BackupSize: utils.BytesToMb(uint64(backupSize)), Database: db.dbName, Storage: config.storage, BackupLocation: filepath.Join(storagePath, finalFileName), diff --git a/pkg/remote.go b/pkg/remote.go index a70be3e..b668413 100644 --- a/pkg/remote.go +++ b/pkg/remote.go @@ -92,7 +92,7 @@ func sshBackup(db *dbConfig, config *BackupConfig) { // Send notification utils.NotifySuccess(&utils.NotificationData{ File: finalFileName, - BackupSize: backupSize, + BackupSize: utils.BytesToMb(uint64(backupSize)), Database: db.dbName, Storage: config.storage, BackupLocation: filepath.Join(config.remotePath, finalFileName), @@ -204,7 +204,7 @@ func ftpBackup(db *dbConfig, config *BackupConfig) { // Send notification utils.NotifySuccess(&utils.NotificationData{ File: finalFileName, - BackupSize: backupSize, + BackupSize: utils.BytesToMb(uint64(backupSize)), Database: db.dbName, Storage: config.storage, BackupLocation: filepath.Join(config.remotePath, finalFileName), diff --git a/pkg/s3.go b/pkg/s3.go index 8a33841..9a5c6da 100644 --- a/pkg/s3.go +++ b/pkg/s3.go @@ -93,7 +93,7 @@ func s3Backup(db *dbConfig, config *BackupConfig) { // Send notification utils.NotifySuccess(&utils.NotificationData{ File: finalFileName, - BackupSize: backupSize, + BackupSize: utils.BytesToMb(uint64(backupSize)), Database: db.dbName, Storage: config.storage, BackupLocation: filepath.Join(config.remotePath, finalFileName), diff --git a/templates/email-error.tmpl b/templates/email-error.tmpl index 6325baf..cf81816 100644 --- a/templates/email-error.tmpl +++ b/templates/email-error.tmpl @@ -52,9 +52,9 @@

Failure Details:

diff --git a/templates/email.tmpl b/templates/email.tmpl index c100668..66f6733 100644 --- a/templates/email.tmpl +++ b/templates/email.tmpl @@ -56,7 +56,7 @@
  • Backup End Time: {{.EndTime}}
  • Backup Storage: {{.Storage}}
  • Backup Location: {{.BackupLocation}}
  • -
  • Backup Size: {{.BackupSize}} bytes
  • +
  • Backup Size: {{.BackupSize}} MiB
  • Backup Reference: {{.BackupReference}}
  • diff --git a/templates/telegram.tmpl b/templates/telegram.tmpl index 6423ce7..68c754d 100644 --- a/templates/telegram.tmpl +++ b/templates/telegram.tmpl @@ -10,7 +10,7 @@ Backup Details: - Backup EndTime: {{.EndTime}} - Backup Storage: {{.Storage}} - Backup Location: {{.BackupLocation}} -- Backup Size: {{.BackupSize}} bytes +- Backup Size: {{.BackupSize}} MiB - Backup Reference: {{.BackupReference}} You can access the backup at the specified location if needed. \ No newline at end of file diff --git a/utils/config.go b/utils/config.go index d111b01..e76fbc4 100644 --- a/utils/config.go +++ b/utils/config.go @@ -37,7 +37,7 @@ type MailConfig struct { } type NotificationData struct { File string - BackupSize int64 + BackupSize uint64 Database string StartTime string EndTime string diff --git a/utils/utils.go b/utils/utils.go index 3a138a9..82b2e39 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -254,3 +254,7 @@ func CronNextTime(cronExpr string) time.Time { next := schedule.Next(now) return next } + +func BytesToMb(b uint64) uint64 { + return b / 1024 / 1024 +} From 93f9595464127a233ba60a4a733351776dedd9c2 Mon Sep 17 00:00:00 2001 From: Jonas Kaninda Date: Tue, 10 Dec 2024 10:10:33 +0100 Subject: [PATCH 2/2] chore: remove db port from required vars --- pkg/var.go | 2 -- templates/email.tmpl | 2 +- templates/telegram.tmpl | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/pkg/var.go b/pkg/var.go index e474f56..8f3fabe 100644 --- a/pkg/var.go +++ b/pkg/var.go @@ -45,14 +45,12 @@ var ( // dbHVars Required environment variables for database var dbHVars = []string{ "DB_HOST", - "DB_PORT", "DB_PASSWORD", "DB_USERNAME", "DB_NAME", } var tdbRVars = []string{ "TARGET_DB_HOST", - "TARGET_DB_PORT", "TARGET_DB_NAME", "TARGET_DB_USERNAME", "TARGET_DB_PASSWORD", diff --git a/templates/email.tmpl b/templates/email.tmpl index 66f6733..2c93ab5 100644 --- a/templates/email.tmpl +++ b/templates/email.tmpl @@ -45,7 +45,7 @@

    ✅ Database Backup Successful

    -

    Dear Team,

    +

    Hi,

    The backup process for the {{.Database}} database was successfully completed. Please find the details below:

    diff --git a/templates/telegram.tmpl b/templates/telegram.tmpl index 68c754d..2c2013b 100644 --- a/templates/telegram.tmpl +++ b/templates/telegram.tmpl @@ -1,6 +1,6 @@ ✅ Database Backup Successful -Dear Team, +Hi, The backup process for the {{.Database}} database was successfully completed. Please find the details below: