refactor: refactoring of code
This commit is contained in:
8
main.go
8
main.go
@@ -160,7 +160,7 @@ func start() {
|
|||||||
if operation != "backup" {
|
if operation != "backup" {
|
||||||
if storage != "s3" {
|
if storage != "s3" {
|
||||||
utils.Info("Restore from local")
|
utils.Info("Restore from local")
|
||||||
pkg.Restore(file)
|
pkg.RestoreDatabase(file)
|
||||||
} else {
|
} else {
|
||||||
utils.Info("Restore from s3")
|
utils.Info("Restore from s3")
|
||||||
s3Restore()
|
s3Restore()
|
||||||
@@ -168,7 +168,7 @@ func start() {
|
|||||||
} else {
|
} else {
|
||||||
if storage != "s3" {
|
if storage != "s3" {
|
||||||
utils.Info("Backup to local storage")
|
utils.Info("Backup to local storage")
|
||||||
pkg.Backup(disableCompression)
|
pkg.BackupDatabase(disableCompression)
|
||||||
} else {
|
} else {
|
||||||
utils.Info("Backup to s3 storage")
|
utils.Info("Backup to s3 storage")
|
||||||
s3Backup()
|
s3Backup()
|
||||||
@@ -182,7 +182,7 @@ func start() {
|
|||||||
}
|
}
|
||||||
func s3Backup() {
|
func s3Backup() {
|
||||||
pkg.MountS3Storage(s3Path)
|
pkg.MountS3Storage(s3Path)
|
||||||
pkg.Backup(disableCompression)
|
pkg.BackupDatabase(disableCompression)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run in scheduled mode
|
// Run in scheduled mode
|
||||||
@@ -215,5 +215,5 @@ func scheduledMode() {
|
|||||||
func s3Restore() {
|
func s3Restore() {
|
||||||
// Restore database from S3
|
// Restore database from S3
|
||||||
pkg.MountS3Storage(s3Path)
|
pkg.MountS3Storage(s3Path)
|
||||||
pkg.Restore(file)
|
pkg.RestoreDatabase(file)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ var (
|
|||||||
storagePath = "/backup"
|
storagePath = "/backup"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Backup backup database
|
// BackupDatabase backup database
|
||||||
func Backup(disableCompression bool) {
|
func BackupDatabase(disableCompression bool) {
|
||||||
dbHost = os.Getenv("DB_HOST")
|
dbHost = os.Getenv("DB_HOST")
|
||||||
dbPassword = os.Getenv("DB_PASSWORD")
|
dbPassword = os.Getenv("DB_PASSWORD")
|
||||||
dbUserName = os.Getenv("DB_USERNAME")
|
dbUserName = os.Getenv("DB_USERNAME")
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Restore restore database
|
// RestoreDatabase restore database
|
||||||
func Restore(file string) {
|
func RestoreDatabase(file string) {
|
||||||
dbHost = os.Getenv("DB_HOST")
|
dbHost = os.Getenv("DB_HOST")
|
||||||
dbPassword = os.Getenv("DB_PASSWORD")
|
dbPassword = os.Getenv("DB_PASSWORD")
|
||||||
dbUserName = os.Getenv("DB_USERNAME")
|
dbUserName = os.Getenv("DB_USERNAME")
|
||||||
|
|||||||
@@ -21,15 +21,13 @@ var (
|
|||||||
s3Endpoint = ""
|
s3Endpoint = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
// MountS3Storage Mount s3 storage using s3fs
|
||||||
|
func MountS3Storage(s3Path string) {
|
||||||
accessKey = os.Getenv("ACCESS_KEY")
|
accessKey = os.Getenv("ACCESS_KEY")
|
||||||
secretKey = os.Getenv("SECRET_KEY")
|
secretKey = os.Getenv("SECRET_KEY")
|
||||||
bucketName = os.Getenv("BUCKETNAME")
|
bucketName = os.Getenv("BUCKETNAME")
|
||||||
s3Endpoint = os.Getenv("S3_ENDPOINT")
|
s3Endpoint = os.Getenv("S3_ENDPOINT")
|
||||||
}
|
|
||||||
|
|
||||||
// MountS3Storage Mount s3 storage using s3fs
|
|
||||||
func MountS3Storage(s3Path string) {
|
|
||||||
if accessKey == "" || secretKey == "" || bucketName == "" {
|
if accessKey == "" || secretKey == "" || bucketName == "" {
|
||||||
utils.Fatal("Please make sure all environment variables are set")
|
utils.Fatal("Please make sure all environment variables are set")
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user