Package net.solarnetwork.node.backup
Class BackupServiceSupport
java.lang.Object
net.solarnetwork.node.backup.BackupServiceSupport
- All Implemented Interfaces:
BackupService
- Direct Known Subclasses:
FileSystemBackupService
Abstract support class for
BackupService implementations.- Since:
- 1.54
- Version:
- 1.2
- Author:
- matt
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringA date and time format to use with backup keys.protected final org.slf4j.LoggerA class-level logger.static final PatternA pattern to match node-N-backup-D-Q where N is a node ID and D is a date formatted usingBACKUP_KEY_DATE_FORMATand Q is an optional qualifier.protected static final com.fasterxml.jackson.databind.ObjectMapperThe object mapper to use. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected DatebackupDateFromProps(Date date, Map<String, String> props) Shortcut forbackupDateFromProps(Date, Map, Pattern, String)using default values.protected DatebackupDateFromProps(Date date, Map<String, String> props, Pattern nodeIdAndDatePattern, String dateFormat) Parse a date from a backup key.protected LongbackupNodeIdFromProps(Long nodeId, Map<String, String> props) Shortcut forbackupNodeIdFromProps(Long, Map, Pattern)using default values.protected LongParse a node ID from a backup key.protected FileGet a directory to use for local backup data.static final BackupIdentityExtract backup identity information from a backup key.static final BackupIdentityidentityFromBackupKey(Pattern nodeIdAndDatePattern, String dateFormat, String key) Extract backup identity information from a backup key.booleanmarkBackupForRestore(Backup backup, Map<String, String> props) Mark a specific backup to be restored in the future call toBackupService.markedBackupForRestore(Map).markedBackupForRestore(Map<String, String> props) Get a backup previously set viaBackupService.markBackupForRestore(Backup, Map).protected FileGet a file to use for "marked backup" metadata.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.solarnetwork.node.backup.BackupService
backupForKey, getAvailableBackups, getBackupResources, getInfo, getKey, getSettingSpecifierProvider, getSettingSpecifierProviderForRestore, importBackup, performBackup
-
Field Details
-
BACKUP_KEY_DATE_FORMAT
A date and time format to use with backup keys.- See Also:
-
NODE_AND_DATE_BACKUP_KEY_PATTERN
A pattern to match node-N-backup-D-Q where N is a node ID and D is a date formatted usingBACKUP_KEY_DATE_FORMATand Q is an optional qualifier.Note that the qualifier and the leading dash is optional, so its
Matchergroup is 4 (not 3). -
OBJECT_MAPPER
protected static final com.fasterxml.jackson.databind.ObjectMapper OBJECT_MAPPERThe object mapper to use. -
log
protected final org.slf4j.Logger logA class-level logger.
-
-
Constructor Details
-
BackupServiceSupport
public BackupServiceSupport()Default constructor.
-
-
Method Details
-
defaultBackuprDir
Get a directory to use for local backup data.- Returns:
- a directory to use for local backup data
-
markedBackupForRestoreFile
Get a file to use for "marked backup" metadata.- Returns:
- the file for marked backup metadata
-
backupDateFromProps
Shortcut forbackupDateFromProps(Date, Map, Pattern, String)using default values.The
NODE_AND_DATE_BACKUP_KEY_PATTERNpattern andBACKUP_KEY_DATE_FORMATformat are used.- Parameters:
date- if not null then return this valueprops- a mapping of properties, which may include aBackupManager.BACKUP_KEYvalue- Returns:
- the date, never null
- See Also:
-
backupDateFromProps
protected Date backupDateFromProps(Date date, Map<String, String> props, Pattern nodeIdAndDatePattern, String dateFormat) Parse a date from a backup key.If no date can be extracted from the given arguments, the current system time will be returned.
- Parameters:
date- if not null then return this valueprops- a mapping of properties, which may include aBackupManager.BACKUP_KEYvaluenodeIdAndDatePattern- a regular expression to match a node ID and date from a backup keydateFormat- the format of the date extracted from thenodeIdAndDatePattern- Returns:
- the date, never null
-
backupNodeIdFromProps
Shortcut forbackupNodeIdFromProps(Long, Map, Pattern)using default values.The
NODE_AND_DATE_BACKUP_KEY_PATTERNpattern is used.- Parameters:
nodeId- if not null then return this valueprops- a mapping of properties, which may include aBackupManager.BACKUP_KEYvalue- Returns:
- the node ID, or 0 if not available
- See Also:
-
backupNodeIdFromProps
protected Long backupNodeIdFromProps(Long nodeId, Map<String, String> props, Pattern nodeIdAndDatePattern) Parse a node ID from a backup key.- Parameters:
nodeId- if not null then return this valueprops- a mapping of properties, which may include aBackupManager.BACKUP_KEYvaluenodeIdAndDatePattern- a regular expression to match a node ID and date from a backup key- Returns:
- the node ID, or 0 if not available
-
identityFromBackupKey
Extract backup identity information from a backup key.This method calls
identityFromBackupKey(Pattern, String, String), passingNODE_AND_DATE_BACKUP_KEY_PATTERNandBACKUP_KEY_DATE_FORMATfor arguments.- Parameters:
key- the key to extract the details from- Returns:
- the extracted details, or null if none found
- Since:
- 1.1
-
identityFromBackupKey
public static final BackupIdentity identityFromBackupKey(Pattern nodeIdAndDatePattern, String dateFormat, String key) Extract backup identity information from a backup key.- Parameters:
nodeIdAndDatePattern- a pattern that contains groups for a node ID, date, and an optional qualifierdateFormat- the date format to parse the date withkey- the key to extract the details from- Returns:
- the extracted details, or null if none found
- Since:
- 1.1
-
markBackupForRestore
Description copied from interface:BackupServiceMark a specific backup to be restored in the future call toBackupService.markedBackupForRestore(Map).- Specified by:
markBackupForRestorein interfaceBackupService- Parameters:
backup- The backup to mark for restoration later, or null to clear a previous marked backup.props- An optional map of properties to save with the mark.- Returns:
- true on success
-
markedBackupForRestore
Description copied from interface:BackupServiceGet a backup previously set viaBackupService.markBackupForRestore(Backup, Map).- Specified by:
markedBackupForRestorein interfaceBackupService- Parameters:
props- An optional map in which any properties passed toBackupService.markBackupForRestore(Backup, Map)should be populated into- Returns:
- The marked backup, or null if none exists.
-