Package CedarBackup2 :: Package extend :: Module subversion
[show private | hide private]
[frames | no frames]

Module CedarBackup2.extend.subversion

Provides an extension to back up Subversion databases.

This is a Cedar Backup extension used to back up Subversion repositories via the Cedar Backup command line. It requires a new configurations section <subversion> and is intended to be run either immediately before or immediately after the standard collect action. Aside from its own configuration, it requires the options and collect configuration sections in the standard Cedar Backup configuration file.

There are two different kinds of Subversion repositories at this writing: BDB (Berkeley Database) and fsfs (a more CVS-like "filesystem within a filesystem"). I personally only use the BDB version, because when I started using Subversion, that's all there was. This extension only backs up BDB repositories. If I ever start using fsfs, I'll add another function to back up that kind of repository as well. (Feel free to contribute code if you would like to see fsfs supported.)

Each repository can be backed using the same collect modes allowed for filesystems in the standard Cedar Backup collect action: weekly, daily, incremental.

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

Classes
BDBRepository Class representing Subversion BDB (Berkeley Database) repository configuration.
LocalConfig Class representing this extension's configuration document.
Repository Class representing generic Subversion repository configuration..
SubversionConfig Class representing Subversion configuration.

Function Summary
  _backupBDBRepository(config, repositoryPath, backupPath, revisionPath, fullBackup, collectMode, compressMode)
Backs up an individual Subversion BDB repository.
  _getBackupPath(config, repository, compressMode)
Gets the backup file path (including correct extension) associated with a repository.
  _getCollectMode(local, repository)
Gets the collect mode that should be used for a repository.
  _getCompressMode(local, repository)
Gets the compress mode that should be used for a repository.
  _getOutputFile(backupPath, compressMode)
Opens the output file used for saving the Subversion dump.
  _getRevisionPath(config, repository)
Gets the path to the revision file associated with a repository.
  _loadLastRevision(revisionPath)
Loads the indicated revision file from disk into an integer.
  _writeLastRevision(config, revisionPath, endRevision)
Writes the end revision to the indicated revision file on disk.
  backupBDBRepository(repositoryPath, backupFile, startRevision, endRevision)
Backs up an individual Subversion BDB repository.
  executeAction(configPath, options, config)
Executes the Subversion backup action.
  getYoungestRevision(repositoryPath)
Gets the youngest (newest) revision in a Subversion repository using svnlook.

Function Details

_backupBDBRepository(config, repositoryPath, backupPath, revisionPath, fullBackup, collectMode, compressMode)

Backs up an individual Subversion BDB repository.

This internal method wraps the public method and adds some functionality to work better with the extended action itself.
Parameters:
config - Cedar Backup configuration.
repositoryPath - Path to Subversion repository to back up.
backupPath - Path to backup file that will be written.
revisionPath - Path used to store incremental revision information.
fullBackup - Indicates whether this should be a full backup.
collectMode - Collect mode to use.
compressMode - Compress mode to use.
Raises:
ValueError - If some value is missing or invalid.
IOError - If there is a problem executing the Subversion dump.

_getBackupPath(config, repository, compressMode)

Gets the backup file path (including correct extension) associated with a repository.
Parameters:
config - Config object.
repository - BDBRepository object.
compressMode - Compress mode to use for this repository.
Returns:
Absolute path to the backup file associated with the repository.

_getCollectMode(local, repository)

Gets the collect mode that should be used for a repository. Use repository's if possible, otherwise take from subversion section.
Parameters:
repository - BDBRepository object.
Returns:
Collect mode to use.

_getCompressMode(local, repository)

Gets the compress mode that should be used for a repository. Use repository's if possible, otherwise take from subversion section.
Parameters:
local - LocalConfig object.
repository - BDBRepository object.
Returns:
Compress mode to use.

_getOutputFile(backupPath, compressMode)

Opens the output file used for saving the Subversion dump.

If the compress mode is "gzip", we'll open a GzipFile, and if the compress mode is "bzip2", we'll open a BZ2File. Otherwise, we'll just return an object from the normal open() method.
Parameters:
backupPath - Path to file to open.
compressMode - Compress mode of file ("none", "gzip", "bzip").
Returns:
Output file object.

_getRevisionPath(config, repository)

Gets the path to the revision file associated with a repository.
Parameters:
config - Config object.
repository - BDBRepository object.
Returns:
Absolute path to the revision file associated with the repository.

_loadLastRevision(revisionPath)

Loads the indicated revision file from disk into an integer.

If we can't load the revision file successfully (either because it doesn't exist or for some other reason), then a revision of -1 will be returned - but the condition will be logged. This way, we err on the side of backing up too much, because anyone using this will presumably be adding 1 to the revision, so they don't duplicate any backups.
Parameters:
revisionPath - Path to the revision file on disk.
Returns:
Integer representing last backed-up revision, -1 on error or if none can be read.

_writeLastRevision(config, revisionPath, endRevision)

Writes the end revision to the indicated revision file on disk.

If we can't write the revision file successfully for any reason, we'll log the condition but won't throw an exception.
Parameters:
config - Config object.
revisionPath - Path to the revision file on disk.
endRevision - Last revision backed up on this run.

backupBDBRepository(repositoryPath, backupFile, startRevision=None, endRevision=None)

Backs up an individual Subversion BDB repository.

The starting and ending revision values control an incremental backup. If the starting revision is not passed in, then revision zero (the start of the repository) is assumed. If the ending revision is not passed in, then the youngest revision in the database will be used as the endpoint.

The backup data will be written into the passed-in back file. Normally, this would be an object as returned from open, but it is possible to use something like a GzipFile to write compressed output. The caller is responsible for closing the passed-in backup file.
Parameters:
repositoryPath - Path to Subversion repository to back up
           (type=String path representing Subversion BDB repository on disk.)
backupFile - Python file object to use for writing backup.
           (type=Python file object as from open() or file().)
startRevision - Starting repository revision to back up (for incremental backups)
           (type=Integer value >= 0.)
endRevision - Ending repository revision to back up (for incremental backups)
           (type=Integer value >= 0.)
Raises:
ValueError - If some value is missing or invalid.
IOError - If there is a problem executing the MySQL dump.

Notes:

  • This function should either be run as root or as the owner of the Subversion repository.
  • It is apparently not a good idea to interrupt this function. Sometimes, this leaves the repository in a "wedged" state, which requires recovery using svnadmin recover.

executeAction(configPath, options, config)

Executes the Subversion 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 a backup could not be written for some reason.

getYoungestRevision(repositoryPath)

Gets the youngest (newest) revision in a Subversion repository using svnlook.
Parameters:
repositoryPath - Path to Subversion repository to look in.
           (type=String path representing Subversion BDB repository on disk.)
Returns:
Youngest revision as an integer.
Raises:
ValueError - If there is a problem parsing the svnlook output.
IOError - If there is a problem executing the svnlook command.

Note: This function should either be run as root or as the owner of the Subversion repository.


Generated by Epydoc 2.1 on Wed Mar 9 22:55:59 2005 http://epydoc.sf.net