mirror of
https://github.com/jkaninda/mysql-bkup.git
synced 2025-12-06 21:49:40 +01:00
@@ -27,6 +27,7 @@ linters:
|
|||||||
- gosimple
|
- gosimple
|
||||||
- govet
|
- govet
|
||||||
- ineffassign
|
- ineffassign
|
||||||
|
# - lll
|
||||||
- misspell
|
- misspell
|
||||||
- nakedret
|
- nakedret
|
||||||
- prealloc
|
- prealloc
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ var BackupCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
//Backup
|
// Backup
|
||||||
BackupCmd.PersistentFlags().StringP("storage", "s", "local", "Define storage: local, s3, ssh, ftp, azure")
|
BackupCmd.PersistentFlags().StringP("storage", "s", "local", "Define storage: local, s3, ssh, ftp, azure")
|
||||||
BackupCmd.PersistentFlags().StringP("path", "P", "", "Storage path without file name. e.g: /custom_path or ssh remote path `/home/foo/backup`")
|
BackupCmd.PersistentFlags().StringP("path", "P", "", "Storage path without file name. e.g: /custom_path or ssh remote path `/home/foo/backup`")
|
||||||
BackupCmd.PersistentFlags().StringP("cron-expression", "e", "", "Backup cron expression (e.g., `0 0 * * *` or `@daily`)")
|
BackupCmd.PersistentFlags().StringP("cron-expression", "e", "", "Backup cron expression (e.g., `0 0 * * *` or `@daily`)")
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ var RestoreCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
//Restore
|
// Restore
|
||||||
RestoreCmd.PersistentFlags().StringP("file", "f", "", "File name of database")
|
RestoreCmd.PersistentFlags().StringP("file", "f", "", "File name of database")
|
||||||
RestoreCmd.PersistentFlags().StringP("storage", "s", "local", "Define storage: local, s3, ssh, ftp")
|
RestoreCmd.PersistentFlags().StringP("storage", "s", "local", "Define storage: local, s3, ssh, ftp")
|
||||||
RestoreCmd.PersistentFlags().StringP("path", "P", "", "AWS S3 path without file name. eg: /custom_path or ssh remote path `/home/foo/backup`")
|
RestoreCmd.PersistentFlags().StringP("path", "P", "", "AWS S3 path without file name. eg: /custom_path or ssh remote path `/home/foo/backup`")
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ var rootCmd = &cobra.Command{
|
|||||||
Example: utils.MainExample,
|
Example: utils.MainExample,
|
||||||
Version: appVersion,
|
Version: appVersion,
|
||||||
}
|
}
|
||||||
var operation = ""
|
|
||||||
|
|
||||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||||
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ func BackupDatabase(db *dbConfig, backupFileName string, disableCompression bool
|
|||||||
}
|
}
|
||||||
err = testDatabaseConnection(db)
|
err = testDatabaseConnection(db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf(err.Error())
|
return fmt.Errorf("failed to connect to the database: %v", err)
|
||||||
}
|
}
|
||||||
// Backup Database database
|
// Backup Database database
|
||||||
utils.Info("Backing up database...")
|
utils.Info("Backing up database...")
|
||||||
@@ -354,11 +354,11 @@ func recoverMode(err error, msg string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if backupRescueMode {
|
if backupRescueMode {
|
||||||
utils.NotifyError(fmt.Sprintf("%s : %v", msg, err))
|
utils.NotifyError(fmt.Sprintf("%s : %v", msg, err))
|
||||||
utils.Error(msg)
|
utils.Error("Error: %s", msg)
|
||||||
utils.Error("Backup rescue mode is enabled")
|
utils.Error("Backup rescue mode is enabled")
|
||||||
utils.Error("Backup will continue")
|
utils.Error("Backup will continue")
|
||||||
} else {
|
} else {
|
||||||
utils.Error(msg)
|
utils.Error("Error: %s", msg)
|
||||||
utils.Fatal("Error: %v", err)
|
utils.Fatal("Error: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,10 @@ func StartMigration(cmd *cobra.Command) {
|
|||||||
conf := &RestoreConfig{}
|
conf := &RestoreConfig{}
|
||||||
conf.file = backupFileName
|
conf.file = backupFileName
|
||||||
// Backup source Database
|
// Backup source Database
|
||||||
BackupDatabase(dbConf, backupFileName, true)
|
err := BackupDatabase(dbConf, backupFileName, true)
|
||||||
|
if err != nil {
|
||||||
|
utils.Fatal("Error backing up database: %s", err)
|
||||||
|
}
|
||||||
// Restore source database into target database
|
// Restore source database into target database
|
||||||
utils.Info("Restoring [%s] database into [%s] database...", dbConf.dbName, targetDbConf.targetDbName)
|
utils.Info("Restoring [%s] database into [%s] database...", dbConf.dbName, targetDbConf.targetDbName)
|
||||||
RestoreDatabase(&newDbConfig, conf)
|
RestoreDatabase(&newDbConfig, conf)
|
||||||
|
|||||||
@@ -118,7 +118,10 @@ func RestoreDatabase(db *dbConfig, conf *RestoreConfig) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
testDatabaseConnection(db)
|
err = testDatabaseConnection(db)
|
||||||
|
if err != nil {
|
||||||
|
utils.Fatal("Error connecting to the database %v", err)
|
||||||
|
}
|
||||||
utils.Info("Restoring database...")
|
utils.Info("Restoring database...")
|
||||||
|
|
||||||
extension := filepath.Ext(filepath.Join(tmpPath, conf.file))
|
extension := filepath.Ext(filepath.Join(tmpPath, conf.file))
|
||||||
|
|||||||
@@ -62,13 +62,6 @@ var tdbRVars = []string{
|
|||||||
var dbConf *dbConfig
|
var dbConf *dbConfig
|
||||||
var targetDbConf *targetDbConfig
|
var targetDbConf *targetDbConfig
|
||||||
|
|
||||||
// sshVars Required environment variables for SSH remote server storage
|
|
||||||
var sshVars = []string{
|
|
||||||
"SSH_USER",
|
|
||||||
"SSH_HOST_NAME",
|
|
||||||
"SSH_PORT",
|
|
||||||
"REMOTE_PATH",
|
|
||||||
}
|
|
||||||
var ftpVars = []string{
|
var ftpVars = []string{
|
||||||
"FTP_HOST_NAME",
|
"FTP_HOST_NAME",
|
||||||
"FTP_USER",
|
"FTP_USER",
|
||||||
|
|||||||
Reference in New Issue
Block a user