6
"github.com/wal-g/wal-g/internal/databases/greenplum"
8
"github.com/spf13/cobra"
9
"github.com/spf13/viper"
10
"github.com/wal-g/tracelog"
11
"github.com/wal-g/wal-g/internal"
12
conf "github.com/wal-g/wal-g/internal/config"
16
backupFetchShortDescription = "Fetches a backup from storage"
17
targetUserDataDescription = "Fetch storage backup which has the specified user data"
18
restorePointDescription = "Fetch storage backup w/ restore point specified by name"
19
restorePointTSDescription = "Fetch storage backup w/ restore point time less or equal to the provided timestamp"
20
restoreConfigPathDescription = "Path to the cluster restore configuration"
21
fetchContentIdsDescription = "If set, WAL-G will fetch only the specified segments"
22
fetchModeDescription = "Backup fetch mode. default: do the backup unpacking " +
23
"and prepare the configs [unpack+prepare], unpack: backup unpacking only, prepare: config preparation only."
24
inPlaceFlagDescription = "Perform the backup fetch in-place (without the restore config)"
25
restoreOnlyDescription = `[Experimental] Downloads only databases specified by passed names from default tablespace.
26
Always downloads system databases.`
29
var fetchTargetUserData string
30
var restorePointTS string
31
var restorePoint string
32
var restoreConfigPath string
33
var fetchContentIds *[]int
34
var fetchModeStr string
35
var inPlaceRestore bool
36
var partialRestoreArgs []string
38
var backupFetchCmd = &cobra.Command{
39
Use: "backup-fetch [backup_name | --target-user-data <data> | --restore-point <name>]",
40
Short: backupFetchShortDescription,
41
Args: cobra.RangeArgs(0, 1),
42
Run: func(cmd *cobra.Command, args []string) {
43
internal.ConfigureLimiters()
45
if !inPlaceRestore && restoreConfigPath == "" {
46
tracelog.ErrorLogger.Fatalf(
47
"No restore config was specified. Either specify one via the --restore-config flag or add the --in-place flag to restore in-place.")
50
if fetchTargetUserData == "" {
51
fetchTargetUserData = viper.GetString(conf.FetchTargetUserDataSetting)
54
storage, err := internal.ConfigureStorage()
55
tracelog.ErrorLogger.FatalOnError(err)
57
if restorePoint != "" && restorePointTS != "" {
58
tracelog.ErrorLogger.Fatalf("can't use both --restore-point and --restore-point-ts")
61
if restorePointTS != "" {
62
restorePoint, err = greenplum.FindRestorePointBeforeTS(restorePointTS, storage.RootFolder())
63
tracelog.ErrorLogger.FatalOnError(err)
66
targetBackupSelector, err := createTargetFetchBackupSelector(cmd, args, fetchTargetUserData, restorePoint)
67
tracelog.ErrorLogger.FatalOnError(err)
69
logsDir := viper.GetString(conf.GPLogsDirectory)
71
if len(*fetchContentIds) > 0 {
72
tracelog.InfoLogger.Printf("Will perform fetch operations only on the specified segments: %v", *fetchContentIds)
75
fetchMode, err := greenplum.NewBackupFetchMode(fetchModeStr)
76
tracelog.ErrorLogger.FatalOnError(err)
78
internal.HandleBackupFetch(storage.RootFolder(), targetBackupSelector,
79
greenplum.NewGreenplumBackupFetcher(restoreConfigPath, inPlaceRestore, logsDir, *fetchContentIds, fetchMode, restorePoint,
85
func createTargetFetchBackupSelector(cmd *cobra.Command,
86
args []string, targetUserData, restorePoint string) (internal.BackupSelector, error) {
94
if restorePoint != "" && targetUserData == "" && targetName == "" {
95
tracelog.InfoLogger.Printf("Restore point %s is specified without the backup name or target user data, "+
96
"will search for a matching backup", restorePoint)
97
return greenplum.NewRestorePointBackupSelector(restorePoint), nil
100
backupSelector, err := internal.NewTargetBackupSelector(targetUserData, targetName, greenplum.NewGenericMetaFetcher())
102
fmt.Println(cmd.UsageString())
105
return backupSelector, nil
109
backupFetchCmd.Flags().StringVar(&fetchTargetUserData, "target-user-data",
110
"", targetUserDataDescription)
111
backupFetchCmd.Flags().StringVar(&restorePointTS, "restore-point-ts", "", restorePointTSDescription)
112
backupFetchCmd.Flags().StringVar(&restorePoint, "restore-point", "", restorePointDescription)
113
backupFetchCmd.Flags().StringVar(&restoreConfigPath, "restore-config",
114
"", restoreConfigPathDescription)
115
backupFetchCmd.Flags().BoolVar(&inPlaceRestore, "in-place", false, inPlaceFlagDescription)
116
fetchContentIds = backupFetchCmd.Flags().IntSlice("content-ids", []int{}, fetchContentIdsDescription)
117
backupFetchCmd.Flags().StringSliceVar(&partialRestoreArgs, "restore-only", nil, restoreOnlyDescription)
119
backupFetchCmd.Flags().StringVar(&fetchModeStr, "mode", "default", fetchModeDescription)
120
cmd.AddCommand(backupFetchCmd)