-
-
Notifications
You must be signed in to change notification settings - Fork 222
/
backups.go
733 lines (603 loc) · 20.3 KB
/
backups.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
//go:build linux && cgo && !agent
package db
import (
"context"
"database/sql"
"fmt"
"net/http"
"time"
"github.com/lxc/incus/v6/internal/server/db/query"
"github.com/lxc/incus/v6/shared/api"
"github.com/lxc/incus/v6/shared/logger"
)
// InstanceBackup is a value object holding all db-related details about an instance backup.
type InstanceBackup struct {
ID int
InstanceID int
Name string
CreationDate time.Time
ExpiryDate time.Time
InstanceOnly bool
OptimizedStorage bool
CompressionAlgorithm string
}
// StoragePoolVolumeBackup is a value object holding all db-related details about a storage volume backup.
type StoragePoolVolumeBackup struct {
ID int
VolumeID int64
Name string
CreationDate time.Time
ExpiryDate time.Time
VolumeOnly bool
OptimizedStorage bool
CompressionAlgorithm string
}
// StoragePoolBucketBackup is a value object holding all db-related details about a storage bucket backup.
type StoragePoolBucketBackup struct {
ID int
BucketID int64
Name string
CreationDate time.Time
ExpiryDate time.Time
CompressionAlgorithm string
}
// Returns the ID of the instance backup with the given name.
func (c *ClusterTx) getInstanceBackupID(ctx context.Context, name string) (int, error) {
q := "SELECT id FROM instances_backups WHERE name=?"
id := -1
arg1 := []any{name}
arg2 := []any{&id}
err := dbQueryRowScan(ctx, c, q, arg1, arg2)
if err == sql.ErrNoRows {
return -1, api.StatusErrorf(http.StatusNotFound, "Instance backup not found")
}
return id, err
}
// GetInstanceBackup returns the backup with the given name.
func (c *ClusterTx) GetInstanceBackup(ctx context.Context, projectName string, name string) (InstanceBackup, error) {
args := InstanceBackup{}
args.Name = name
instanceOnlyInt := -1
optimizedStorageInt := -1
q := `
SELECT instances_backups.id, instances_backups.instance_id,
instances_backups.creation_date, instances_backups.expiry_date,
instances_backups.container_only, instances_backups.optimized_storage
FROM instances_backups
JOIN instances ON instances.id=instances_backups.instance_id
JOIN projects ON projects.id=instances.project_id
WHERE projects.name=? AND instances_backups.name=?
`
arg1 := []any{projectName, name}
arg2 := []any{&args.ID, &args.InstanceID, &args.CreationDate,
&args.ExpiryDate, &instanceOnlyInt, &optimizedStorageInt}
err := dbQueryRowScan(ctx, c, q, arg1, arg2)
if err != nil {
if err == sql.ErrNoRows {
return args, api.StatusErrorf(http.StatusNotFound, "Instance backup not found")
}
return args, err
}
if instanceOnlyInt == 1 {
args.InstanceOnly = true
}
if optimizedStorageInt == 1 {
args.OptimizedStorage = true
}
return args, nil
}
// GetInstanceBackupWithID returns the backup with the given ID.
func (c *ClusterTx) GetInstanceBackupWithID(ctx context.Context, backupID int) (InstanceBackup, error) {
args := InstanceBackup{}
args.ID = backupID
instanceOnlyInt := -1
optimizedStorageInt := -1
q := `
SELECT instances_backups.name, instances_backups.instance_id,
instances_backups.creation_date, instances_backups.expiry_date,
instances_backups.container_only, instances_backups.optimized_storage
FROM instances_backups
JOIN instances ON instances.id=instances_backups.instance_id
JOIN projects ON projects.id=instances.project_id
WHERE instances_backups.id=?
`
arg1 := []any{backupID}
arg2 := []any{&args.Name, &args.InstanceID, &args.CreationDate,
&args.ExpiryDate, &instanceOnlyInt, &optimizedStorageInt}
err := dbQueryRowScan(ctx, c, q, arg1, arg2)
if err != nil {
if err == sql.ErrNoRows {
return args, api.StatusErrorf(http.StatusNotFound, "Instance backup not found")
}
return args, err
}
if instanceOnlyInt == 1 {
args.InstanceOnly = true
}
if optimizedStorageInt == 1 {
args.OptimizedStorage = true
}
return args, nil
}
// GetInstanceBackups returns the names of all backups of the instance with the
// given name.
func (c *ClusterTx) GetInstanceBackups(ctx context.Context, projectName string, name string) ([]string, error) {
var result []string
q := `SELECT instances_backups.name FROM instances_backups
JOIN instances ON instances_backups.instance_id=instances.id
JOIN projects ON projects.id=instances.project_id
WHERE projects.name=? AND instances.name=?`
inargs := []any{projectName, name}
outfmt := []any{name}
dbResults, err := queryScan(ctx, c, q, inargs, outfmt)
if err != nil {
return nil, err
}
for _, r := range dbResults {
result = append(result, r[0].(string))
}
return result, nil
}
// CreateInstanceBackup creates a new backup.
func (c *ClusterTx) CreateInstanceBackup(ctx context.Context, args InstanceBackup) error {
_, err := c.getInstanceBackupID(ctx, args.Name)
if err == nil {
return ErrAlreadyDefined
}
instanceOnlyInt := 0
if args.InstanceOnly {
instanceOnlyInt = 1
}
optimizedStorageInt := 0
if args.OptimizedStorage {
optimizedStorageInt = 1
}
str := "INSERT INTO instances_backups (instance_id, name, creation_date, expiry_date, container_only, optimized_storage) VALUES (?, ?, ?, ?, ?, ?)"
stmt, err := c.tx.Prepare(str)
if err != nil {
return err
}
defer func() { _ = stmt.Close() }()
result, err := stmt.Exec(args.InstanceID, args.Name,
args.CreationDate.Unix(), args.ExpiryDate.Unix(), instanceOnlyInt,
optimizedStorageInt)
if err != nil {
return err
}
_, err = result.LastInsertId()
if err != nil {
return fmt.Errorf("Error inserting %q into database", args.Name)
}
return nil
}
// DeleteInstanceBackup removes the instance backup with the given name from the database.
func (c *ClusterTx) DeleteInstanceBackup(ctx context.Context, name string) error {
id, err := c.getInstanceBackupID(ctx, name)
if err != nil {
return err
}
_, err = c.tx.ExecContext(ctx, "DELETE FROM instances_backups WHERE id=?", id)
if err != nil {
return err
}
return nil
}
// RenameInstanceBackup renames an instance backup from the given current name
// to the new one.
func (c *ClusterTx) RenameInstanceBackup(ctx context.Context, oldName, newName string) error {
str := "UPDATE instances_backups SET name = ? WHERE name = ?"
stmt, err := c.tx.PrepareContext(ctx, str)
if err != nil {
return err
}
defer func() { _ = stmt.Close() }()
logger.Debug(
"Calling SQL Query",
logger.Ctx{
"query": "UPDATE instances_backups SET name = ? WHERE name = ?",
"oldName": oldName,
"newName": newName})
_, err = stmt.ExecContext(ctx, newName, oldName)
if err != nil {
return err
}
return nil
}
// GetExpiredInstanceBackups returns a list of expired instance backups.
func (c *ClusterTx) GetExpiredInstanceBackups(ctx context.Context) ([]InstanceBackup, error) {
var result []InstanceBackup
var name string
var expiryDate string
var instanceID int
q := `SELECT instances_backups.name, instances_backups.expiry_date, instances_backups.instance_id FROM instances_backups`
outfmt := []any{name, expiryDate, instanceID}
dbResults, err := queryScan(ctx, c, q, nil, outfmt)
if err != nil {
return nil, err
}
for _, r := range dbResults {
timestamp := r[1]
var backupExpiry time.Time
err = backupExpiry.UnmarshalText([]byte(timestamp.(string)))
if err != nil {
return []InstanceBackup{}, err
}
// Since zero time causes some issues due to timezones, we check the
// unix timestamp instead of IsZero().
if backupExpiry.Unix() <= 0 {
// Backup doesn't expire
continue
}
// Backup has expired
if time.Now().Unix()-backupExpiry.Unix() >= 0 {
result = append(result, InstanceBackup{
Name: r[0].(string),
InstanceID: r[2].(int),
ExpiryDate: backupExpiry,
})
}
}
return result, nil
}
// GetExpiredStorageVolumeBackups returns a list of expired storage volume backups.
func (c *ClusterTx) GetExpiredStorageVolumeBackups(ctx context.Context) ([]StoragePoolVolumeBackup, error) {
var backups []StoragePoolVolumeBackup
q := `SELECT storage_volumes_backups.name, storage_volumes_backups.expiry_date, storage_volumes_backups.storage_volume_id FROM storage_volumes_backups`
err := query.Scan(ctx, c.Tx(), q, func(scan func(dest ...any) error) error {
var b StoragePoolVolumeBackup
var expiryTime sql.NullTime
err := scan(&b.Name, &expiryTime, &b.VolumeID)
if err != nil {
return err
}
b.ExpiryDate = expiryTime.Time // Convert nulls to zero.
// Since zero time causes some issues due to timezones, we check the
// unix timestamp instead of IsZero().
if b.ExpiryDate.Unix() <= 0 {
// Backup doesn't expire
return nil
}
// Backup has expired
if time.Now().Unix()-b.ExpiryDate.Unix() >= 0 {
backups = append(backups, b)
}
return nil
})
if err != nil {
return nil, err
}
return backups, nil
}
// GetStoragePoolVolumeBackups returns a list of volume backups.
func (c *ClusterTx) GetStoragePoolVolumeBackups(ctx context.Context, projectName string, volumeName string, poolID int64) ([]StoragePoolVolumeBackup, error) {
q := `
SELECT
backups.id,
backups.storage_volume_id,
backups.name,
backups.creation_date,
backups.expiry_date,
backups.volume_only,
backups.optimized_storage
FROM storage_volumes_backups AS backups
JOIN storage_volumes ON storage_volumes.id=backups.storage_volume_id
JOIN projects ON projects.id=storage_volumes.project_id
WHERE projects.name=? AND storage_volumes.name=? AND storage_volumes.storage_pool_id=?
ORDER BY backups.id
`
var backups []StoragePoolVolumeBackup
err := query.Scan(ctx, c.tx, q, func(scan func(dest ...any) error) error {
var b StoragePoolVolumeBackup
var expiryTime sql.NullTime
err := scan(&b.ID, &b.VolumeID, &b.Name, &b.CreationDate, &expiryTime, &b.VolumeOnly, &b.OptimizedStorage)
if err != nil {
return err
}
b.ExpiryDate = expiryTime.Time // Convert nulls to zero.
backups = append(backups, b)
return nil
}, projectName, volumeName, poolID)
if err != nil {
return nil, err
}
return backups, nil
}
// GetStoragePoolVolumeBackupsNames returns the names of all backups of the storage volume with the given name.
func (c *ClusterTx) GetStoragePoolVolumeBackupsNames(ctx context.Context, projectName string, volumeName string, poolID int64) ([]string, error) {
var result []string
q := `SELECT storage_volumes_backups.name FROM storage_volumes_backups
JOIN storage_volumes ON storage_volumes_backups.storage_volume_id=storage_volumes.id
JOIN projects ON projects.id=storage_volumes.project_id
WHERE projects.name=? AND storage_volumes.name=?
ORDER BY storage_volumes_backups.id`
inargs := []any{projectName, volumeName}
outfmt := []any{volumeName}
dbResults, err := queryScan(ctx, c, q, inargs, outfmt)
if err != nil {
return nil, err
}
for _, r := range dbResults {
result = append(result, r[0].(string))
}
return result, nil
}
// CreateStoragePoolVolumeBackup creates a new storage volume backup.
func (c *ClusterTx) CreateStoragePoolVolumeBackup(ctx context.Context, args StoragePoolVolumeBackup) error {
_, err := c.getStoragePoolVolumeBackupID(ctx, args.Name)
if err == nil {
return ErrAlreadyDefined
}
volumeOnlyInt := 0
if args.VolumeOnly {
volumeOnlyInt = 1
}
optimizedStorageInt := 0
if args.OptimizedStorage {
optimizedStorageInt = 1
}
str := "INSERT INTO storage_volumes_backups (storage_volume_id, name, creation_date, expiry_date, volume_only, optimized_storage) VALUES (?, ?, ?, ?, ?, ?)"
stmt, err := c.tx.Prepare(str)
if err != nil {
return err
}
defer func() { _ = stmt.Close() }()
result, err := stmt.Exec(args.VolumeID, args.Name,
args.CreationDate.Unix(), args.ExpiryDate.Unix(), volumeOnlyInt,
optimizedStorageInt)
if err != nil {
return err
}
_, err = result.LastInsertId()
if err != nil {
return fmt.Errorf("Error inserting %q into database", args.Name)
}
return nil
}
// Returns the ID of the storage volume backup with the given name.
func (c *ClusterTx) getStoragePoolVolumeBackupID(ctx context.Context, name string) (int, error) {
q := "SELECT id FROM storage_volumes_backups WHERE name=?"
id := -1
arg1 := []any{name}
arg2 := []any{&id}
err := dbQueryRowScan(ctx, c, q, arg1, arg2)
if err == sql.ErrNoRows {
return -1, api.StatusErrorf(http.StatusNotFound, "Storage volume backup not found")
}
return id, err
}
// DeleteStoragePoolVolumeBackup removes the storage volume backup with the given name from the database.
func (c *ClusterTx) DeleteStoragePoolVolumeBackup(ctx context.Context, name string) error {
id, err := c.getStoragePoolVolumeBackupID(ctx, name)
if err != nil {
return err
}
_, err = c.tx.ExecContext(ctx, "DELETE FROM storage_volumes_backups WHERE id=?", id)
if err != nil {
return err
}
return nil
}
// GetStoragePoolVolumeBackup returns the volume backup with the given name.
func (c *ClusterTx) GetStoragePoolVolumeBackup(ctx context.Context, projectName string, poolName string, backupName string) (StoragePoolVolumeBackup, error) {
args := StoragePoolVolumeBackup{}
q := `
SELECT
backups.id,
backups.storage_volume_id,
backups.name,
backups.creation_date,
backups.expiry_date,
backups.volume_only,
backups.optimized_storage
FROM storage_volumes_backups AS backups
JOIN storage_volumes ON storage_volumes.id=backups.storage_volume_id
JOIN projects ON projects.id=storage_volumes.project_id
WHERE projects.name=? AND backups.name=?
`
arg1 := []any{projectName, backupName}
outfmt := []any{&args.ID, &args.VolumeID, &args.Name, &args.CreationDate, &args.ExpiryDate, &args.VolumeOnly, &args.OptimizedStorage}
err := dbQueryRowScan(ctx, c, q, arg1, outfmt)
if err != nil {
if err == sql.ErrNoRows {
return args, api.StatusErrorf(http.StatusNotFound, "Storage volume backup not found")
}
return args, err
}
return args, nil
}
// GetStoragePoolVolumeBackupWithID returns the volume backup with the given ID.
func (c *ClusterTx) GetStoragePoolVolumeBackupWithID(ctx context.Context, backupID int) (StoragePoolVolumeBackup, error) {
args := StoragePoolVolumeBackup{}
q := `
SELECT
backups.id,
backups.storage_volume_id,
backups.name,
backups.creation_date,
backups.expiry_date,
backups.volume_only,
backups.optimized_storage
FROM storage_volumes_backups AS backups
JOIN storage_volumes ON storage_volumes.id=backups.storage_volume_id
JOIN projects ON projects.id=storage_volumes.project_id
WHERE backups.id=?
`
arg1 := []any{backupID}
outfmt := []any{&args.ID, &args.VolumeID, &args.Name, &args.CreationDate, &args.ExpiryDate, &args.VolumeOnly, &args.OptimizedStorage}
err := dbQueryRowScan(ctx, c, q, arg1, outfmt)
if err != nil {
if err == sql.ErrNoRows {
return args, api.StatusErrorf(http.StatusNotFound, "Storage volume backup not found")
}
return args, err
}
return args, nil
}
// RenameVolumeBackup renames a volume backup from the given current name
// to the new one.
func (c *ClusterTx) RenameVolumeBackup(ctx context.Context, oldName, newName string) error {
str := "UPDATE storage_volumes_backups SET name = ? WHERE name = ?"
stmt, err := c.tx.Prepare(str)
if err != nil {
return err
}
defer func() { _ = stmt.Close() }()
logger.Debug(
"Calling SQL Query",
logger.Ctx{
"query": "UPDATE storage_volumes_backups SET name = ? WHERE name = ?",
"oldName": oldName,
"newName": newName})
_, err = stmt.Exec(newName, oldName)
if err != nil {
return err
}
return nil
}
// GetStoragePoolBucketBackupsName returns the names of all backups of the storage bucket with the given name.
func (c *ClusterTx) GetStoragePoolBucketBackupsName(ctx context.Context, projectName string, bucketName string) ([]string, error) {
var result []string
q := `SELECT storage_buckets_backups.name FROM storage_buckets_backups
JOIN storage_buckets ON storage_buckets_backups.storage_bucket_id=storage_buckets.id
JOIN projects ON projects.id=storage_buckets.project_id
WHERE projects.name=? AND storage_buckets.name=?
ORDER BY storage_buckets_backups.id`
inargs := []any{projectName, bucketName}
outfmt := []any{bucketName}
dbResults, err := queryScan(ctx, c, q, inargs, outfmt)
if err != nil {
return nil, err
}
for _, r := range dbResults {
result = append(result, r[0].(string))
}
return result, nil
}
// CreateStoragePoolBucketBackup creates a new storage bucket backup.
func (c *ClusterTx) CreateStoragePoolBucketBackup(ctx context.Context, args StoragePoolBucketBackup) error {
_, err := c.getStoragePoolBucketBackupID(ctx, args.Name)
if err == nil {
return ErrAlreadyDefined
}
str := "INSERT INTO storage_buckets_backups (storage_bucket_id, name, creation_date, expiry_date) VALUES (?, ?, ?, ?)"
stmt, err := c.tx.Prepare(str)
if err != nil {
return err
}
defer func() { _ = stmt.Close() }()
result, err := stmt.Exec(args.BucketID, args.Name,
args.CreationDate.Unix(), args.ExpiryDate.Unix())
if err != nil {
return err
}
_, err = result.LastInsertId()
if err != nil {
return fmt.Errorf("Error inserting %q into database", args.Name)
}
return nil
}
// Returns the ID of the storage bucket backup with the given name.
func (c *ClusterTx) getStoragePoolBucketBackupID(ctx context.Context, name string) (int, error) {
q := "SELECT id FROM storage_buckets_backups WHERE name=?"
id := -1
arg1 := []any{name}
arg2 := []any{&id}
err := dbQueryRowScan(ctx, c, q, arg1, arg2)
if err == sql.ErrNoRows {
return -1, api.StatusErrorf(http.StatusNotFound, "Storage volume backup not found")
}
return id, err
}
// DeleteStoragePoolBucketBackup removes the storage bucket backup with the given name from the database.
func (c *ClusterTx) DeleteStoragePoolBucketBackup(ctx context.Context, name string) error {
id, err := c.getStoragePoolBucketBackupID(ctx, name)
if err != nil {
return err
}
_, err = c.tx.ExecContext(ctx, "DELETE FROM storage_buckets_backups WHERE id=?", id)
if err != nil {
return err
}
return nil
}
// GetStoragePoolBucketBackup returns the bucket backup with the given name.
func (c *ClusterTx) GetStoragePoolBucketBackup(ctx context.Context, projectName string, poolName string, backupName string) (StoragePoolBucketBackup, error) {
args := StoragePoolBucketBackup{}
q := `
SELECT
backups.id,
backups.storage_bucket_id,
backups.name,
backups.creation_date,
backups.expiry_date
FROM storage_buckets_backups AS backups
JOIN storage_buckets ON storage_buckets.id=backups.storage_bucket_id
JOIN projects ON projects.id=storage_buckets.project_id
WHERE projects.name=? AND backups.name=?
`
arg1 := []any{projectName, backupName}
outfmt := []any{&args.ID, &args.BucketID, &args.Name, &args.CreationDate, &args.ExpiryDate}
err := dbQueryRowScan(ctx, c, q, arg1, outfmt)
if err != nil {
if err == sql.ErrNoRows {
return args, api.StatusErrorf(http.StatusNotFound, "Storage bucket backup not found")
}
return args, err
}
return args, nil
}
// GetExpiredStorageBucketBackups returns a list of expired storage bucket backups.
func (c *ClusterTx) GetExpiredStorageBucketBackups(ctx context.Context) ([]StoragePoolBucketBackup, error) {
var backups []StoragePoolBucketBackup
q := `
SELECT
storage_buckets_backups.id,
storage_buckets_backups.name,
storage_buckets_backups.expiry_date,
storage_buckets_backups.storage_bucket_id
FROM storage_buckets_backups`
err := query.Scan(ctx, c.Tx(), q, func(scan func(dest ...any) error) error {
var b StoragePoolBucketBackup
var expiryTime sql.NullTime
err := scan(&b.ID, &b.Name, &expiryTime, &b.BucketID)
if err != nil {
return err
}
b.ExpiryDate = expiryTime.Time // Convert nulls to zero.
// Since zero time causes some issues due to timezones, we check the
// unix timestamp instead of IsZero().
if b.ExpiryDate.Unix() <= 0 {
// Backup doesn't expire
return nil
}
// Backup has expired
if time.Now().Unix()-b.ExpiryDate.Unix() >= 0 {
backups = append(backups, b)
}
return nil
})
if err != nil {
return nil, err
}
return backups, nil
}
// RenameBucketBackup renames a bucket backup from the given current name to the new one.
func (c *ClusterTx) RenameBucketBackup(ctx context.Context, oldName, newName string) error {
str := "UPDATE storage_buckets_backups SET name = ? WHERE name = ?"
stmt, err := c.tx.Prepare(str)
if err != nil {
return err
}
defer func() { _ = stmt.Close() }()
logger.Debug(
"Calling SQL Query",
logger.Ctx{
"query": "UPDATE storage_buckets_backups SET name = ? WHERE name = ?",
"oldName": oldName,
"newName": newName})
_, err = stmt.Exec(newName, oldName)
if err != nil {
return err
}
return nil
}