@@ -24,10 +24,12 @@ type snapshot struct {
24
24
Time time.Time // Parsed timestamp from the dataset name
25
25
}
26
26
27
+ // FIXME PruneSnapshots does not actually perform any destructive operations
28
+ // on your datasets at this time.
27
29
func PruneSnapshots (job * config.JobConfig ) {
28
30
var host = job .Host ()
29
31
30
- // Set defaults if config is not set
32
+ // Defaults: if config is not set
31
33
if job .Retention == nil {
32
34
job .Retention = & config.RetentionConfig {
33
35
Daily : 100000 ,
@@ -37,7 +39,7 @@ func PruneSnapshots(job *config.JobConfig) {
37
39
}
38
40
}
39
41
40
- // This catches any gaps in the config
42
+ // Defaults: catch any gaps in the config
41
43
if job .Retention .Daily == 0 {
42
44
job .Retention .Daily = 100000
43
45
}
@@ -51,51 +53,41 @@ func PruneSnapshots(job *config.JobConfig) {
51
53
job .Retention .Yearly = 100000
52
54
}
53
55
54
- // FIXME probably should iterate over a list instead here
55
- for _ , snapshot := range listKeepers (host , "daily" , job .Retention .Daily ) {
56
- log .WithFields (logrus.Fields {
57
- "snapshot" : snapshot ,
58
- "period" : "daily" ,
59
- }).Debug ("keeping snapshot" )
56
+ var keep_counts = map [string ]uint {
57
+ "daily" : job .Retention .Daily ,
58
+ "weekly" : job .Retention .Weekly ,
59
+ "monthly" : job .Retention .Monthly ,
60
+ "yearly" : job .Retention .Yearly ,
60
61
}
61
- for _ , snapshot := range listKeepers (host , "weekly" , job .Retention .Weekly ) {
62
- log .WithFields (logrus.Fields {
63
- "snapshot" : snapshot ,
64
- "period" : "weekly" ,
65
- }).Debug ("keeping snapshot" )
66
- }
67
- for _ , snapshot := range listKeepers (host , "monthly" , job .Retention .Monthly ) {
68
- log .WithFields (logrus.Fields {
69
- "snapshot" : snapshot ,
70
- "period" : "monthly" ,
71
- }).Debug ("keeping snapshot" )
72
- }
73
- for _ , snapshot := range listKeepers (host , "yearly" , job .Retention .Yearly ) {
74
- log .WithFields (logrus.Fields {
75
- "snapshot" : snapshot ,
76
- "period" : "yearly" ,
77
- }).Debug ("keeping snapshot" )
62
+
63
+ for bucket , keep_count := range keep_counts {
64
+ for _ , snapshot := range listKeepers (host , bucket , keep_count ) {
65
+ log .WithFields (logrus.Fields {
66
+ "snapshot" : snapshot ,
67
+ "bucket" : bucket ,
68
+ }).Debug ("keeping snapshot" )
69
+ }
78
70
}
79
71
80
72
// TODO subtract keepers from the list of snapshots and rm -rf them
81
73
}
82
74
83
75
// listKeepers returns a list of snapshot that are not subject to deletion
84
76
// for a given host, pattern, and keep_count.
85
- func listKeepers (host string , pattern string , keep_count uint ) []snapshot {
77
+ func listKeepers (host string , bucket string , keep_count uint ) []snapshot {
86
78
var keepers []snapshot
87
79
var last string
88
80
89
81
for _ , snapshot := range listSnapshots (host ) {
90
82
var period string
91
83
92
84
// Weekly is special because golang doesn't have support for "week number in year"
93
- // in Time.Format strings .
94
- if pattern == "weekly" {
85
+ // as Time.Format string pattern .
86
+ if bucket == "weekly" {
95
87
year , week := snapshot .Time .Local ().ISOWeek ()
96
88
period = fmt .Sprintf ("%d-%d" , year , week )
97
89
} else {
98
- period = snapshot .Time .Local ().Format (patterns [pattern ])
90
+ period = snapshot .Time .Local ().Format (patterns [bucket ])
99
91
}
100
92
101
93
if period != last {
0 commit comments