Libraryless. Click here for Pure Java version (5839L/33K).
svoid thinAProgramsBackups(S progID, bool doIt) { File dir = programDir(progID); thinAProgramsBackups(dir, doIt); } svoid thinAProgramsBackups(File dir, bool doIt) { new L<File> files; new Map<File, Double> ageMap; // minutes (last group) are optional java.util.regex.Pattern pat = regexp("^(.*)\\.backup(20\\d\\d)(\\d\\d)(\\d\\d)-(\\d\\d)(\\d*)$"); print("Processing backups in " + dir); for (File f : listFilesNotDirs(dir, newFile(dir, "backups"))) { S s = f.getName(); java.util.regex.Matcher matcher = pat.matcher(s); continue unless matcher.find(); S originalName = matcher.group(1); continue unless eq(originalName, "concepts.structure.gz"); //print("Found backup: " + sfu(matcherGroups(matcher))); int year = matcherInt(matcher, 2); int month = matcherInt(matcher, 3); int day = matcherInt(matcher, 4); int hour = matcherInt(matcher, 5); int minute = matcherInt(matcher, 6); long time = timestampFromYMDHM(year, month, day, hour, minute); double age = ((now()-time)/1000.0/60/60/24; //print("Age: " + age + " days"); ageMap.put(f, age); files.add(f); } int numDeleted = 0; sortByMap_inPlace(files, ageMap); double lastAge = -1; for (File f : files) { double age = ageMap.get(f); if (!thinAProgramsBackups_shouldKeep(age, lastAge)) { //print("Deleting: " + f); ++numDeleted; if (doIt) { print("Deleting: " + f); f.delete(); } } else { //print("Keeping: " + f); lastAge = age; } } if (numDeleted != 0) print((doIt ? "Deleted: " : "Would delete: ") + n(numDeleted, "file")); } // age = age in days sbool thinAProgramsBackups_shouldKeep(double age, double lastAge) { ret defaultAgeBasedBackupRetentionStrategy_shouldKeep(age, lastAge); }
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: | 585 / 756 |
Version history: | 14 change(s) |
Referenced in: | [show references] |