Skip to content

Commit

Permalink
Merge pull request #150 from jkaninda/refactor
Browse files Browse the repository at this point in the history
chore: add convert backup size from bytes to Mib
  • Loading branch information
jkaninda authored Dec 10, 2024
2 parents f9dbd0b + 0191503 commit fdb79d3
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkg/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion pkg/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions pkg/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion pkg/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 0 additions & 2 deletions pkg/var.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion templates/email-error.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
<h3>Failure Details:</h3>
<ul>
<li><strong>Database Name:</strong> {{.DatabaseName}}</li>
<li><strong>Error Message:</strong> {{.Error}}</li>
<li><strong>Date:</strong> {{.EndTime}}</li>
<li><strong>Backup Reference:</strong> {{.BackupReference}}</li>
<li><strong>Error Message:</strong> {{.Error}}</li>
</ul>
</div>

Expand Down
4 changes: 2 additions & 2 deletions templates/email.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</head>
<body>
<h2>✅ Database Backup Successful</h2>
<p>Dear Team,</p>
<p>Hi,</p>
<p>The backup process for the <strong>{{.Database}}</strong> database was successfully completed. Please find the details below:</p>

<div class="details">
Expand All @@ -56,7 +56,7 @@
<li><strong>Backup End Time:</strong> {{.EndTime}}</li>
<li><strong>Backup Storage:</strong> {{.Storage}}</li>
<li><strong>Backup Location:</strong> {{.BackupLocation}}</li>
<li><strong>Backup Size:</strong> {{.BackupSize}} bytes</li>
<li><strong>Backup Size:</strong> {{.BackupSize}} MiB</li>
<li><strong>Backup Reference:</strong> {{.BackupReference}}</li>
</ul>
</div>
Expand Down
4 changes: 2 additions & 2 deletions templates/telegram.tmpl
Original file line number Diff line number Diff line change
@@ -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:

Expand All @@ -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.
2 changes: 1 addition & 1 deletion utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type MailConfig struct {
}
type NotificationData struct {
File string
BackupSize int64
BackupSize uint64
Database string
StartTime string
EndTime string
Expand Down
4 changes: 4 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit fdb79d3

Please sign in to comment.