AutoArchive._application.archiving¶
Provides the core functionality of the application. Executes an archiver and creates a backup based
on provided archive specification file and configuration. It also allows to read various information about
configured and stored archives. It requires archiver service
(ArchiverServiceIdentification
) for the backup creation.
Modules¶
archiving_application¶
-
class
AutoArchive._application.archiving.archiving_application.
ArchivingApplication
(componentUi, applicationContext, serviceAccessor)[source]¶ Bases:
object
Takes care of executing user actions - application main use cases.
Parameters: - componentUi (
CmdlineUi
) – Access to user interface. - applicationContext (
ApplicationContext
) – Application context. - serviceAccessor (
IServiceAccessor
) – Access to services.
-
executeCreateAction
(selectedArchiveSpecs)[source]¶ Executes create backup(s) action.
Takes
selectedArchiveSpecs
and for each it creates a backup. IfselectedArchiveSpecs
is empty orOptions.ALL
is set toTrue
then backups for all knows archives (typically all archive specification files inOptions.ARCHIVE_SPECS_DIR
directory) plus those inselectedArchiveSpecs
are created.Parameters: selectedArchiveSpecs ( Sequence<ArchiveSpecInfo>
) – archive specification files for which backups shall be created.
-
executeListAction
(selectedArchiveSpecs)[source]¶ Lists information about selected and orphaned archives to standard output.
Similarly to
executeCreateAction()
archives inselectedArchiveSpecs
are listed. If it is empty orOptions.ALL
isTrue
then all archives plus selected are listed. Orphaned archives are always listed.List of orphaned archives is obtained by following operation: from the list of stored archives is subtracted the unique list of valid selected archives and valid configured archives.
Output has two possible formats depending on the
Options.VERBOSE
option.Parameters: selectedArchiveSpecs ( Sequence<ArchiveSpecInfo>
) – archive specification files which shall be listed.
-
executePurgeAction
(selectedArchiveSpecs)[source]¶ Removes all stored information about specified orphaned archives.
If
selectedArchiveSpecs
is empty orOptions.ALL
isTrue
then all orphaned archives are processed.Parameters: selectedArchiveSpecs ( Sequence<ArchiveSpecInfo>
) – archive specification files which shall be purged.
- componentUi (
config_constants¶
ArchiveSpecInfo
and ConfigConstants
.
-
class
AutoArchive._application.archiving.config_constants.
ArchiveSpecInfo
(name, path)¶ Bases:
tuple
Holds information about an archive specification file; its name and full path.
-
name
¶ Alias for field number 0
-
path
¶ Alias for field number 1
-
-
class
AutoArchive._application.archiving.config_constants.
ConfigConstants
[source]¶ Bases:
object
Configuration related constants.
-
ARCHIVE_SPEC_EXT
= '.aa'¶ Extension of archive specification files.
-
_archiving¶
_Archiving
class.
-
class
AutoArchive._application.archiving._archiving.
_Archiving
(componentUi, applicationContext, serviceAccessor, commandExecutor)[source]¶ Bases:
object
Provides means for working with archives.
Several methods of this class requires an archive specification file as the input parameter (usually named
specFile
). This file should contain all information required to create the backup. Its format is defined by the standardconfigparser
module. It has to contain section[Content]
and may contain section[Archive]
. The[Content]
section requires following options to be present:path
,include-files
andexclude-files
. Optionally,name
can be present. Options in the archive specification file has higher priority than those in the configuration.Parameters: - componentUi (
CmdlineUi
) – Access to user interface. - applicationContext (
ApplicationContext
) – Application context. - serviceAccessor (
IServiceAccessor
) – Access to services. - commandExecutor (
_CommandExecutor
) – For executing commands before and after backup creation.
-
filterValidSpecFiles
(specFiles)[source]¶ Returns names of configured archives from valid only archive specification files passed in
specFiles
.Parameters: specFiles ( Iterable<str>
) – Paths to archive specification files that shall be validated and from which the names shall be retrieved.Returns: Iterable of names of validly configured archives. Return type: Iterable<str>
-
getArchiveInfo
(specFile)[source]¶ Returns information about archive represented by the
specFile
parameter.Warning
This method utilizes the user configuration directory so the option
Options.USER_CONFIG_DIR
has to point to an existing directory.Parameters: specFile ( str
) – Path to the archive specification file.Returns: Information about an archive or None
.Return type: _ArchiveInfo
-
getArchiveSpecs
()[source]¶ Iterable of all known archive specification files.
Returns: Iterable of archive specification files information. Return type: Iterable<ArchiveSpecInfo>
Raises RuntimeError: If list of archive specification can not be obtained.
-
getStoredArchiveInfo
(archiveName)[source]¶ Returns information about an archive from stored data.
Unlike in the
getArchiveInfo()
method the information is not read from the archive specification file but from other stored data about the archive created by the component in previous runs. Such data can be fetched for example from application storage (IStorage
) or other sources specific to the archiver. It is expected that the large portion of data will be missing in the returned information.Warning
This method utilizes the user configuration directory so the option
Options.USER_CONFIG_DIR
has to point to an existing directory.See also:
getStoredArchiveNames()
Parameters: archiveName ( str
) – Name of the archive which information shall be returned.Returns: Information about an archive or None
if no data for the archive was found.Return type: _ArchiveInfo
-
getStoredArchiveNames
()[source]¶ Returns iterable of archive names which has some data stored in a persistent storage.
Warning
This method utilizes the user configuration directory so the option
Options.USER_CONFIG_DIR
has to point to an existing directory.See also:
getStoredArchiveInfo()
Returns: Iterable of archive names. Return type: Iterable<str>
-
makeBackup
(specFile)[source]¶ Creates the backup based on
specFile
.The result can be a file with a full backup or an incremental backup of some particular level. This depends on the archive specification file (
specFile
), the configuration (IConfiguration
), previous operations with thespecFile
and the time. Some of the properties of_ArchiveInfo
returned by the methodgetArchiveInfo()
can be used to determine what the result will be. The path and name of the created file will be assembled as follows: “<Options.DEST_DIR>/<archive_name>[.<backup_level>].<archiver_specific_extension>”.Method uses
CmdlineUi
-like interface to report errors, warnings et al. to the user.Warning
This method utilizes the user configuration directory so the option
Options.USER_CONFIG_DIR
has to point to an existing directory.See also:
IArchiving.makeBackup()
.Parameters: specFile ( str
) – Path to the archive specification file.Raises ValueError: If the desired archiver type is not supported.
-
purgeStoredArchiveData
(archiveName)[source]¶ Deletes all data stored for the archive named
archiveName
.Warning
This method utilizes the user configuration directory so the option
Options.USER_CONFIG_DIR
has to point to an existing directory.See also:
getStoredArchiveInfo()
Parameters: archiveName (
str
) – Name of the archive which data shall be purged.Raises: - KeyError – If
archiveName
does not have any stored data to purge. - OSError – If an error occurred during the operation of removing data from a physical storage.
- KeyError – If
- componentUi (
_backup_information_provider¶
_BackupInformationProvider
class.
-
class
AutoArchive._application.archiving._backup_information_provider.
_BackupInformationProvider
(archiveSpec, componentUi, storage, serviceAccessor)[source]¶ Bases:
object
Provides information about backups.
Parameters: - archiveSpec (
_ArchiveSpec
) – Archive specification of the backup that this instance will provide information about. - storage (
IStorage
) – Application storage. - componentUi (
CmdlineUi
) – Access to the user interface. - serviceAccessor (
IServiceAccessor
) – AnIServiceAccessor
instance.
Raises: - RuntimeError – If the archiver service could not be created.
- OSError – If a system error occurred.
-
static
getBackupLevelForBackup
(archiveName, userConfigDir, serviceAccessor)[source]¶ Returns current backup level for the passed
archiveName
.Parameters: - archiveName (
str
) – Name of the archive for which the backup level shall be returned. - userConfigDir (
str
) – Path to the user configuration directory. - serviceAccessor (
IServiceAccessor
) – Service accessor.
Returns: Current backup level for
archiveName
or NoneReturn type: int
Raises: - RuntimeError – If the archiver service could not be created.
- OSError – If a system error occurred.
- archiveName (
-
getLastFullRestartDate
()[source]¶ Reads the last full restart date from the persistent storage and returns it.
Returns: Date of the last full backup level restart. Return type: datetime.date
-
getLastRestartDate
()[source]¶ Reads the last restart date from the persistent storage and returns it.
Returns: Date of the last backup level restart. Return type: datetime.date
-
static
getRestartDate
(storageVariable, storagePortion)[source]¶ Reads the date of a backup level restart from storage and returns it.
Parameters: - storageVariable (
str
) – Variable that holds the restart date in the persistent storage. - storagePortion (
IStoragePortion
) – The persistent storage where the variable is located.
Returns: A backup level restart date.
Return type: datetime.date
- storageVariable (
-
static
getStoredArchiveNames
(userConfigDir, storage, serviceAccessor)[source]¶ Returns iterable of archive names which has some data stored in a persistent storage.
Persistent storages from which archive names are retrieved are specific to the concrete archiver service. A typical storage used by archivers is the application storage (
IStorage
).Parameters: - userConfigDir (
str
) – Path to the user configuration directory. - storage (
IStorage
) – The application storage. - serviceAccessor (
IServiceAccessor
) – Service accessor.
Returns: Set of archive names.
Return type: set<str>
Raises RuntimeError: If the archiver service could not be created.
- userConfigDir (
-
archiveSpec
¶ Gets the archive specification that corresponds to the backup about which this instance provides information.
Return type: _ArchiveSpec
-
currentBackupLevel
¶ Gets the current backup level or
None
.Return type: int
-
nextBackupLevel
¶ Gets the backup level that would be created if the backup creation was triggered.
Return type: int
-
restartLevel
¶ Gets a backup level to which a next restart would be done.
Return type: int
-
restartReason
¶ Gets the reason for upcoming backup level restart.
Return type: _BackupLevelRestartReasons
- archiveSpec (
_command_executor¶
_CommandExecutor
class.
_archiving_constants¶
_ArchiverMaps
and _RestartStorageVariables
classes.
-
class
AutoArchive._application.archiving._archiving_constants.
_ArchiverMaps
[source]¶ Bases:
object
Mappings which involves archiver types.
-
ARCHIVER_TYPE_TO_SERVICE_MAP
= {0: 1, 1: 1, 2: 1, 3: 1, 4: 0, 5: 0, 6: 0}¶
-
-
class
AutoArchive._application.archiving._archiving_constants.
_RestartStorageVariables
[source]¶ Bases:
object
Names of storage variables for backup level restarting.
-
BACKUP_SIZE
= 'archiving-size-level'¶
-
LAST_FULL_RESTART
= 'archiving-last-full-restart'¶
-
LAST_RESTART
= 'archiving-last-restart'¶
-
RESTART_COUNT
= 'archiving-restart-count'¶
-
_archive_spec¶
_ArchiveSpec
class.
-
class
AutoArchive._application.archiving._archive_spec.
_ArchiveSpec
(specFile, configuration, componentUi=None)[source]¶ Bases:
AutoArchive._infrastructure.configuration.configuration_base.ConfigurationBase
The archive specification.
Contains all information needed to create the backup such as the name, list of files which shall be included into the backup, list of files to exclude, etc. These values can be configured in the archive specification file (
specFile
) or in the general configuration such as command line or configuration files. Options that can be read from this class are defined as static attributes of_ArchiveSpecOptions
andOptions
. If an option is not defined in the archive specification file it is read fromconfiguration
.The instance is fully populated during construction.
Parameters: - specFile (
str
) – Archive specification file name (the “.aa file”). - configuration (
IConfiguration
) – The application’s configuration. - componentUi (
CmdlineUi
) – The application’s UI interface. IfNone
then messages about non-accessible files or other errors during processing of included and excluded file lists will not be shown.
Raises: - IOError – If
specFile
can not be opened. - LookupError – If a section or an option is missing in
specFile
. - SyntaxError – If
specFile
can not be parsed. - KeyError – If an invalid (unsupported) section or option is found in the archive specification file.
- ValueError – If option’s value is not correct.
- specFile (
-
class
AutoArchive._application.archiving._archive_spec.
_ArchiveSpecOptions
[source]¶ Bases:
object
Constants for options used specifically in the archive specification file.
These constants should be used to access options in
_ArchiveSpec
.Note
It is not allowed to change values of these constants.
-
EXCLUDE_FILES
= <Option exclude-files of type <class 'str'>>¶ Files and directories that will be excluded from the backup (
frozenset<str>
). Note that frozenset<str> is not supported byOptionsUtils.strToOptionType()
; it is not used while populating this option. Guaranteed to be defined.
-
INCLUDE_FILES
= <Option include-files of type <class 'str'>>¶ Files and directories that will be included in the backup (
frozenset<str>
). Note that frozenset<str> is not supported byOptionsUtils.strToOptionType()
; it is not used while populating this option. Guaranteed to be defined.
-
NAME
= <Option name of type <class 'str'>>¶ Archive name (
str
). Guaranteed to be defined.
-
PATH
= <Option path of type path>¶ Path to the base directory for
INCLUDE_FILES
,EXCLUDE_FILES
(SpecialOptionTypes.PATH
). Guaranteed to be defined.
-
_archive_info¶
_BackupLevelRestartReasons
enum and _ArchiveInfo
class.
-
class
AutoArchive._application.archiving._archive_info.
_ArchiveInfo
(name)[source]¶ Bases:
object
Information about an archive.
Note
Class should be instantiated by calling the
_Archiving.getArchiveInfo()
or_Archiving.getStoredArchiveInfo()
factory methods.-
archiverType
¶ Gets the archiver type for this archive.
Note
Value is guaranteed to be non-
None
.Return type: ArchiverTypes
-
backupLevel
¶ Gets the current backup level.
Note
Will be
None
if the archive is not incremental or usedarchiverType
does not support incremental archiving.Note
For archiver types that supports incremental archiving, whether the return value will be
None
or not does not depend on the currentincremental
value. If the archive was configured and created as incremental previously then the backup level will be defined even if the currentincremental
value would beFalse
and vice versa.Return type: int
-
destDir
¶ Gets the archive’s destination directory.
Note
Value is guaranteed to be non-
None
.Return type: str
-
fullRestartAfterAge
¶ Gets the number of days after which the backup level should be restarted to level 0.
Note
Will be
None
if thearchiverType
does not support incremental archiving or if no value is defined forOptions.FULL_RESTART_AFTER_AGE
.Return type: int
-
fullRestartAfterCount
¶ Gets the number of restarts after which the backup level will be restarted to 0.
Note
Will be
None
if thearchiverType
does not support incremental archiving or if no value is defined forOptions.FULL_RESTART_AFTER_COUNT
.Return type: int
-
incremental
¶ Gets the status of incremental archiving activation.
Note
Will be
None
if thearchiverType
does not support incremental archiving.Return type: bool
-
lastFullRestart
¶ Gets the date when the last backup level restart to level 0 occurred.
Note
Will be
None
if thearchiverType
does not support incremental archiving or ifrestarting
was not enabled for the archive in the past.Return type: datetime.date
-
lastRestart
¶ Gets the date when the last backup level restart occurred.
Note
Will be
None
if thearchiverType
does not support incremental archiving or ifrestarting
was not enabled for the archive in the past.Return type: datetime.date
-
name
¶ Gets the name of the archive.
Return type: str
-
nextBackupLevel
¶ Gets the next backup level.
See also
backupLevel
.Note
Will be
None
if the archive is not incremental or usedarchiverType
does not support incremental archiving.Return type: int
-
path
¶ Gets the path to the archive’s root.
Note
Will be
None
if the archive’s root can not be retrieved.Return type: str
-
restartAfterAge
¶ Gets the number of days after which the backup level should be restarted.
Note
Will be
None
if thearchiverType
does not support incremental archiving or if no value is defined forOptions.RESTART_AFTER_AGE
.Return type: int
-
restartAfterLevel
¶ Gets the maximal backup level; after it is reached it will be restarted to a lower value.
Note
Will be
None
if thearchiverType
does not support incremental archiving.Return type: int
-
restartCount
¶ Gets the number of backup level restarts already performed.
Note
Will be
None
if thearchiverType
does not support incremental archiving or ifrestarting
was not enabled for the archive in the past.Return type: int
-
restartLevel
¶ Gets a backup level to which a next restart would be done.
Note
Will be
None
if thearchiverType
does not support incremental archiving.Return type: int
-
restartReason
¶ Gets the reason for the upcoming backup level restart.
Note
Will be
None
if thearchiverType
does not support incremental archiving or the restart reason can not be determined.Return type: _BackupLevelRestartReasons
-
restarting
¶ Gets the status of backup level restarting activation.
Note
Will be
None
if thearchiverType
does not support incremental archiving.Return type: bool
-
-
AutoArchive._application.archiving._archive_info.
_BackupLevelRestartReasons
¶