MCPcopy
hub / github.com/lxc/incus / GetExpiredStorageBucketBackups

Method GetExpiredStorageBucketBackups

internal/server/db/backups.go:737–778  ·  view source on GitHub ↗

GetExpiredStorageBucketBackups returns a list of expired storage bucket backups.

(ctx context.Context)

Source from the content-addressed store, hash-verified

735
736// GetExpiredStorageBucketBackups returns a list of expired storage bucket backups.
737func (c *ClusterTx) GetExpiredStorageBucketBackups(ctx context.Context) ([]StoragePoolBucketBackup, error) {
738 var backups []StoragePoolBucketBackup
739
740 q := `
741SELECT
742 storage_buckets_backups.id,
743 storage_buckets_backups.name,
744 storage_buckets_backups.expiry_date,
745 storage_buckets_backups.storage_bucket_id
746FROM 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.
781func (c *ClusterTx) RenameBucketBackup(ctx context.Context, oldName, newName string) error {

Callers 1

Calls 4

TxMethod · 0.95
ScanFunction · 0.92
UnixMethod · 0.80
scanFunction · 0.50

Tested by

no test coverage detected