@@ -86,15 +86,6 @@ func runBackupRestore(ctx context.Context) error {
86
86
destAppName = flag .FirstArg (ctx )
87
87
)
88
88
89
- enabled , err := isBackupEnabled (ctx , appName )
90
- if err != nil {
91
- return err
92
- }
93
-
94
- if ! enabled {
95
- return fmt .Errorf ("backups are not enabled. Run `fly pg backup enable -a %s` to enable them" , appName )
96
- }
97
-
98
89
flapsClient , err := flapsutil .NewClientWithOptions (ctx , flaps.NewClientOpts {
99
90
AppName : appName ,
100
91
})
@@ -111,17 +102,30 @@ func runBackupRestore(ctx context.Context) error {
111
102
return fmt .Errorf ("No active machines" )
112
103
}
113
104
114
- // Ensure the the app has the required flex version.
115
- if err := hasRequiredFlexVersionOnMachines (appName , machines , backupVersion ); err != nil {
105
+ // Resolve the leader
106
+ leader , err := pickLeader (ctx , machines )
107
+ if err != nil {
116
108
return err
117
109
}
118
110
119
- // Resolve the leader
120
- leader , err := pickLeader (ctx , machines )
111
+ if ! IsFlex (leader ) {
112
+ return fmt .Errorf ("backups are only supported on Flexclusters" )
113
+ }
114
+
115
+ enabled , err := isBackupEnabled (ctx , appName )
121
116
if err != nil {
122
117
return err
123
118
}
124
119
120
+ if ! enabled {
121
+ return fmt .Errorf ("backups are not enabled. Run `fly pg backup enable -a %s` to enable them" , appName )
122
+ }
123
+
124
+ // Ensure the the app has the required flex version.
125
+ if err := hasRequiredFlexVersionOnMachines (appName , machines , backupVersion ); err != nil {
126
+ return err
127
+ }
128
+
125
129
// TODO - Use this to create new Tigris access keys. However, if we can't yet revoke
126
130
// access keys after the restore process completes, we should understand the implications of
127
131
// creating potentially many access keys.
@@ -212,15 +216,6 @@ func runBackupCreate(ctx context.Context) error {
212
216
appName = appconfig .NameFromContext (ctx )
213
217
)
214
218
215
- enabled , err := isBackupEnabled (ctx , appName )
216
- if err != nil {
217
- return err
218
- }
219
-
220
- if ! enabled {
221
- return fmt .Errorf ("backups are not enabled. Run `fly pg backup enable -a %s` to enable them" , appName )
222
- }
223
-
224
219
flapsClient , err := flapsutil .NewClientWithOptions (ctx , flaps.NewClientOpts {
225
220
AppName : appName ,
226
221
})
@@ -237,16 +232,29 @@ func runBackupCreate(ctx context.Context) error {
237
232
return fmt .Errorf ("No active machines" )
238
233
}
239
234
240
- if err := hasRequiredFlexVersionOnMachines (appName , machines , backupVersion ); err != nil {
235
+ // Ensure the backup is issued against the primary.
236
+ leader , err := pickLeader (ctx , machines )
237
+ if err != nil {
241
238
return err
242
239
}
243
240
244
- // Ensure the backup is issued against the primary.
245
- leader , err := pickLeader (ctx , machines )
241
+ if ! IsFlex (leader ) {
242
+ return fmt .Errorf ("backups are only supported on Flexclusters" )
243
+ }
244
+
245
+ enabled , err := isBackupEnabled (ctx , appName )
246
246
if err != nil {
247
247
return err
248
248
}
249
249
250
+ if ! enabled {
251
+ return fmt .Errorf ("backups are not enabled. Run `fly pg backup enable -a %s` to enable them" , appName )
252
+ }
253
+
254
+ if err := hasRequiredFlexVersionOnMachines (appName , machines , backupVersion ); err != nil {
255
+ return err
256
+ }
257
+
250
258
if ! hasRequiredMemoryForBackup (* leader ) {
251
259
return fmt .Errorf ("backup creation requires at least 512MB of memory. Use `fly m update %s --vm-memory 512` to scale up." , leader .ID )
252
260
}
@@ -330,12 +338,16 @@ func runBackupEnable(ctx context.Context) error {
330
338
return fmt .Errorf ("No active machines" )
331
339
}
332
340
333
- if err := hasRequiredFlexVersionOnMachines (appName , machines , backupVersion ); err != nil {
341
+ leader , err := pickLeader (ctx , machines )
342
+ if err != nil {
334
343
return err
335
344
}
336
345
337
- leader , err := pickLeader (ctx , machines )
338
- if err != nil {
346
+ if ! IsFlex (leader ) {
347
+ return fmt .Errorf ("backups are only supported on Flexclusters" )
348
+ }
349
+
350
+ if err := hasRequiredFlexVersionOnMachines (appName , machines , backupVersion ); err != nil {
339
351
return err
340
352
}
341
353
@@ -397,23 +409,14 @@ func runBackupList(ctx context.Context) error {
397
409
appName = appconfig .NameFromContext (ctx )
398
410
)
399
411
400
- enabled , err := isBackupEnabled (ctx , appName )
401
- if err != nil {
402
- return err
403
- }
404
-
405
- if ! enabled {
406
- return fmt .Errorf ("backups are not enabled. Run `fly pg backup enable -a %s` to enable them" , appName )
407
- }
408
-
409
412
flapsClient , err := flapsutil .NewClientWithOptions (ctx , flaps.NewClientOpts {
410
413
AppName : appName ,
411
414
})
412
415
if err != nil {
413
416
return fmt .Errorf ("list of machines could not be retrieved: %w" , err )
414
417
}
415
418
416
- machines , err := flapsClient .List (ctx , "started" )
419
+ machines , err := flapsClient .ListActive (ctx )
417
420
if err != nil {
418
421
return err
419
422
}
@@ -422,11 +425,24 @@ func runBackupList(ctx context.Context) error {
422
425
return fmt .Errorf ("No active machines" )
423
426
}
424
427
425
- if err = hasRequiredFlexVersionOnMachines (appName , machines , backupVersion ); err != nil {
428
+ machine := machines [0 ]
429
+
430
+ if ! IsFlex (machine ) {
431
+ return fmt .Errorf ("backups are only supported on Flexclusters" )
432
+ }
433
+
434
+ enabled , err := isBackupEnabled (ctx , appName )
435
+ if err != nil {
426
436
return err
427
437
}
428
438
429
- machine := machines [0 ]
439
+ if ! enabled {
440
+ return fmt .Errorf ("backups are not enabled. Run `fly pg backup enable -a %s` to enable them" , appName )
441
+ }
442
+
443
+ if err = hasRequiredFlexVersionOnMachines (appName , machines , backupVersion ); err != nil {
444
+ return err
445
+ }
430
446
431
447
return ExecOnMachine (ctx , flapsClient , machine .ID , "flexctl backup list" )
432
448
}
@@ -540,15 +556,6 @@ func runBackupConfigShow(ctx context.Context) error {
540
556
appName = appconfig .NameFromContext (ctx )
541
557
)
542
558
543
- enabled , err := isBackupEnabled (ctx , appName )
544
- if err != nil {
545
- return err
546
- }
547
-
548
- if ! enabled {
549
- return fmt .Errorf ("backups are not enabled. Run `fly pg backup enable -a %s` to enable them" , appName )
550
- }
551
-
552
559
flapsClient , err := flapsutil .NewClientWithOptions (ctx , flaps.NewClientOpts {
553
560
AppName : appName ,
554
561
})
@@ -565,6 +572,19 @@ func runBackupConfigShow(ctx context.Context) error {
565
572
return fmt .Errorf ("No active machines" )
566
573
}
567
574
575
+ if ! IsFlex (machines [0 ]) {
576
+ return fmt .Errorf ("backups are only supported on Flexclusters" )
577
+ }
578
+
579
+ enabled , err := isBackupEnabled (ctx , appName )
580
+ if err != nil {
581
+ return err
582
+ }
583
+
584
+ if ! enabled {
585
+ return fmt .Errorf ("backups are not enabled. Run `fly pg backup enable -a %s` to enable them" , appName )
586
+ }
587
+
568
588
// Ensure the the app has the required flex version.
569
589
if err := hasRequiredFlexVersionOnMachines (appName , machines , backupConfigVersion ); err != nil {
570
590
return err
@@ -594,6 +614,10 @@ func runBackupConfigUpdate(ctx context.Context) error {
594
614
return fmt .Errorf ("No active machines" )
595
615
}
596
616
617
+ if ! IsFlex (machines [0 ]) {
618
+ return fmt .Errorf ("backups are only supported on Flexclusters" )
619
+ }
620
+
597
621
// Ensure the the app has the required flex version.
598
622
if err := hasRequiredFlexVersionOnMachines (appName , machines , backupConfigVersion ); err != nil {
599
623
return err
0 commit comments