public static Date parseBackupTag(String tag) throws ParseException { if (tag == null) { throw new ParseException("Can't parse backup date because tag is null", -1); } int beginIndex = tag.length() - BackupConstants.SCHEDULED_BACKUP_DATE_PATTERN.length(); if (beginIndex < 0) { throw new ParseException( "Can't parse backup date from wrong begin index for tag: " + tag, beginIndex); } return parseTimestamp(tag.substring(beginIndex)); }
public static List<String> pickScheduledBackupTags(Collection<String> tags) { ArrayList<String> scheduledTags = new ArrayList<>(); // Typically, this pattern String could match all tags produced by toBackupTag method // also in consideration of extension, version part could be longer and node count could bigger String regex = String.format( BackupConstants.SCHEDULED_BACKUP_TAG_REGEX_PATTERN, ProductName.getName(), BackupConstants.SCHEDULED_BACKUP_DATE_PATTERN.length()); Pattern backupNamePattern = Pattern.compile(regex); for (String tag : tags) { if (backupNamePattern.matcher(tag).find()) { scheduledTags.add(tag); } } log.info("Scheduled backup tags: {}", scheduledTags); return scheduledTags; }