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

Module CedarBackup2.actions.store

Implements the standard 'store' action.

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

Function Summary
  executeStore(configPath, options, config)
Executes the store backup action.
  createWriter(config)
Creates a writer object based on current configuration.
  writeImage(config, newDisc, stagingDirs)
Builds and writes an ISO image containing the indicated stage directories.
  writeStoreIndicator(config, stagingDirs)
Writes a store indicator file into staging directories.
  consistencyCheck(config, stagingDirs)
Runs a consistency check against media in the backup device.
  _findCorrectDailyDir(options, config)
Finds the correct daily staging directory to be written to disk.
  _getDeviceType(config)
Gets the device type that should be used for storing.
  _getMediaType(config)
Gets the media type that should be used for storing.

Variable Summary
Logger logger = <logging.Logger instance at 0x402e76ec>

Function Details

executeStore(configPath, options, config)

Executes the store backup action.
Parameters:
configPath - Path to configuration file on disk.
           (type=String representing a path on disk.)
options - Program command-line options.
           (type=Options object.)
config - Program configuration.
           (type=Config object.)
Raises:
ValueError - Under many generic error conditions
IOError - If there are problems reading or writing files.

Notes:

  • The rebuild action and the store action are very similar. The main difference is that while store only stores a single day's staging directory, the rebuild action operates on multiple staging directories.
  • When the store action is complete, we will write a store indicator to the daily staging directory we used, so it's obvious that the store action has completed.

createWriter(config)

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.

writeImage(config, newDisc, stagingDirs)

Builds and writes an ISO image containing the indicated stage directories.

The generated image will contain each of the staging directories listed in stagingDirs. The directories will be placed into the image at the root by date, so staging directory /opt/stage/2005/02/10 will be placed into the disc at /2005/02/10.
Parameters:
config - Config object.
newDisc - Indicates whether the disc should be re-initialized
stagingDirs - Dictionary mapping directory path to date suffix.
Raises:
ValueError - Under many generic error conditions
IOError - If there is a problem writing the image to disc.

writeStoreIndicator(config, stagingDirs)

Writes a store indicator file into staging directories.

The store indicator is written into each of the staging directories when either a store or rebuild action has written the staging directory to disc.
Parameters:
config - Config object.
stagingDirs - Dictionary mapping directory path to date suffix.

consistencyCheck(config, stagingDirs)

Runs a consistency check against media in the backup device.

It seems that sometimes, it's possible to create a corrupted multisession disc (i.e. one that cannot be read) although no errors were encountered while writing the disc. This consistency check makes sure that the data read from disc matches the data that was used to create the disc.

The function mounts the device at a temporary mount point in the working directory, and then compares the indicated staging directories in the staging directory and on the media. The comparison is done via functionality in filesystem.py.

If no exceptions are thrown, there were no problems with the consistency check. A positive confirmation of "no problems" is also written to the log with info priority.
Parameters:
config - Config object.
stagingDirs - Dictionary mapping directory path to date suffix.
Raises:
ValueError - If the two directories are not equivalent.
IOError - If there is a problem working with the media.

Warning: The implementation of this function is very UNIX-specific.

_findCorrectDailyDir(options, config)

Finds the correct daily staging directory to be written to disk.

In Cedar Backup v1.0, we assumed that the correct staging directory matched the current date. However, that has problems. In particular, it breaks down if collect is on one side of midnite and stage is on the other, or if certain processes span midnite.

For v2.0, I'm trying to be smarter. I'll first check the current day. If that directory is found, it's good enough. If it's not found, I'll look for a valid directory from the day before or day after which has not yet been staged, according to the stage indicator file. The first one I find, I'll use. If I use a directory other than for the current day and config.store.warnMidnite is set, a warning will be put in the log.

There is one exception to this rule. If the options.full flag is set, then the special "span midnite" logic will be disabled and any existing store indicator will be ignored. I did this because I think that most users who run cback --full store twice in a row expect the command to generate two identical discs. With the other rule in place, running that command twice in a row could result in an error ("no unstored directory exists") or could even cause a completely unexpected directory to be written to disc (if some previous day's contents had not yet been written).
Parameters:
options - Options object.
config - Config object.
Returns:
Correct staging dir, as a dict mapping directory to date suffix.
Raises:
IOError - If the staging directory cannot be found.

Note: This code is probably longer and more verbose than it needs to be, but at least it's straightforward.

_getDeviceType(config)

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)

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.

Variable Details

logger

Type:
Logger
Value:
<logging.Logger instance at 0x402e76ec>                                

Generated by Epydoc 2.1 on Fri Feb 23 23:10:13 2007 http://epydoc.sf.net