(ctx context.Context, app, addon string, params scalingo.DatabaseUpdatePeriodicBackupsConfigParams)
| 14 | ) |
| 15 | |
| 16 | func BackupsConfiguration(ctx context.Context, app, addon string, params scalingo.DatabaseUpdatePeriodicBackupsConfigParams) error { |
| 17 | client, err := config.ScalingoClient(ctx) |
| 18 | if err != nil { |
| 19 | return errors.Wrapf(ctx, err, "fail to get Scalingo client") |
| 20 | } |
| 21 | |
| 22 | db, err := client.DatabaseShow(ctx, app, addon) |
| 23 | if err != nil { |
| 24 | return errors.Wrapf(ctx, err, "fail to get database current configuration") |
| 25 | } |
| 26 | |
| 27 | if params.ScheduledAt != nil && len(db.PeriodicBackupsScheduledAt) > 1 { |
| 28 | msg := "Your database is backed up multiple times a day at " + |
| 29 | formatScheduledAt(db.PeriodicBackupsScheduledAt) + |
| 30 | ". Please ask the support to update the frequency of these backups." |
| 31 | return errors.New(ctx, msg) |
| 32 | } |
| 33 | |
| 34 | db, err = client.DatabaseUpdatePeriodicBackupsConfig(ctx, app, addon, params) |
| 35 | if err != nil { |
| 36 | return errors.Wrapf(ctx, err, "fail to configure the periodic backups") |
| 37 | } |
| 38 | |
| 39 | if db.PeriodicBackupsEnabled { |
| 40 | io.Statusf("Periodic backups will be done daily at %s\n", formatScheduledAt(db.PeriodicBackupsScheduledAt)) |
| 41 | } else { |
| 42 | io.Status("Periodic backups are disabled") |
| 43 | } |
| 44 | |
| 45 | return nil |
| 46 | } |
| 47 | |
| 48 | func formatScheduledAt(hours []int) string { |
| 49 | hoursStr := make([]string, len(hours)) |
no test coverage detected