mirror of
https://github.com/jkaninda/mysql-bkup.git
synced 2025-12-06 21:49:40 +01:00
fix: generate backup file name in scheduled mode
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func StartBackup(cmd *cobra.Command) {
|
func StartBackup(cmd *cobra.Command) {
|
||||||
@@ -39,7 +40,7 @@ func StartBackup(cmd *cobra.Command) {
|
|||||||
func scheduledMode(db *dbConfig, config *BackupConfig) {
|
func scheduledMode(db *dbConfig, config *BackupConfig) {
|
||||||
utils.Info("Running in Scheduled mode")
|
utils.Info("Running in Scheduled mode")
|
||||||
utils.Info("Backup cron expression: %s", config.cronExpression)
|
utils.Info("Backup cron expression: %s", config.cronExpression)
|
||||||
utils.Info("Storage type %s ", storage)
|
utils.Info("Storage type %s ", config.storage)
|
||||||
|
|
||||||
//Test database connexion
|
//Test database connexion
|
||||||
testDatabaseConnection(db)
|
testDatabaseConnection(db)
|
||||||
@@ -62,6 +63,12 @@ func scheduledMode(db *dbConfig, config *BackupConfig) {
|
|||||||
}
|
}
|
||||||
func BackupTask(db *dbConfig, config *BackupConfig) {
|
func BackupTask(db *dbConfig, config *BackupConfig) {
|
||||||
utils.Info("Starting backup task...")
|
utils.Info("Starting backup task...")
|
||||||
|
//Generate backup file name
|
||||||
|
backupFileName := fmt.Sprintf("%s_%s.sql.gz", db.dbName, time.Now().Format("20240102_150405"))
|
||||||
|
if config.disableCompression {
|
||||||
|
backupFileName = fmt.Sprintf("%s_%s.sql", db.dbName, time.Now().Format("20240102_150405"))
|
||||||
|
}
|
||||||
|
config.backupFileName = backupFileName
|
||||||
switch config.storage {
|
switch config.storage {
|
||||||
case "s3":
|
case "s3":
|
||||||
s3Backup(db, config.backupFileName, config.disableCompression, config.prune, config.backupRetention, config.encryption)
|
s3Backup(db, config.backupFileName, config.disableCompression, config.prune, config.backupRetention, config.encryption)
|
||||||
|
|||||||
@@ -7,11 +7,9 @@
|
|||||||
package pkg
|
package pkg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/jkaninda/mysql-bkup/utils"
|
"github.com/jkaninda/mysql-bkup/utils"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
@@ -88,15 +86,8 @@ func initBackupConfig(cmd *cobra.Command) *BackupConfig {
|
|||||||
if gpqPassphrase != "" {
|
if gpqPassphrase != "" {
|
||||||
encryption = true
|
encryption = true
|
||||||
}
|
}
|
||||||
//Generate file name
|
|
||||||
backupFileName := fmt.Sprintf("%s_%s.sql.gz", dbConf.dbName, time.Now().Format("20240102_150405"))
|
|
||||||
if disableCompression {
|
|
||||||
backupFileName = fmt.Sprintf("%s_%s.sql", dbConf.dbName, time.Now().Format("20240102_150405"))
|
|
||||||
}
|
|
||||||
|
|
||||||
//Initialize backup configs
|
//Initialize backup configs
|
||||||
config := BackupConfig{}
|
config := BackupConfig{}
|
||||||
config.backupFileName = backupFileName
|
|
||||||
config.backupRetention = backupRetention
|
config.backupRetention = backupRetention
|
||||||
config.disableCompression = disableCompression
|
config.disableCompression = disableCompression
|
||||||
config.prune = prune
|
config.prune = prune
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ func StartRestore(cmd *cobra.Command) {
|
|||||||
dbConf = initDbConfig(cmd)
|
dbConf = initDbConfig(cmd)
|
||||||
restoreConf := initRestoreConfig(cmd)
|
restoreConf := initRestoreConfig(cmd)
|
||||||
|
|
||||||
switch storage {
|
switch restoreConf.storage {
|
||||||
case "s3":
|
case "s3":
|
||||||
restoreFromS3(dbConf, restoreConf.file, restoreConf.bucket, restoreConf.s3Path)
|
restoreFromS3(dbConf, restoreConf.file, restoreConf.bucket, restoreConf.s3Path)
|
||||||
case "local":
|
case "local":
|
||||||
|
|||||||
Reference in New Issue
Block a user