@@ -92,14 +92,13 @@ func deleteBackupByName(ctx context.Context, pbm sdk.Client, d *deleteBcpOpts) (
92
92
return sdk .NoOpID , errors .Wrap (err , "backup cannot be deleted" )
93
93
}
94
94
95
- fmt .Println (shortBcpInfo (bcp ))
96
- if bcp .Type == sdk .IncrementalBackup {
97
- for _ , increments := range bcp .Increments {
98
- for _ , inc := range increments {
99
- fmt .Println (shortBcpInfo (inc ))
100
- }
95
+ allBackups := []sdk.BackupMetadata {* bcp }
96
+ for _ , increments := range bcp .Increments {
97
+ for _ , inc := range increments {
98
+ allBackups = append (allBackups , * inc )
101
99
}
102
100
}
101
+ printDeleteInfoTo (os .Stdout , allBackups , nil )
103
102
104
103
if d .dryRun {
105
104
return sdk .NoOpID , nil
@@ -136,9 +135,7 @@ func deleteManyBackup(ctx context.Context, pbm sdk.Client, d *deleteBcpOpts) (sd
136
135
return sdk .NoOpID , errors .Wrap (err , "fetch backup list" )
137
136
}
138
137
139
- for i := range backups {
140
- fmt .Println (shortBcpInfo (& backups [i ]))
141
- }
138
+ printDeleteInfoTo (os .Stdout , backups , nil )
142
139
143
140
if d .dryRun {
144
141
return sdk .NoOpID , nil
@@ -153,20 +150,6 @@ func deleteManyBackup(ctx context.Context, pbm sdk.Client, d *deleteBcpOpts) (sd
153
150
return cid , errors .Wrap (err , "schedule delete" )
154
151
}
155
152
156
- func shortBcpInfo (bcp * sdk.BackupMetadata ) string {
157
- size := fmtSize (bcp .Size )
158
-
159
- t := string (bcp .Type )
160
- if bcp .Type == sdk .LogicalBackup && len (bcp .Namespaces ) != 0 {
161
- t += ", selective"
162
- } else if bcp .Type == defs .IncrementalBackup && bcp .SrcBackup == "" {
163
- t += ", base"
164
- }
165
-
166
- restoreTime := time .Unix (int64 (bcp .LastWriteTS .T ), 0 ).UTC ().Format (time .RFC3339 )
167
- return fmt .Sprintf ("%q [size: %s type: <%s>, restore time: %s]" , bcp .Name , size , t , restoreTime )
168
- }
169
-
170
153
type deletePitrOpts struct {
171
154
olderThan string
172
155
yes bool
@@ -251,14 +234,13 @@ func doCleanup(ctx context.Context, conn connect.Client, pbm sdk.Client, d *clea
251
234
return outMsg {"nothing to delete" }, nil
252
235
}
253
236
237
+ printDeleteInfoTo (os .Stdout , info .Backups , info .Chunks )
238
+
254
239
if d .dryRun {
255
- b := & strings.Builder {}
256
- printCleanupInfoTo (b , info .Backups , info .Chunks )
257
- return b , nil
240
+ return nil , nil
258
241
}
259
-
260
242
if ! d .yes {
261
- if err := askCleanupConfirmation ( info ); err != nil {
243
+ if err := askConfirmation ( "Are you sure you want to delete?" ); err != nil {
262
244
if errors .Is (err , errUserCanceled ) {
263
245
return outMsg {err .Error ()}, nil
264
246
}
@@ -319,19 +301,22 @@ func parseDuration(s string) (time.Duration, error) {
319
301
return time .Duration (d * 24 * int64 (time .Hour )), nil
320
302
}
321
303
322
- func printCleanupInfoTo (w io.Writer , backups []backup.BackupMeta , chunks []oplog.OplogChunk ) {
304
+ func printDeleteInfoTo (w io.Writer , backups []backup.BackupMeta , chunks []oplog.OplogChunk ) {
323
305
if len (backups ) != 0 {
324
306
fmt .Fprintln (w , "Snapshots:" )
325
307
for i := range backups {
326
308
bcp := & backups [i ]
309
+
327
310
t := string (bcp .Type )
328
- if util . IsSelective (bcp .Namespaces ) {
311
+ if bcp . Type == sdk . LogicalBackup && len (bcp .Namespaces ) != 0 {
329
312
t += ", selective"
330
313
} else if bcp .Type == defs .IncrementalBackup && bcp .SrcBackup == "" {
331
314
t += ", base"
332
315
}
333
- fmt .Fprintf (w , " - %s <%s> [restore_time: %s]\n " ,
334
- bcp .Name , t , fmtTS (int64 (bcp .LastWriteTS .T )))
316
+
317
+ restoreTime := time .Unix (int64 (bcp .LastWriteTS .T ), 0 ).UTC ().Format (time .RFC3339 )
318
+ fmt .Fprintf (w , " - %q [size: %s type: <%s>, restore time: %s]" ,
319
+ bcp .Name , fmtSize (bcp .Size ), t , restoreTime )
335
320
}
336
321
}
337
322
@@ -371,11 +356,6 @@ func printCleanupInfoTo(w io.Writer, backups []backup.BackupMeta, chunks []oplog
371
356
}
372
357
}
373
358
374
- func askCleanupConfirmation (info backup.CleanupInfo ) error {
375
- printCleanupInfoTo (os .Stdout , info .Backups , info .Chunks )
376
- return askConfirmation ("Are you sure you want to delete?" )
377
- }
378
-
379
359
var errUserCanceled = errors .New ("canceled" )
380
360
381
361
func askConfirmation (question string ) error {
0 commit comments