Libraryless. Click here for Pure Java version (5839L/33K).
1 | svoid thinAProgramsBackups(S progID, bool doIt) { |
2 | File dir = programDir(progID); |
3 | thinAProgramsBackups(dir, doIt); |
4 | } |
5 | |
6 | svoid thinAProgramsBackups(File dir, bool doIt) { |
7 | new L<File> files; |
8 | new Map<File, Double> ageMap; |
9 | |
10 | // minutes (last group) are optional |
11 | java.util.regex.Pattern pat = regexp("^(.*)\\.backup(20\\d\\d)(\\d\\d)(\\d\\d)-(\\d\\d)(\\d*)$"); |
12 | print("Processing backups in " + dir); |
13 | |
14 | for (File f : listFilesNotDirs(dir, newFile(dir, "backups"))) { |
15 | S s = f.getName(); |
16 | java.util.regex.Matcher matcher = pat.matcher(s); |
17 | continue unless matcher.find(); |
18 | S originalName = matcher.group(1); |
19 | continue unless eq(originalName, "concepts.structure.gz"); |
20 | //print("Found backup: " + sfu(matcherGroups(matcher))); |
21 | int year = matcherInt(matcher, 2); |
22 | int month = matcherInt(matcher, 3); |
23 | int day = matcherInt(matcher, 4); |
24 | int hour = matcherInt(matcher, 5); |
25 | int minute = matcherInt(matcher, 6); |
26 | long time = timestampFromYMDHM(year, month, day, hour, minute); |
27 | double age = ((now()-time)/1000.0/60/60/24; |
28 | //print("Age: " + age + " days"); |
29 | ageMap.put(f, age); |
30 | files.add(f); |
31 | } |
32 | |
33 | int numDeleted = 0; |
34 | sortByMap_inPlace(files, ageMap); |
35 | double lastAge = -1; |
36 | for (File f : files) { |
37 | double age = ageMap.get(f); |
38 | if (!thinAProgramsBackups_shouldKeep(age, lastAge)) { |
39 | //print("Deleting: " + f); |
40 | ++numDeleted; |
41 | if (doIt) { |
42 | print("Deleting: " + f); |
43 | f.delete(); |
44 | } |
45 | } else { |
46 | //print("Keeping: " + f); |
47 | lastAge = age; |
48 | } |
49 | } |
50 | if (numDeleted != 0) |
51 | print((doIt ? "Deleted: " : "Would delete: ") + n(numDeleted, "file")); |
52 | } |
53 | |
54 | // age = age in days |
55 | sbool thinAProgramsBackups_shouldKeep(double age, double lastAge) { |
56 | ret defaultAgeBasedBackupRetentionStrategy_shouldKeep(age, lastAge); |
57 | } |
Began life as a copy of #1011258
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1011269 |
Snippet name: | thinAProgramsBackups - keeps all hourly backups in last 2 days, one per day in last 31 days, one per week after |
Eternal ID of this version: | #1011269/15 |
Text MD5: | 46dfef6fed096e560fc8c555bb45be5a |
Transpilation MD5: | 60bb88975f6f24235a62a2f3be8c8b01 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-03-20 16:57:59 |
Source code size: | 1875 bytes / 57 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 587 / 760 |
Version history: | 14 change(s) |
Referenced in: | [show references] |