Compare commits
23 Commits
1a6e2e4ffc
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 8d9131fa9e | |||
| abf1aeba7c | |||
| ad2f3a1990 | |||
| 0edee0b703 | |||
| fdb79d3cef | |||
| 01915039e7 | |||
| f9dbd0b85c | |||
| 409f9e91f2 | |||
| 93f9595464 | |||
| c89411cfa6 | |||
| 6ec480acda | |||
|
|
0501c151a4 | ||
| 91a440035d | |||
| 3009747874 | |||
| 5a65c51f54 | |||
| 6f854d5165 | |||
| 05003b386e | |||
| 47c7afda4e | |||
| fc6325e5b6 | |||
| cbeb8b0ba2 | |||
| 4904e8d0a6 | |||
| 803b077b3d | |||
| 6503e4b5bd |
@@ -1,4 +1,4 @@
|
|||||||
FROM golang:1.23.3 AS build
|
FROM golang:1.23.4 AS build
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
ARG appVersion=""
|
ARG appVersion=""
|
||||||
# Copy the source code.
|
# Copy the source code.
|
||||||
|
|||||||
@@ -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
|
- AWS S3 or any S3-compatible object storage
|
||||||
- FTP
|
- FTP
|
||||||
- SSH-compatible storage
|
- SSH-compatible storage
|
||||||
|
- Azure Blob storage
|
||||||
|
|
||||||
- **Data Security:**
|
- **Data Security:**
|
||||||
- Backups can be encrypted using **GPG** to ensure confidentiality.
|
- Backups can be encrypted using **GPG** to ensure confidentiality.
|
||||||
|
|||||||
@@ -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 ")
|
utils.Info("Uploading backup archive to Azure Blob storage ... done ")
|
||||||
|
|
||||||
// Send notification
|
// Send notification
|
||||||
utils.NotifySuccess(&utils.NotificationData{
|
utils.NotifySuccess(&utils.NotificationData{
|
||||||
File: finalFileName,
|
File: finalFileName,
|
||||||
BackupSize: backupSize,
|
BackupSize: utils.ConvertBytes(uint64(backupSize)),
|
||||||
Database: db.dbName,
|
Database: db.dbName,
|
||||||
Storage: config.storage,
|
Storage: config.storage,
|
||||||
BackupLocation: filepath.Join(config.remotePath, finalFileName),
|
BackupLocation: filepath.Join(config.remotePath, finalFileName),
|
||||||
|
|||||||
@@ -277,7 +277,6 @@ func localBackup(db *dbConfig, config *BackupConfig) {
|
|||||||
utils.Error("Error: %s", err)
|
utils.Error("Error: %s", err)
|
||||||
}
|
}
|
||||||
backupSize = fileInfo.Size()
|
backupSize = fileInfo.Size()
|
||||||
utils.Info("Backup name is %s", finalFileName)
|
|
||||||
localStorage := local.NewStorage(local.Config{
|
localStorage := local.NewStorage(local.Config{
|
||||||
LocalPath: tmpPath,
|
LocalPath: tmpPath,
|
||||||
RemotePath: storagePath,
|
RemotePath: storagePath,
|
||||||
@@ -286,11 +285,13 @@ func localBackup(db *dbConfig, config *BackupConfig) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Fatal("Error copying backup file: %s", err)
|
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))
|
utils.Info("Backup saved in %s", filepath.Join(storagePath, finalFileName))
|
||||||
// Send notification
|
// Send notification
|
||||||
utils.NotifySuccess(&utils.NotificationData{
|
utils.NotifySuccess(&utils.NotificationData{
|
||||||
File: finalFileName,
|
File: finalFileName,
|
||||||
BackupSize: backupSize,
|
BackupSize: utils.ConvertBytes(uint64(backupSize)),
|
||||||
Database: db.dbName,
|
Database: db.dbName,
|
||||||
Storage: config.storage,
|
Storage: config.storage,
|
||||||
BackupLocation: filepath.Join(storagePath, finalFileName),
|
BackupLocation: filepath.Join(storagePath, finalFileName),
|
||||||
|
|||||||
@@ -199,10 +199,7 @@ func RemoveLastExtension(filename string) string {
|
|||||||
}
|
}
|
||||||
func convertJDBCToDbConfig(jdbcURI string) (*dbConfig, error) {
|
func convertJDBCToDbConfig(jdbcURI string) (*dbConfig, error) {
|
||||||
// Remove the "jdbc:" prefix
|
// Remove the "jdbc:" prefix
|
||||||
if strings.HasPrefix(jdbcURI, "jdbc:") {
|
|
||||||
jdbcURI = strings.TrimPrefix(jdbcURI, "jdbc:")
|
jdbcURI = strings.TrimPrefix(jdbcURI, "jdbc:")
|
||||||
}
|
|
||||||
|
|
||||||
// Parse the URI
|
// Parse the URI
|
||||||
u, err := url.Parse(jdbcURI)
|
u, err := url.Parse(jdbcURI)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -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 ")
|
utils.Info("Uploading backup archive to remote storage ... done ")
|
||||||
// Send notification
|
// Send notification
|
||||||
utils.NotifySuccess(&utils.NotificationData{
|
utils.NotifySuccess(&utils.NotificationData{
|
||||||
File: finalFileName,
|
File: finalFileName,
|
||||||
BackupSize: backupSize,
|
BackupSize: utils.ConvertBytes(uint64(backupSize)),
|
||||||
Database: db.dbName,
|
Database: db.dbName,
|
||||||
Storage: config.storage,
|
Storage: config.storage,
|
||||||
BackupLocation: filepath.Join(config.remotePath, finalFileName),
|
BackupLocation: filepath.Join(config.remotePath, finalFileName),
|
||||||
@@ -161,7 +163,6 @@ func ftpBackup(db *dbConfig, config *BackupConfig) {
|
|||||||
finalFileName = fmt.Sprintf("%s.%s", config.backupFileName, "gpg")
|
finalFileName = fmt.Sprintf("%s.%s", config.backupFileName, "gpg")
|
||||||
}
|
}
|
||||||
utils.Info("Uploading backup archive to the remote FTP server ... ")
|
utils.Info("Uploading backup archive to the remote FTP server ... ")
|
||||||
utils.Info("Backup name is %s", finalFileName)
|
|
||||||
ftpConfig := loadFtpConfig()
|
ftpConfig := loadFtpConfig()
|
||||||
ftpStorage, err := ftp.NewStorage(ftp.Config{
|
ftpStorage, err := ftp.NewStorage(ftp.Config{
|
||||||
Host: ftpConfig.host,
|
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 ")
|
utils.Info("Uploading backup archive to the remote FTP server ... done ")
|
||||||
|
|
||||||
// Send notification
|
// Send notification
|
||||||
utils.NotifySuccess(&utils.NotificationData{
|
utils.NotifySuccess(&utils.NotificationData{
|
||||||
File: finalFileName,
|
File: finalFileName,
|
||||||
BackupSize: backupSize,
|
BackupSize: utils.ConvertBytes(uint64(backupSize)),
|
||||||
Database: db.dbName,
|
Database: db.dbName,
|
||||||
Storage: config.storage,
|
Storage: config.storage,
|
||||||
BackupLocation: filepath.Join(config.remotePath, finalFileName),
|
BackupLocation: filepath.Join(config.remotePath, finalFileName),
|
||||||
|
|||||||
@@ -89,11 +89,12 @@ func s3Backup(db *dbConfig, config *BackupConfig) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
utils.Info("Backup saved in %s", filepath.Join(config.remotePath, finalFileName))
|
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 ")
|
utils.Info("Uploading backup archive to remote storage S3 ... done ")
|
||||||
// Send notification
|
// Send notification
|
||||||
utils.NotifySuccess(&utils.NotificationData{
|
utils.NotifySuccess(&utils.NotificationData{
|
||||||
File: finalFileName,
|
File: finalFileName,
|
||||||
BackupSize: backupSize,
|
BackupSize: utils.ConvertBytes(uint64(backupSize)),
|
||||||
Database: db.dbName,
|
Database: db.dbName,
|
||||||
Storage: config.storage,
|
Storage: config.storage,
|
||||||
BackupLocation: filepath.Join(config.remotePath, finalFileName),
|
BackupLocation: filepath.Join(config.remotePath, finalFileName),
|
||||||
|
|||||||
@@ -45,14 +45,12 @@ var (
|
|||||||
// dbHVars Required environment variables for database
|
// dbHVars Required environment variables for database
|
||||||
var dbHVars = []string{
|
var dbHVars = []string{
|
||||||
"DB_HOST",
|
"DB_HOST",
|
||||||
"DB_PORT",
|
|
||||||
"DB_PASSWORD",
|
"DB_PASSWORD",
|
||||||
"DB_USERNAME",
|
"DB_USERNAME",
|
||||||
"DB_NAME",
|
"DB_NAME",
|
||||||
}
|
}
|
||||||
var tdbRVars = []string{
|
var tdbRVars = []string{
|
||||||
"TARGET_DB_HOST",
|
"TARGET_DB_HOST",
|
||||||
"TARGET_DB_PORT",
|
|
||||||
"TARGET_DB_NAME",
|
"TARGET_DB_NAME",
|
||||||
"TARGET_DB_USERNAME",
|
"TARGET_DB_USERNAME",
|
||||||
"TARGET_DB_PASSWORD",
|
"TARGET_DB_PASSWORD",
|
||||||
|
|||||||
@@ -52,9 +52,9 @@
|
|||||||
<h3>Failure Details:</h3>
|
<h3>Failure Details:</h3>
|
||||||
<ul>
|
<ul>
|
||||||
<li><strong>Database Name:</strong> {{.DatabaseName}}</li>
|
<li><strong>Database Name:</strong> {{.DatabaseName}}</li>
|
||||||
<li><strong>Error Message:</strong> {{.Error}}</li>
|
|
||||||
<li><strong>Date:</strong> {{.EndTime}}</li>
|
<li><strong>Date:</strong> {{.EndTime}}</li>
|
||||||
<li><strong>Backup Reference:</strong> {{.BackupReference}}</li>
|
<li><strong>Backup Reference:</strong> {{.BackupReference}}</li>
|
||||||
|
<li><strong>Error Message:</strong> {{.Error}}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h2>✅ Database Backup Successful</h2>
|
<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>
|
<p>The backup process for the <strong>{{.Database}}</strong> database was successfully completed. Please find the details below:</p>
|
||||||
|
|
||||||
<div class="details">
|
<div class="details">
|
||||||
@@ -56,7 +56,7 @@
|
|||||||
<li><strong>Backup End Time:</strong> {{.EndTime}}</li>
|
<li><strong>Backup End Time:</strong> {{.EndTime}}</li>
|
||||||
<li><strong>Backup Storage:</strong> {{.Storage}}</li>
|
<li><strong>Backup Storage:</strong> {{.Storage}}</li>
|
||||||
<li><strong>Backup Location:</strong> {{.BackupLocation}}</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>
|
<li><strong>Backup Reference:</strong> {{.BackupReference}}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
✅ Database Backup Successful
|
✅ Database Backup Successful
|
||||||
|
|
||||||
Dear Team,
|
Hi,
|
||||||
The backup process for the {{.Database}} database was successfully completed.
|
The backup process for the {{.Database}} database was successfully completed.
|
||||||
Please find the details below:
|
Please find the details below:
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ Backup Details:
|
|||||||
- Backup EndTime: {{.EndTime}}
|
- Backup EndTime: {{.EndTime}}
|
||||||
- Backup Storage: {{.Storage}}
|
- Backup Storage: {{.Storage}}
|
||||||
- Backup Location: {{.BackupLocation}}
|
- Backup Location: {{.BackupLocation}}
|
||||||
- Backup Size: {{.BackupSize}} bytes
|
- Backup Size: {{.BackupSize}}
|
||||||
- Backup Reference: {{.BackupReference}}
|
- Backup Reference: {{.BackupReference}}
|
||||||
|
|
||||||
You can access the backup at the specified location if needed.
|
You can access the backup at the specified location if needed.
|
||||||
@@ -37,7 +37,7 @@ type MailConfig struct {
|
|||||||
}
|
}
|
||||||
type NotificationData struct {
|
type NotificationData struct {
|
||||||
File string
|
File string
|
||||||
BackupSize int64
|
BackupSize string
|
||||||
Database string
|
Database string
|
||||||
StartTime string
|
StartTime string
|
||||||
EndTime string
|
EndTime string
|
||||||
|
|||||||
@@ -254,3 +254,19 @@ func CronNextTime(cronExpr string) time.Time {
|
|||||||
next := schedule.Next(now)
|
next := schedule.Next(now)
|
||||||
return next
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user