Skip to content

Commit

Permalink
[PLAT-15369][YBA CLI]Backup list-increments doesn't support pretty/js…
Browse files Browse the repository at this point in the history
…on outputs

Summary: The common backup info had formatter described only for table layout. Changed the structure to support JSON and YAML

Test Plan:
```
./yba backup list-increments --backup-uuid 7251123c-4c27-44ec-8401-ba08b439a9d4 -o pretty

[
  {
    "backupUUID": "7251123c-4c27-44ec-8401-ba08b439a9d4",
    "baseBackupUUID": "7251123c-4c27-44ec-8401-ba08b439a9d4",
    "completionTime": "2024-08-26T11:35:45Z",
    "createTime": "2024-08-26T11:35:17Z",
    "kmsConfigUUID": "",
    "responseList": [
      {
        "allTables": true,
        "backupPointInTimeRestoreWindow": {
          "timestampRetentionWindowEndMillis": 0,
          "timestampRetentionWindowStartMillis": 0
        },
        "backupSizeInBytes": 3053549,
        "defaultLocation": "s3://dkumar-test/univ-8c398f38-5e18-4242-83f2-185c2127d5d6/ybc_backup-7251123c4c2744ec8401ba08b439a9d4/full/2024-08-26T11:35:17/multi-table-postgres_4ad4ee9937a2464b8d6c644bc0f1d1dd",
        "keyspace": "postgres",
        "perRegionLocations": null,
        "tableUUIDList": [],
        "tablesList": []
      }
    ],
    "sse": true,
    "state": "Completed",
    "storageConfigUUID": "ed40cbf8-576b-4517-88c5-a7bb4e876363",
    "tableByTableBackup": false,
    "taskUUID": "dee5c208-fa32-492c-9996-67c2484a54c7",
    "totalBackupSizeInBytes": 3053549,
    "updateTime": "2024-08-26T11:35:59Z"
  }
]
```

Reviewers: skurapati

Reviewed By: skurapati

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D38192
  • Loading branch information
Deepti-yb committed Sep 19, 2024
1 parent f4a002a commit 29c56ed
Show file tree
Hide file tree
Showing 6 changed files with 354 additions and 256 deletions.
30 changes: 20 additions & 10 deletions managed/yba-cli/cmd/backup/list_incremental_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/yugabyte/yugabyte-db/managed/yba-cli/cmd/util"
ybaAuthClient "github.com/yugabyte/yugabyte-db/managed/yba-cli/internal/client"
"github.com/yugabyte/yugabyte-db/managed/yba-cli/internal/formatter"
"github.com/yugabyte/yugabyte-db/managed/yba-cli/internal/formatter/backup"
"github.com/yugabyte/yugabyte-db/managed/yba-cli/internal/formatter/backup/commonbackupinfo"
)

// listIncrementalBackupsCmd represents the universe backup command
Expand Down Expand Up @@ -58,22 +58,32 @@ var listIncrementalBackupsCmd = &cobra.Command{
logrus.Fatalf(formatter.Colorize(errMessage.Error()+"\n", formatter.RedColor))
}

backup.StorageConfigs = make([]ybaclient.CustomerConfigUI, 0)
commonbackupinfo.StorageConfigs = make([]ybaclient.CustomerConfigUI, 0)
for _, s := range rList {
if strings.Compare(s.GetType(), util.StorageCustomerConfigType) == 0 {
backup.StorageConfigs = append(backup.StorageConfigs, s)
commonbackupinfo.StorageConfigs = append(commonbackupinfo.StorageConfigs, s)
}
}

commonBackupInfoContext := *backup.NewCommonBackupInfoContext()
commonBackupInfoContext.Output = os.Stdout
commonBackupInfoContext.Format = backup.NewCommonBackupInfoFormat(viper.GetString("output"))
for index, value := range r {
commonBackupInfoContext.SetCommonBackupInfo(value)
commonBackupInfoContext.Write(index)
if len(r) > 0 && util.IsOutputType(formatter.TableFormatKey) {
fullCommonBackupInfoContext := *commonbackupinfo.NewFullCommonBackupInfoContext()
fullCommonBackupInfoContext.Output = os.Stdout
fullCommonBackupInfoContext.Format = commonbackupinfo.NewFullCommonBackupInfoFormat(
viper.GetString("output"))
for i, cbi := range r {
fullCommonBackupInfoContext.SetFullCommonBackupInfo(cbi)
fullCommonBackupInfoContext.Write(i)
}

return
}
return

commonBackupInfoCtx := formatter.Context{
Command: "list",
Output: os.Stdout,
Format: commonbackupinfo.NewCommonBackupInfoFormat(viper.GetString("output")),
}
commonbackupinfo.Write(commonBackupInfoCtx, r)
},
}

Expand Down
36 changes: 21 additions & 15 deletions managed/yba-cli/internal/formatter/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,25 @@ const (
"\t{{.StorageConfig}}\t{{.StorageConfigType}}\t{{.BackupType}}" +
"\t{{.State}}\t{{.CompletionTime}}"

backupUUIDHeader = "Backup UUID"
// BackupUUIDHeader to display backup UUID
BackupUUIDHeader = "Backup UUID"
baseBackupUUIDHeader = "Base Backup UUID"
// UniverseHeader to display universe UUID and Name
UniverseHeader = "Universe"
storageConfigHeader = "Storage Configuration"
storageConfigTypeHeader = "Storage Configuration Type"
backupTypeHeader = "Backup Type"
UniverseHeader = "Universe"
// StorageConfigHeader to display storage config
StorageConfigHeader = "Storage Configuration"
storageConfigTypeHeader = "Storage Configuration Type"
// BackupTypeHeader to display backup type
BackupTypeHeader = "Backup Type"
scheduleNameHeader = "Schedule Name"
hasIncrementalBackupsHeader = "Has Incremental Backups"
stateHeader = "State"
expiryTimeHeader = "Expiry Time"
createTimeHeader = "Create Time"
completionTimeHeader = "Completion Time"
// StateHeader to display state
StateHeader = "State"
expiryTimeHeader = "Expiry Time"
// CreateTimeHeader to display create time
CreateTimeHeader = "Create Time"
// CompletionTimeHeader to display completion time
CompletionTimeHeader = "Completion Time"
)

// Context for BackupResp outputs
Expand Down Expand Up @@ -95,18 +101,18 @@ func Write(ctx formatter.Context, backups []ybaclient.BackupResp) error {
func NewBackupContext() *Context {
backupCtx := Context{}
backupCtx.Header = formatter.SubHeaderContext{
"BackupUUID": backupUUIDHeader,
"BackupUUID": BackupUUIDHeader,
"BaseBackupUUID": baseBackupUUIDHeader,
"Universe": UniverseHeader,
"StorageConfig": storageConfigHeader,
"StorageConfig": StorageConfigHeader,
"StorageConfigType": storageConfigTypeHeader,
"BackupType": backupTypeHeader,
"BackupType": BackupTypeHeader,
"ScheduleName": scheduleNameHeader,
"HasIncrementalBackups": hasIncrementalBackupsHeader,
"State": stateHeader,
"State": StateHeader,
"ExpiryTime": expiryTimeHeader,
"CreateTime": createTimeHeader,
"CompletionTime": completionTimeHeader,
"CreateTime": CreateTimeHeader,
"CompletionTime": CompletionTimeHeader,
}
return &backupCtx
}
Expand Down
223 changes: 0 additions & 223 deletions managed/yba-cli/internal/formatter/backup/common_backup_info.go

This file was deleted.

Loading

0 comments on commit 29c56ed

Please sign in to comment.