CedarBackup2.actions.util

Package CedarBackup2 :: Package actions :: Module util |
[hide private]
[frames] | no frames]

# Module util

source code

Implements action-related utilities

Author: Kenneth J. Pronovici <pronovic@ieee.org>

Functions | [hide private]
findDailyDirs(stagingDir, indicatorFile) Returns a list of all daily staging directories that do not contain the indicated indicator file. | source code
createWriter(config) Creates a writer object based on current configuration. | source code
writeIndicatorFile(targetDir, indicatorFile, backupUser, backupGroup) Writes an indicator file into a target directory. | source code
getBackupFiles(targetDir) Gets a list of backup files in a target directory. | source code
checkMediaState(storeConfig) Checks state of the media in the backup device to confirm whether it has been initialized for use with Cedar Backup. | source code
initializeMediaState(config) Initializes state of the media in the backup device so Cedar Backup can recognize it. | source code
buildMediaLabel() Builds a media label to be used on Cedar Backup media. | source code
_getDeviceType(config) Gets the device type that should be used for storing. | source code
_getMediaType(config) Gets the media type that should be used for storing. | source code

Variables | [hide private]
| logger = `logging.getLogger("CedarBackup2.log.actions.util")`
| MEDIA_LABEL_PREFIX = ``'``CEDAR BACKUP``'``
| __package__ = ``'``CedarBackup2.actions``'``

Function Details | [hide private]

### findDailyDirs(stagingDir, indicatorFile) | source code
Returns a list of all daily staging directories that do not contain the indicated indicator file. Parameters: `stagingDir` - Configured staging directory (config.targetDir) Returns: List of absolute paths to daily staging directories.

### createWriter(config) | source code
Creates a writer object based on current configuration. This function creates and returns a writer based on configuration. This is done to abstract action functionality from knowing what kind of writer is in use. Since all writers implement the same interface, there's no need for actions to care which one they're working with. Currently, the `cdwriter` and `dvdwriter` device types are allowed. An exception will be raised if any other device type is used. This function also checks to make sure that the device isn't mounted before creating a writer object for it. Experience shows that sometimes if the device is mounted, we have problems with the backup. We may as well do the check here first, before instantiating the writer. Parameters: `config` - Config object. Returns: Writer that can be used to write a directory to some media. Raises: `ValueError` - If there is a problem getting the writer. `IOError` - If there is a problem creating the writer object.

### writeIndicatorFile(targetDir, indicatorFile, backupUser, backupGroup) | source code
Writes an indicator file into a target directory. Parameters: `targetDir` - Target directory in which to write indicator `indicatorFile` - Name of the indicator file `backupUser` - User that indicator file should be owned by `backupGroup` - Group that indicator file should be owned by Raises: `IOException` - If there is a problem writing the indicator file

### getBackupFiles(targetDir) | source code
Gets a list of backup files in a target directory. Files that match INDICATOR_PATTERN (i.e. `"cback.store"`, `"cback.stage"`, etc.) are assumed to be indicator files and are ignored. Parameters: `targetDir` - Directory to look in Returns: List of backup files in the directory Raises: `ValueError` - If the target directory does not exist

### checkMediaState(storeConfig) | source code
Checks state of the media in the backup device to confirm whether it has been initialized for use with Cedar Backup. We can tell whether the media has been initialized by looking at its media label. If the media label starts with MEDIA_LABEL_PREFIX, then it has been initialized. The check varies depending on whether the media is rewritable or not. For non-rewritable media, we also accept a `None` media label, since this kind of media cannot safely be initialized. Parameters: `storeConfig` - Store configuration Raises: `ValueError` - If media is not initialized.

### initializeMediaState(config) | source code
Initializes state of the media in the backup device so Cedar Backup can recognize it. This is done by writing an mostly-empty image (it contains a "Cedar Backup" directory) to the media with a known media label. Parameters: `config` - Cedar Backup configuration Raises: `ValueError` - If media could not be initialized. `ValueError` - If the configured media type is not rewritable Note: Only rewritable media (CD-RW, DVD+RW) can be initialized. It doesn't make any sense to initialize media that cannot be rewritten (CD-R, DVD+R), since Cedar Backup would then not be able to use that media for a backup.

### buildMediaLabel() | source code
Builds a media label to be used on Cedar Backup media. Returns: Media label as a string.

### _getDeviceType(config) | source code
Gets the device type that should be used for storing. Use the configured device type if not `None`, otherwise use config.DEFAULT_DEVICE_TYPE. Parameters: `config` - Config object. Returns: Device type to be used.

### _getMediaType(config) | source code
Gets the media type that should be used for storing. Use the configured media type if not `None`, otherwise use `DEFAULT_MEDIA_TYPE`. Once we figure out what configuration value to use, we return a media type value that is valid in one of the supported writers:
      MEDIA_CDR_74
      MEDIA_CDRW_74
      MEDIA_CDR_80
      MEDIA_CDRW_80
      MEDIA_DVDPLUSR
      MEDIA_DVDPLUSRW
Parameters: `config` - Config object. Returns: Media type to be used as a writer media type value. Raises: `ValueError` - If the media type is not valid.