Merge pull request #128 from jkaninda/refactor

refactor: update logger, fix warning message
This commit is contained in:
2024-10-23 12:01:43 +02:00
committed by GitHub
3 changed files with 10 additions and 13 deletions

View File

@@ -245,7 +245,7 @@ func localBackup(db *dbConfig, config *BackupConfig) {
} }
fileInfo, err := os.Stat(filepath.Join(tmpPath, finalFileName)) fileInfo, err := os.Stat(filepath.Join(tmpPath, finalFileName))
if err != nil { if err != nil {
utils.Error("Error:", err) utils.Error("Error: %s", err)
} }
backupSize = fileInfo.Size() backupSize = fileInfo.Size()
utils.Info("Backup name is %s", finalFileName) utils.Info("Backup name is %s", finalFileName)
@@ -319,7 +319,7 @@ func s3Backup(db *dbConfig, config *BackupConfig) {
//Get backup info //Get backup info
fileInfo, err := os.Stat(filepath.Join(tmpPath, finalFileName)) fileInfo, err := os.Stat(filepath.Join(tmpPath, finalFileName))
if err != nil { if err != nil {
utils.Error("Error:", err) utils.Error("Error: %s", err)
} }
backupSize = fileInfo.Size() backupSize = fileInfo.Size()
@@ -388,7 +388,7 @@ func sshBackup(db *dbConfig, config *BackupConfig) {
//Get backup info //Get backup info
fileInfo, err := os.Stat(filepath.Join(tmpPath, finalFileName)) fileInfo, err := os.Stat(filepath.Join(tmpPath, finalFileName))
if err != nil { if err != nil {
utils.Error("Error:", err) utils.Error("Error: %s", err)
} }
backupSize = fileInfo.Size() backupSize = fileInfo.Size()
utils.Info("Backup saved in %s", filepath.Join(config.remotePath, finalFileName)) utils.Info("Backup saved in %s", filepath.Join(config.remotePath, finalFileName))
@@ -455,7 +455,7 @@ func ftpBackup(db *dbConfig, config *BackupConfig) {
//Get backup info //Get backup info
fileInfo, err := os.Stat(filepath.Join(tmpPath, finalFileName)) fileInfo, err := os.Stat(filepath.Join(tmpPath, finalFileName))
if err != nil { if err != nil {
utils.Error("Error:", err) utils.Error("Error: %s", err)
} }
backupSize = fileInfo.Size() backupSize = fileInfo.Size()
//Delete backup file from tmp folder //Delete backup file from tmp folder

View File

@@ -7,6 +7,10 @@
package pkg package pkg
import ( import (
"os"
"os/exec"
"path/filepath"
"github.com/jkaninda/encryptor" "github.com/jkaninda/encryptor"
"github.com/jkaninda/go-storage/pkg/ftp" "github.com/jkaninda/go-storage/pkg/ftp"
"github.com/jkaninda/go-storage/pkg/local" "github.com/jkaninda/go-storage/pkg/local"
@@ -14,9 +18,6 @@ import (
"github.com/jkaninda/go-storage/pkg/ssh" "github.com/jkaninda/go-storage/pkg/ssh"
"github.com/jkaninda/pg-bkup/utils" "github.com/jkaninda/pg-bkup/utils"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"os"
"os/exec"
"path/filepath"
) )
func StartRestore(cmd *cobra.Command) { func StartRestore(cmd *cobra.Command) {
@@ -52,10 +53,6 @@ func localRestore(dbConf *dbConfig, restoreConf *RestoreConfig) {
} }
func restoreFromS3(db *dbConfig, conf *RestoreConfig) { func restoreFromS3(db *dbConfig, conf *RestoreConfig) {
utils.Info("Restore database from s3") utils.Info("Restore database from s3")
//err := DownloadFile(tmpPath, conf.file, conf.bucket, conf.s3Path)
//if err != nil {
// utils.Fatal("Error download file from s3 %s %v ", conf.file, err)
//}
awsConfig := initAWSConfig() awsConfig := initAWSConfig()
if conf.remotePath == "" { if conf.remotePath == "" {
conf.remotePath = awsConfig.remotePath conf.remotePath = awsConfig.remotePath
@@ -101,7 +98,7 @@ func restoreFromRemote(db *dbConfig, conf *RestoreConfig) {
} }
err = sshStorage.CopyFrom(conf.file) err = sshStorage.CopyFrom(conf.file)
if err != nil { if err != nil {
utils.Fatal("Error copying backup file: %w", err) utils.Fatal("Error copying backup file: %s", err)
} }
RestoreDatabase(db, conf) RestoreDatabase(db, conf)
} }

View File

@@ -203,7 +203,7 @@ func CronNextTime(cronExpr string) time.Time {
// Parse the cron expression // Parse the cron expression
schedule, err := cron.ParseStandard(cronExpr) schedule, err := cron.ParseStandard(cronExpr)
if err != nil { if err != nil {
Error("Error parsing cron expression:", err) Error("Error parsing cron expression: %s", err)
return time.Time{} return time.Time{}
} }
// Get the current time // Get the current time