From f9a48c52e4a5bb644c56c87a5e38f0a19b1caa97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E9=B8=BF=E9=A3=9E?= Date: Thu, 11 May 2023 11:19:08 +0800 Subject: [PATCH] fix(region): add cleanSnapshotDate option --- pkg/compute/models/snapshots.go | 4 ++-- pkg/compute/options/options.go | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/compute/models/snapshots.go b/pkg/compute/models/snapshots.go index 1956763d26..712d90f00f 100644 --- a/pkg/compute/models/snapshots.go +++ b/pkg/compute/models/snapshots.go @@ -1195,9 +1195,9 @@ func (manager *SSnapshotManager) DataCleaning(ctx context.Context, userCred mccl func dataCleaning(tableName string) error { now := time.Now() - monthsDaysAgo := now.AddDate(0, -1, 0).Format("2006-01-02 15:04:05") + monthsDaysAgo := now.AddDate(0, 0, -options.Options.KeepDeletedSnapshotDays).Format("2006-01-02 15:04:05") sqlStr := fmt.Sprintf( - "delete from %s where deleted = 1 and updated_at < '%s'", + "delete from %s where deleted = 1 and deleted_at < '%s'", tableName, monthsDaysAgo, ) diff --git a/pkg/compute/options/options.go b/pkg/compute/options/options.go index 80c87192d2..51af02c577 100644 --- a/pkg/compute/options/options.go +++ b/pkg/compute/options/options.go @@ -187,7 +187,8 @@ type ComputeOptions struct { DefaultIPAllocationDirection string `help:"default IP allocation direction" default:"stepdown"` - CleanupSnapshots bool `help:"create a cronjob to cleaning snapshots every day" default:"true"` + CleanupSnapshots bool `help:"create a cronjob to cleaning snapshots every day" default:"true"` + KeepDeletedSnapshotDays int `help:"The day of cleanup snapshot" default:"30"` // 弹性伸缩中的ecs一般会有特殊的系统标签,通过指定这些标签可以忽略这部分ecs的同步, 指定多个key需要以 ',' 分隔 SkipServerBySysTagKeys string `help:"skip server,disk sync and create with system tags" default:"acs:autoscaling:scalingGroupId"` SkipServerByUserTagKeys string `help:"skip server,disk sync and create with user tags" default:""`