MCPcopy Create free account
hub / github.com/Scalingo/cli / BackupsConfiguration

Function BackupsConfiguration

db/backups_config.go:16–46  ·  view source on GitHub ↗
(ctx context.Context, app, addon string, params scalingo.DatabaseUpdatePeriodicBackupsConfigParams)

Source from the content-addressed store, hash-verified

14)
15
16func 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
48func formatScheduledAt(hours []int) string {
49 hoursStr := make([]string, len(hours))

Callers 1

databases.goFile · 0.92

Calls 4

ScalingoClientFunction · 0.92
StatusfFunction · 0.92
StatusFunction · 0.92
formatScheduledAtFunction · 0.85

Tested by

no test coverage detected