Compare commits

...

22 Commits

Author SHA1 Message Date
abf1aeba7c chore: add convert bytes to a human-readable string with the appropriate unit (bytes, MiB, or GiB)
All checks were successful
Lint / Run on Ubuntu (push) Successful in 20m39s
Lint / Run on Ubuntu (pull_request) Successful in 20m14s
2024-12-12 12:43:06 +01:00
ad2f3a1990 Merge pull request #151 from jkaninda/refactor
docs: update features
2024-12-10 10:15:34 +01:00
0edee0b703 docs: update features 2024-12-10 10:14:43 +01:00
fdb79d3cef Merge pull request #150 from jkaninda/refactor
chore: add convert backup size from bytes to Mib
2024-12-10 10:13:30 +01:00
01915039e7 Merge branch 'main' of github.com:jkaninda/pg-bkup into refactor 2024-12-10 10:12:27 +01:00
f9dbd0b85c Merge pull request #148 from jkaninda/develop
feat: add support Database source jdbc uri format
2024-12-10 10:11:31 +01:00
409f9e91f2 Merge pull request #149 from jkaninda/dependabot/docker/golang-1.23.4
chore(deps): bump golang from 1.23.3 to 1.23.4
2024-12-10 10:11:07 +01:00
93f9595464 chore: remove db port from required vars 2024-12-10 10:10:33 +01:00
c89411cfa6 chore: add convert backup size from bytes to Mib 2024-12-10 09:58:39 +01:00
6ec480acda Merge branch 'main' of github.com:jkaninda/pg-bkup into refactor 2024-12-10 09:48:07 +01:00
dependabot[bot]
0501c151a4 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] <support@github.com>
2024-12-09 06:56:30 +00:00
91a440035d refactor: refactoring of code
All checks were successful
Lint / Run on Ubuntu (push) Successful in 20m9s
2024-12-08 13:39:54 +01:00
3009747874 Merge pull request #147 from jkaninda/refactor
Fix grammar issues in azure.go
2024-12-07 23:59:27 +01:00
5a65c51f54 Merge pull request #146 from jkaninda/develop
fix: SSH storage key identify file
2024-12-07 20:38:38 +01:00
6f854d5165 Merge pull request #145 from jkaninda/develop
chore: update notification template
2024-12-07 18:00:53 +01:00
05003b386e Merge pull request #144 from jkaninda/refactor
chore: correct pg name
2024-12-07 03:48:50 +01:00
47c7afda4e Merge pull request #143 from jkaninda/refactor
chore: update .env.example
2024-12-07 03:28:34 +01:00
fc6325e5b6 Merge pull request #142 from jkaninda/refactor
chore: update .env.example
2024-12-07 03:27:40 +01:00
cbeb8b0ba2 Merge pull request #141 from jkaninda/refactor
chore: update base image
2024-12-07 02:32:14 +01:00
4904e8d0a6 Merge pull request #140 from jkaninda/refactor
refactor: clean up code
2024-12-07 02:30:39 +01:00
803b077b3d Merge pull request #139 from jkaninda/refactor
fix: fix s3 remote path when backing up multiple databases
2024-12-07 02:11:34 +01:00
6503e4b5bd Merge pull request #138 from jkaninda/refactor
feat: add Azure Blob storage
2024-12-06 21:36:05 +01:00
13 changed files with 39 additions and 22 deletions

View File

@@ -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.

View File

@@ -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.

View File

@@ -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: backupSize,
BackupSize: utils.ConvertBytes(uint64(backupSize)),
Database: db.dbName,
Storage: config.storage,
BackupLocation: filepath.Join(config.remotePath, finalFileName),

View File

@@ -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: backupSize,
BackupSize: utils.ConvertBytes(uint64(backupSize)),
Database: db.dbName,
Storage: config.storage,
BackupLocation: filepath.Join(storagePath, finalFileName),

View File

@@ -199,10 +199,7 @@ func RemoveLastExtension(filename string) string {
}
func convertJDBCToDbConfig(jdbcURI string) (*dbConfig, error) {
// Remove the "jdbc:" prefix
if strings.HasPrefix(jdbcURI, "jdbc:") {
jdbcURI = strings.TrimPrefix(jdbcURI, "jdbc:")
}
jdbcURI = strings.TrimPrefix(jdbcURI, "jdbc:")
// Parse the URI
u, err := url.Parse(jdbcURI)
if err != nil {

View File

@@ -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: 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: backupSize,
BackupSize: utils.ConvertBytes(uint64(backupSize)),
Database: db.dbName,
Storage: config.storage,
BackupLocation: filepath.Join(config.remotePath, finalFileName),

View File

@@ -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: backupSize,
BackupSize: utils.ConvertBytes(uint64(backupSize)),
Database: db.dbName,
Storage: config.storage,
BackupLocation: filepath.Join(config.remotePath, finalFileName),

View File

@@ -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",

View File

@@ -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>

View File

@@ -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">
@@ -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}}</li>
<li><strong>Backup Reference:</strong> {{.BackupReference}}</li>
</ul>
</div>

View File

@@ -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:
@@ -10,7 +10,7 @@ Backup Details:
- Backup EndTime: {{.EndTime}}
- Backup Storage: {{.Storage}}
- Backup Location: {{.BackupLocation}}
- Backup Size: {{.BackupSize}} bytes
- Backup Size: {{.BackupSize}}
- Backup Reference: {{.BackupReference}}
You can access the backup at the specified location if needed.

View File

@@ -37,7 +37,7 @@ type MailConfig struct {
}
type NotificationData struct {
File string
BackupSize int64
BackupSize string
Database string
StartTime string
EndTime string

View File

@@ -254,3 +254,19 @@ func CronNextTime(cronExpr string) time.Time {
next := schedule.Next(now)
return next
}
// 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)
}
}