-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for db restore for postgres (#338)
Signed-off-by: Vishal Anarse <vishal@civo.com> Co-authored-by: Vishal Anarse <vishal@civo.com>
- Loading branch information
1 parent
9852272
commit 5885a7a
Showing
5 changed files
with
89 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package database | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/civo/civogo" | ||
"github.com/civo/cli/common" | ||
"github.com/civo/cli/config" | ||
"github.com/civo/cli/utility" | ||
|
||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var backup string | ||
|
||
var dbRestoreCmd = &cobra.Command{ | ||
Use: "restore", | ||
Aliases: []string{"reset", "restores"}, | ||
Short: "Restore a database", | ||
Example: "civo db restore <DATABASE-NAME/ID> --backup <BACKUP-NAME>", | ||
Args: cobra.MinimumNArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
utility.EnsureCurrentRegion() | ||
|
||
client, err := config.CivoAPIClient() | ||
if err != nil { | ||
utility.Error("Creating the connection to Civo's API failed with %s", err) | ||
os.Exit(1) | ||
} | ||
|
||
if common.RegionSet != "" { | ||
client.Region = common.RegionSet | ||
} | ||
|
||
db, err := client.FindDatabase(args[0]) | ||
if err != nil { | ||
utility.Error("Database %s", err) | ||
os.Exit(1) | ||
} | ||
|
||
if utility.UserConfirmedRestore(db.Name, common.DefaultYes, backup) { | ||
config := &civogo.RestoreDatabaseRequest{ | ||
Software: db.Software, | ||
Backup: backup, | ||
} | ||
_, err = client.RestoreDatabase(db.ID, config) | ||
if err != nil { | ||
utility.Error("%s", err) | ||
os.Exit(1) | ||
} | ||
ow := utility.NewOutputWriter() | ||
switch common.OutputFormat { | ||
case "json": | ||
ow.WriteSingleObjectJSON(common.PrettySet) | ||
case "custom": | ||
ow.WriteCustomOutput(common.OutputFields) | ||
default: | ||
fmt.Printf("Restoring database %s from from backup %s\n", utility.Green(db.Name), utility.Green(backup)) | ||
} | ||
} else { | ||
fmt.Println("Aborted") | ||
} | ||
|
||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters