/** * Will delete snapshots older than 15 days, if there are at least two snapshots in the list. Will * set the message that can be read with getMessage() to have more insight of what has happened. * * @param snapshotsOfaVolume the list of snapshots of a volume * @return a list of snapshots to be deleted. if none, it will be an empty list */ public final List<MySnapshot> snapshotsToBeDeleted(final List<MySnapshot> snapshotsOfaVolume) { List<MySnapshot> toBeDeleted = new ArrayList<MySnapshot>(); message = ""; if (snapshotsOfaVolume.size() == 0) { return toBeDeleted; // there are no Snapshots at all, so nothing to be deleted } int volumeSize = snapshotsOfaVolume.get(0).getSizeInGb(); if (volumeSize <= thresholdGb && snapshotsOfaVolume.size() <= howManyCopiesForSmallVolumes) { message = "Skipped deletion because I don't have more than " + howManyCopiesForSmallVolumes + " snapshots"; return toBeDeleted; // empty list } if (volumeSize > thresholdGb && snapshotsOfaVolume.size() <= howManyCopiesForBigVolumes) { message = "Skipped deletion because I don't have more than " + howManyCopiesForBigVolumes + " snapshots"; return toBeDeleted; // empty list } for (MySnapshot snapshot : snapshotsOfaVolume) { if (snapshot.howManyDaysAgo() > howManyDaysBeforeDeleting) { toBeDeleted.add(snapshot); } } return toBeDeleted; }
/** * From a list of snapshots of a volume, tells if the snapshots need a backup or not. The current * policy is that if the last snapshot is older than 7 days (8 or more), we need a backup. If the * snapshot is greater than 140 Gb, we need a backup only every 14 days. * * @param snapShotsOfAVolume the snapshots of a volume (it's responsibility of the caller to * provide those) * @return true */ public final boolean needBackup(final List<MySnapshot> snapShotsOfAVolume) { int size, daysAgo; message = ""; for (MySnapshot snapshot : snapShotsOfAVolume) { size = snapshot.getSizeInGb(); daysAgo = snapshot.howManyDaysAgo(); if (size <= thresholdGb && daysAgo <= everyHowManyDaysForSmallVolumes) { return false; } else if (size > thresholdGb && daysAgo <= everyHowManyDaysForBigVolumes) { return false; } } return true; }