Package CedarBackup2 :: Package tools :: Module span
[hide private]
[frames] | no frames]

Module span

source code

Spans staged data among multiple discs

This is the Cedar Backup span tool. It is intended for use by people who stage more data than can fit on a single disc. It allows a user to split staged data among more than one disc. It can't be an extension because it requires user input when switching media.

Most configuration is taken from the Cedar Backup configuration file, specifically the store section. A few pieces of configuration are taken directly from the user.


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

Classes [hide private]
  SpanOptions
Tool-specific command-line options.
Functions [hide private]
 
cli()
Implements the command-line interface for the cback-span script.
source code
 
_usage(fd=sys.stdout)
Prints usage information for the cback script.
source code
 
_version(fd=sys.stdout)
Prints version information for the cback script.
source code
 
_executeAction(options, config)
Implements the guts of the cback-span tool.
source code
 
_findDailyDirs(stagingDir)
Returns a list of all daily staging directories that have not yet been stored.
source code
 
_getWriter(config)
Gets a writer and media capacity from store configuration.
source code
 
_writeDisc(config, writer, spanItem)
Writes a span item to disc.
source code
 
_consistencyCheck(config, fileList)
Runs a consistency check against media in the backup device.
source code
 
_getYesNoAnswer(prompt, default)
Get a yes/no answer from the user.
source code
 
_getChoiceAnswer(prompt, default, validChoices)
Get a particular choice from the user.
source code
 
_getFloat(prompt, default)
Get a floating point number from the user.
source code
 
_getReturn(prompt)
Get a return key from the user.
source code
Variables [hide private]
  logger = logging.getLogger("CedarBackup2.log.tools.span")
Function Details [hide private]

cli()

source code 

Implements the command-line interface for the cback-span script.

Essentially, this is the "main routine" for the cback-span script. It does all of the argument processing for the script, and then also implements the tool functionality.

This function looks pretty similiar to CedarBackup2.cli.cli(). It's not easy to refactor this code to make it reusable and also readable, so I've decided to just live with the duplication.

A different error code is returned for each type of failure:
  • 1: The Python interpreter version is < 2.3
  • 2: Error processing command-line arguments
  • 3: Error configuring logging
  • 4: Error parsing indicated configuration file
  • 5: Backup was interrupted with a CTRL-C or similar
  • 6: Error executing other parts of the script
Returns:
Error code as described above.

Note: This script uses print rather than logging to the INFO level, because it is interactive. Underlying Cedar Backup functionality uses the logging mechanism exclusively.

_usage(fd=sys.stdout)

source code 
Prints usage information for the cback script.
Parameters:
  • fd - File descriptor used to print information.

Note: The fd is used rather than print to facilitate unit testing.

_version(fd=sys.stdout)

source code 
Prints version information for the cback script.
Parameters:
  • fd - File descriptor used to print information.

Note: The fd is used rather than print to facilitate unit testing.

_executeAction(options, config)

source code 
Implements the guts of the cback-span tool.
Parameters:
  • options (SpanOptions object.) - Program command-line options.
  • config (Config object.) - Program configuration.
Raises:
  • Exception - Under many generic error conditions

_findDailyDirs(stagingDir)

source code 

Returns a list of all daily staging directories that have not yet been stored.

The store indicator file cback.store will be written to a daily staging directory once that directory is written to disc. So, this function looks at each daily staging directory within the configured staging directory, and returns a list of those which do not contain the indicator file.

Returned is a tuple containing two items: a list of daily staging directories, and a BackupFileList containing all files among those staging directories.
Parameters:
  • stagingDir - Configured staging directory
Returns:
Tuple (staging dirs, backup file list)

_getWriter(config)

source code 
Gets a writer and media capacity from store configuration. Returned is a writer and a media capacity in bytes.
Parameters:
  • config - Cedar Backup configuration
Returns:
Tuple of (writer, mediaCapacity)

_writeDisc(config, writer, spanItem)

source code 
Writes a span item to disc.
Parameters:
  • config - Cedar Backup configuration
  • writer - Writer to use
  • spanItem - Span item to write

_consistencyCheck(config, fileList)

source code 

Runs a consistency check against media in the backup device.

The function mounts the device at a temporary mount point in the working directory, and then compares the passed-in file list's digest map with the one generated from the disc. The two lists should be identical.

If no exceptions are thrown, there were no problems with the consistency check.
Parameters:
  • config - Config object.
  • fileList - BackupFileList whose contents to check against
Raises:
  • ValueError - If the check fails
  • IOError - If there is a problem working with the media.

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

_getYesNoAnswer(prompt, default)

source code 
Get a yes/no answer from the user. The default will be placed at the end of the prompt. A "Y" or "y" is considered yes, anything else no. A blank (empty) response results in the default.
Parameters:
  • prompt - Prompt to show.
  • default - Default to set if the result is blank
Returns:
Boolean true/false corresponding to Y/N

_getChoiceAnswer(prompt, default, validChoices)

source code 
Get a particular choice from the user. The default will be placed at the end of the prompt. The function loops until getting a valid choice. A blank (empty) response results in the default.
Parameters:
  • prompt - Prompt to show.
  • default - Default to set if the result is None or blank.
  • validChoices - List of valid choices (strings)
Returns:
Valid choice from user.

_getFloat(prompt, default)

source code 
Get a floating point number from the user. The default will be placed at the end of the prompt. The function loops until getting a valid floating point number. A blank (empty) response results in the default.
Parameters:
  • prompt - Prompt to show.
  • default - Default to set if the result is None or blank.
Returns:
Floating point number from user

_getReturn(prompt)

source code 
Get a return key from the user.
Parameters:
  • prompt - Prompt to show.