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
//! Long-term preservation policy definitions for media archives.
#![allow(dead_code)]
// ---------------------------------------------------------------------------
// ReplicationTier
// ---------------------------------------------------------------------------
/// Defines how many on-site and off-site replica copies are required.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ReplicationTier {
/// Number of on-site copies required.
pub on_site_copies: u32,
/// Number of off-site copies required.
pub off_site_copies: u32,
}
impl ReplicationTier {
/// Create a new replication tier.
#[must_use]
pub fn new(on_site_copies: u32, off_site_copies: u32) -> Self {
Self {
on_site_copies,
off_site_copies,
}
}
/// Total number of copies required.
#[must_use]
pub fn total_copies(&self) -> u32 {
self.on_site_copies + self.off_site_copies
}
/// Returns `true` when the tier satisfies the 3-2-1 backup rule:
/// at least 3 total, at least 2 on-site, at least 1 off-site.
#[must_use]
pub fn satisfies_321_rule(&self) -> bool {
self.total_copies() >= 3 && self.on_site_copies >= 2 && self.off_site_copies >= 1
}
}
// ---------------------------------------------------------------------------
// FixitySchedule
// ---------------------------------------------------------------------------
/// How often fixity checks should be performed.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FixitySchedule {
/// Every day.
Daily,
/// Every week.
Weekly,
/// Every 30 days.
Monthly,
/// Every 90 days.
Quarterly,
/// Every 365 days.
Annually,
}
impl FixitySchedule {
/// Approximate number of days between checks.
#[must_use]
pub fn interval_days(&self) -> u32 {
match self {
FixitySchedule::Daily => 1,
FixitySchedule::Weekly => 7,
FixitySchedule::Monthly => 30,
FixitySchedule::Quarterly => 90,
FixitySchedule::Annually => 365,
}
}
}
// ---------------------------------------------------------------------------
// PreservationPolicy
// ---------------------------------------------------------------------------
/// A named preservation policy applied to one or more archive collections.
#[derive(Debug, Clone)]
pub struct PreservationPolicy {
/// Human-readable name of the policy.
pub name: String,
/// Description of the policy.
pub description: String,
/// Replication requirements.
pub replication: ReplicationTier,
/// How often fixity checks must be run.
pub fixity_schedule: FixitySchedule,
/// Minimum number of years the asset must be retained.
pub retention_years: u32,
/// Whether format migration is required at end-of-life for a format.
pub requires_format_migration: bool,
}
impl PreservationPolicy {
/// Create a new preservation policy.
#[must_use]
pub fn new(
name: impl Into<String>,
description: impl Into<String>,
replication: ReplicationTier,
fixity_schedule: FixitySchedule,
retention_years: u32,
requires_format_migration: bool,
) -> Self {
Self {
name: name.into(),
description: description.into(),
replication,
fixity_schedule,
retention_years,
requires_format_migration,
}
}
/// Returns `true` if this policy is classified as "gold" (highest grade):
/// satisfies 3-2-1 rule, monthly or more frequent fixity, ≥10 years retention.
#[must_use]
pub fn is_gold_tier(&self) -> bool {
self.replication.satisfies_321_rule()
&& self.fixity_schedule.interval_days() <= 30
&& self.retention_years >= 10
}
/// Approximate total number of fixity checks over the retention period.
#[must_use]
pub fn total_fixity_checks(&self) -> u64 {
let days = u64::from(self.retention_years) * 365;
let interval = u64::from(self.fixity_schedule.interval_days()).max(1);
days / interval
}
}
// ---------------------------------------------------------------------------
#[cfg(test)]
mod tests {
use super::*;
// --- ReplicationTier ---
#[test]
fn test_replication_total_copies() {
let tier = ReplicationTier::new(2, 1);
assert_eq!(tier.total_copies(), 3);
}
#[test]
fn test_replication_321_satisfied() {
let tier = ReplicationTier::new(2, 1);
assert!(tier.satisfies_321_rule());
}
#[test]
fn test_replication_321_not_satisfied_low_total() {
let tier = ReplicationTier::new(1, 1);
assert!(!tier.satisfies_321_rule());
}
#[test]
fn test_replication_321_not_satisfied_no_offsite() {
let tier = ReplicationTier::new(3, 0);
assert!(!tier.satisfies_321_rule());
}
#[test]
fn test_replication_321_not_satisfied_one_onsite() {
let tier = ReplicationTier::new(1, 2);
// Total = 3, on-site < 2 → fails
assert!(!tier.satisfies_321_rule());
}
#[test]
fn test_replication_fields() {
let tier = ReplicationTier::new(3, 2);
assert_eq!(tier.on_site_copies, 3);
assert_eq!(tier.off_site_copies, 2);
}
// --- FixitySchedule ---
#[test]
fn test_fixity_daily_interval() {
assert_eq!(FixitySchedule::Daily.interval_days(), 1);
}
#[test]
fn test_fixity_weekly_interval() {
assert_eq!(FixitySchedule::Weekly.interval_days(), 7);
}
#[test]
fn test_fixity_monthly_interval() {
assert_eq!(FixitySchedule::Monthly.interval_days(), 30);
}
#[test]
fn test_fixity_quarterly_interval() {
assert_eq!(FixitySchedule::Quarterly.interval_days(), 90);
}
#[test]
fn test_fixity_annually_interval() {
assert_eq!(FixitySchedule::Annually.interval_days(), 365);
}
// --- PreservationPolicy ---
#[test]
fn test_policy_gold_tier_yes() {
let policy = PreservationPolicy::new(
"Gold",
"Highest grade policy",
ReplicationTier::new(2, 1),
FixitySchedule::Monthly,
25,
true,
);
assert!(policy.is_gold_tier());
}
#[test]
fn test_policy_gold_tier_no_quarterly() {
// Quarterly is > 30 days, should fail gold check.
let policy = PreservationPolicy::new(
"Silver",
"Not gold",
ReplicationTier::new(2, 1),
FixitySchedule::Quarterly,
25,
false,
);
assert!(!policy.is_gold_tier());
}
#[test]
fn test_policy_gold_tier_no_short_retention() {
let policy = PreservationPolicy::new(
"Bronze",
"Short retention",
ReplicationTier::new(2, 1),
FixitySchedule::Monthly,
5,
false,
);
assert!(!policy.is_gold_tier());
}
#[test]
fn test_policy_total_fixity_checks() {
// 10 years × 365 days / 30 days-per-check ≈ 121
let policy = PreservationPolicy::new(
"Test",
"Policy",
ReplicationTier::new(2, 1),
FixitySchedule::Monthly,
10,
false,
);
let checks = policy.total_fixity_checks();
assert_eq!(checks, 10 * 365 / 30);
}
#[test]
fn test_policy_name_field() {
let policy = PreservationPolicy::new(
"MyPolicy",
"Desc",
ReplicationTier::new(2, 1),
FixitySchedule::Weekly,
5,
false,
);
assert_eq!(policy.name, "MyPolicy");
}
}