GetExpiredStorageBucketBackups returns a list of expired storage bucket backups.
(ctx context.Context)
| 735 | |
| 736 | // GetExpiredStorageBucketBackups returns a list of expired storage bucket backups. |
| 737 | func (c *ClusterTx) GetExpiredStorageBucketBackups(ctx context.Context) ([]StoragePoolBucketBackup, error) { |
| 738 | var backups []StoragePoolBucketBackup |
| 739 | |
| 740 | q := ` |
| 741 | SELECT |
| 742 | storage_buckets_backups.id, |
| 743 | storage_buckets_backups.name, |
| 744 | storage_buckets_backups.expiry_date, |
| 745 | storage_buckets_backups.storage_bucket_id |
| 746 | FROM storage_buckets_backups` |
| 747 | |
| 748 | err := query.Scan(ctx, c.Tx(), q, func(scan func(dest ...any) error) error { |
| 749 | var b StoragePoolBucketBackup |
| 750 | var expiryTime sql.NullTime |
| 751 | |
| 752 | err := scan(&b.ID, &b.Name, &expiryTime, &b.BucketID) |
| 753 | if err != nil { |
| 754 | return err |
| 755 | } |
| 756 | |
| 757 | b.ExpiryDate = expiryTime.Time // Convert nulls to zero. |
| 758 | |
| 759 | // Since zero time causes some issues due to timezones, we check the |
| 760 | // unix timestamp instead of IsZero(). |
| 761 | if b.ExpiryDate.Unix() <= 0 { |
| 762 | // Backup doesn't expire |
| 763 | return nil |
| 764 | } |
| 765 | |
| 766 | // Backup has expired |
| 767 | if time.Now().Unix()-b.ExpiryDate.Unix() >= 0 { |
| 768 | backups = append(backups, b) |
| 769 | } |
| 770 | |
| 771 | return nil |
| 772 | }) |
| 773 | if err != nil { |
| 774 | return nil, err |
| 775 | } |
| 776 | |
| 777 | return backups, nil |
| 778 | } |
| 779 | |
| 780 | // RenameBucketBackup renames a bucket backup from the given current name to the new one. |
| 781 | func (c *ClusterTx) RenameBucketBackup(ctx context.Context, oldName, newName string) error { |
no test coverage detected