From 0501c151a4dfa3e2afba1faec15be91acab87abf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Dec 2024 06:56:30 +0000 Subject: [PATCH 1/5] chore(deps): bump golang from 1.23.3 to 1.23.4 Bumps golang from 1.23.3 to 1.23.4. --- updated-dependencies: - dependency-name: golang dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9d505e0..e44a461 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.23.3 AS build +FROM golang:1.23.4 AS build WORKDIR /app ARG appVersion="" # Copy the source code. From c89411cfa6aff510aca669da2724486d87f372f0 Mon Sep 17 00:00:00 2001 From: Jonas Kaninda Date: Tue, 10 Dec 2024 09:58:39 +0100 Subject: [PATCH 2/5] 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 3/5] 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: From 0edee0b7031d4c7a988504ce9920f2dbf96eb3ed Mon Sep 17 00:00:00 2001 From: Jonas Kaninda Date: Tue, 10 Dec 2024 10:14:43 +0100 Subject: [PATCH 4/5] docs: update features --- docs/index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/index.md b/docs/index.md index 9a2e11c..bf75224 100644 --- a/docs/index.md +++ b/docs/index.md @@ -17,6 +17,7 @@ It supports a variety of storage options and ensures data security through GPG e - AWS S3 or any S3-compatible object storage - FTP - SSH-compatible storage + - Azure Blob storage - **Data Security:** - Backups can be encrypted using **GPG** to ensure confidentiality. From abf1aeba7c27ee1b9e8810dc6b4b6fd43ac42a38 Mon Sep 17 00:00:00 2001 From: Jonas Kaninda Date: Thu, 12 Dec 2024 12:43:06 +0100 Subject: [PATCH 5/5] chore: add convert bytes to a human-readable string with the appropriate unit (bytes, MiB, or GiB) --- pkg/azure.go | 5 +++-- pkg/backup.go | 5 +++-- pkg/remote.go | 10 ++++++---- pkg/s3.go | 3 ++- templates/email.tmpl | 2 +- templates/telegram.tmpl | 2 +- utils/config.go | 2 +- utils/utils.go | 16 ++++++++++++++-- 8 files changed, 31 insertions(+), 14 deletions(-) diff --git a/pkg/azure.go b/pkg/azure.go index 9df74ba..5c5d468 100644 --- a/pkg/azure.go +++ b/pkg/azure.go @@ -57,13 +57,14 @@ func azureBackup(db *dbConfig, config *BackupConfig) { } } - + utils.Info("Backup name is %s", finalFileName) + utils.Info("Backup size: %s", utils.ConvertBytes(uint64(backupSize))) utils.Info("Uploading backup archive to Azure Blob storage ... done ") // Send notification utils.NotifySuccess(&utils.NotificationData{ File: finalFileName, - BackupSize: utils.BytesToMb(uint64(backupSize)), + BackupSize: utils.ConvertBytes(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 78b788f..4140ddb 100644 --- a/pkg/backup.go +++ b/pkg/backup.go @@ -277,7 +277,6 @@ func localBackup(db *dbConfig, config *BackupConfig) { utils.Error("Error: %s", err) } backupSize = fileInfo.Size() - utils.Info("Backup name is %s", finalFileName) localStorage := local.NewStorage(local.Config{ LocalPath: tmpPath, RemotePath: storagePath, @@ -286,11 +285,13 @@ func localBackup(db *dbConfig, config *BackupConfig) { if err != nil { utils.Fatal("Error copying backup file: %s", err) } + utils.Info("Backup name is %s", finalFileName) + utils.Info("Backup size: %s", utils.ConvertBytes(uint64(backupSize))) utils.Info("Backup saved in %s", filepath.Join(storagePath, finalFileName)) // Send notification utils.NotifySuccess(&utils.NotificationData{ File: finalFileName, - BackupSize: utils.BytesToMb(uint64(backupSize)), + BackupSize: utils.ConvertBytes(uint64(backupSize)), Database: db.dbName, Storage: config.storage, BackupLocation: filepath.Join(storagePath, finalFileName), diff --git a/pkg/remote.go b/pkg/remote.go index b668413..5228573 100644 --- a/pkg/remote.go +++ b/pkg/remote.go @@ -88,11 +88,13 @@ func sshBackup(db *dbConfig, config *BackupConfig) { } } + utils.Info("Backup name is %s", finalFileName) + utils.Info("Backup size: %s", utils.ConvertBytes(uint64(backupSize))) utils.Info("Uploading backup archive to remote storage ... done ") // Send notification utils.NotifySuccess(&utils.NotificationData{ File: finalFileName, - BackupSize: utils.BytesToMb(uint64(backupSize)), + BackupSize: utils.ConvertBytes(uint64(backupSize)), Database: db.dbName, Storage: config.storage, BackupLocation: filepath.Join(config.remotePath, finalFileName), @@ -161,7 +163,6 @@ func ftpBackup(db *dbConfig, config *BackupConfig) { finalFileName = fmt.Sprintf("%s.%s", config.backupFileName, "gpg") } utils.Info("Uploading backup archive to the remote FTP server ... ") - utils.Info("Backup name is %s", finalFileName) ftpConfig := loadFtpConfig() ftpStorage, err := ftp.NewStorage(ftp.Config{ Host: ftpConfig.host, @@ -198,13 +199,14 @@ func ftpBackup(db *dbConfig, config *BackupConfig) { } } - + utils.Info("Backup name is %s", finalFileName) + utils.Info("Backup size: %s", utils.ConvertBytes(uint64(backupSize))) utils.Info("Uploading backup archive to the remote FTP server ... done ") // Send notification utils.NotifySuccess(&utils.NotificationData{ File: finalFileName, - BackupSize: utils.BytesToMb(uint64(backupSize)), + BackupSize: utils.ConvertBytes(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 9a5c6da..9588782 100644 --- a/pkg/s3.go +++ b/pkg/s3.go @@ -89,11 +89,12 @@ func s3Backup(db *dbConfig, config *BackupConfig) { } } utils.Info("Backup saved in %s", filepath.Join(config.remotePath, finalFileName)) + utils.Info("Backup size: %s", utils.ConvertBytes(uint64(backupSize))) utils.Info("Uploading backup archive to remote storage S3 ... done ") // Send notification utils.NotifySuccess(&utils.NotificationData{ File: finalFileName, - BackupSize: utils.BytesToMb(uint64(backupSize)), + BackupSize: utils.ConvertBytes(uint64(backupSize)), Database: db.dbName, Storage: config.storage, BackupLocation: filepath.Join(config.remotePath, finalFileName), diff --git a/templates/email.tmpl b/templates/email.tmpl index 2c93ab5..bc859ae 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}} MiB
  • +
  • Backup Size: {{.BackupSize}}
  • Backup Reference: {{.BackupReference}}
  • diff --git a/templates/telegram.tmpl b/templates/telegram.tmpl index 2c2013b..6e38ecf 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}} MiB +- Backup Size: {{.BackupSize}} - 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 e76fbc4..9f8b8c8 100644 --- a/utils/config.go +++ b/utils/config.go @@ -37,7 +37,7 @@ type MailConfig struct { } type NotificationData struct { File string - BackupSize uint64 + BackupSize string Database string StartTime string EndTime string diff --git a/utils/utils.go b/utils/utils.go index 82b2e39..d873b79 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -255,6 +255,18 @@ func CronNextTime(cronExpr string) time.Time { return next } -func BytesToMb(b uint64) uint64 { - return b / 1024 / 1024 +// ConvertBytes converts bytes to a human-readable string with the appropriate unit (bytes, MiB, or GiB). +func ConvertBytes(bytes uint64) string { + const ( + MiB = 1024 * 1024 + GiB = MiB * 1024 + ) + switch { + case bytes >= GiB: + return fmt.Sprintf("%.2f GiB", float64(bytes)/float64(GiB)) + case bytes >= MiB: + return fmt.Sprintf("%.2f MiB", float64(bytes)/float64(MiB)) + default: + return fmt.Sprintf("%d bytes", bytes) + } }