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

Module subversion

source code

Provides an extension to back up Subversion repositories.

This is a Cedar Backup extension used to back up Subversion repositories via the Cedar Backup command line. Each Subversion repository can be backed using the same collect modes allowed for filesystems in the standard Cedar Backup collect action: weekly, daily, incremental.

This extension requires a new configuration 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 "filesystem within a filesystem"). Although the repository type can be specified in configuration, that information is just kept around for reference. It doesn't affect the backup. Both kinds of repositories are backed up in the same way, using svnadmin dump in an incremental mode.

It turns out that FSFS repositories can also be backed up just like any other filesystem directory. If you would rather do that, then use the normal collect action. This is probably simpler, although it carries its own advantages and disadvantages (plus you will have to be careful to exclude the working directories Subversion uses when building an update to commit). Check the Subversion documentation for more information.


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

Classes [hide private]
  RepositoryDir
Class representing Subversion repository directory.
  Repository
Class representing generic Subversion repository configuration..
  SubversionConfig
Class representing Subversion configuration.
  LocalConfig
Class representing this extension's configuration document.
  BDBRepository
Class representing Subversion BDB (Berkeley Database) repository configuration.
  FSFSRepository
Class representing Subversion FSFS repository configuration.
Functions [hide private]
 
executeAction(configPath, options, config)
Executes the Subversion backup action.
source code
 
_getCollectMode(local, repository)
Gets the collect mode that should be used for a repository.
source code
 
_getCompressMode(local, repository)
Gets the compress mode that should be used for a repository.
source code
 
_getRevisionPath(config, repository)
Gets the path to the revision file associated with a repository.
source code
 
_getBackupPath(config, repositoryPath, compressMode, startRevision, endRevision)
Gets the backup file path (including correct extension) associated with a repository.
source code
 
_getRepositoryPaths(repositoryDir)
Gets a list of child repository paths within a repository directory.
source code
 
_getExclusions(repositoryDir)
Gets exclusions (file and patterns) associated with an repository directory.
source code
 
_backupRepository(config, local, todayIsStart, fullBackup, repository)
Backs up an individual Subversion repository.
source code
 
_getOutputFile(backupPath, compressMode)
Opens the output file used for saving the Subversion dump.
source code
 
_loadLastRevision(revisionPath)
Loads the indicated revision file from disk into an integer.
source code
 
_writeLastRevision(config, revisionPath, endRevision)
Writes the end revision to the indicated revision file on disk.
source code
 
backupRepository(repositoryPath, backupFile, startRevision=None, endRevision=None)
Backs up an individual Subversion repository.
source code
 
getYoungestRevision(repositoryPath)
Gets the youngest (newest) revision in a Subversion repository using svnlook.
source code
 
backupBDBRepository(repositoryPath, backupFile, startRevision=None, endRevision=None)
Backs up an individual Subversion BDB repository.
source code
 
backupFSFSRepository(repositoryPath, backupFile, startRevision=None, endRevision=None)
Backs up an individual Subversion FSFS repository.
source code
Variables [hide private]
  logger = logging.getLogger("CedarBackup2.log.extend.subversion")
  SVNLOOK_COMMAND = ['svnlook']
  SVNADMIN_COMMAND = ['svnadmin']
  REVISION_PATH_EXTENSION = 'svnlast'
  __package__ = 'CedarBackup2.extend'
Function Details [hide private]

executeAction(configPath, options, config)

source code 

Executes the Subversion backup action.

Parameters:
  • configPath (String representing a path on disk.) - Path to configuration file on disk.
  • options (Options object.) - Program command-line options.
  • config (Config object.) - Program configuration.
Raises:
  • ValueError - Under many generic error conditions
  • IOError - If a backup could not be written for some reason.

_getCollectMode(local, repository)

source code 

Gets the collect mode that should be used for a repository. Use repository's if possible, otherwise take from subversion section.

Parameters:
  • repository - Repository object.
Returns:
Collect mode to use.

_getCompressMode(local, repository)

source code 

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 - Repository object.
Returns:
Compress mode to use.

_getRevisionPath(config, repository)

source code 

Gets the path to the revision file associated with a repository.

Parameters:
  • config - Config object.
  • repository - Repository object.
Returns:
Absolute path to the revision file associated with the repository.

_getBackupPath(config, repositoryPath, compressMode, startRevision, endRevision)

source code 

Gets the backup file path (including correct extension) associated with a repository.

Parameters:
  • config - Config object.
  • repositoryPath - Path to the indicated repository
  • compressMode - Compress mode to use for this repository.
  • startRevision - Starting repository revision.
  • endRevision - Ending repository revision.
Returns:
Absolute path to the backup file associated with the repository.

_getRepositoryPaths(repositoryDir)

source code 

Gets a list of child repository paths within a repository directory.

Parameters:
  • repositoryDir - RepositoryDirectory

_getExclusions(repositoryDir)

source code 

Gets exclusions (file and patterns) associated with an repository directory.

The returned files value is a list of absolute paths to be excluded from the backup for a given directory. It is derived from the repository directory's relative exclude paths.

The returned patterns value is a list of patterns to be excluded from the backup for a given directory. It is derived from the repository directory's list of patterns.

Parameters:
  • repositoryDir - Repository directory object.
Returns:
Tuple (files, patterns) indicating what to exclude.

_backupRepository(config, local, todayIsStart, fullBackup, repository)

source code 

Backs up an individual Subversion repository.

This internal method wraps the public methods and adds some functionality to work better with the extended action itself.

Parameters:
  • config - Cedar Backup configuration.
  • local - Local configuration
  • todayIsStart - Indicates whether today is start of week
  • fullBackup - Full backup flag
  • repository - Repository to operate on
Raises:
  • ValueError - If some value is missing or invalid.
  • IOError - If there is a problem executing the Subversion dump.

_getOutputFile(backupPath, compressMode)

source code 

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.

_loadLastRevision(revisionPath)

source code 

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)

source code 

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.

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

source code 

Backs up an individual Subversion 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 (String path representing Subversion repository on disk.) - Path to Subversion repository to back up
  • backupFile (Python file object as from open() or file().) - Python file object to use for writing backup.
  • startRevision (Integer value >= 0.) - Starting repository revision to back up (for incremental backups)
  • endRevision (Integer value >= 0.) - Ending repository revision to back up (for incremental backups)
Raises:
  • ValueError - If some value is missing or invalid.
  • IOError - If there is a problem executing the Subversion 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.

getYoungestRevision(repositoryPath)

source code 

Gets the youngest (newest) revision in a Subversion repository using svnlook.

Parameters:
  • repositoryPath (String path representing Subversion repository on disk.) - Path to Subversion repository to look in.
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.

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

source code 

Backs up an individual Subversion BDB repository. This function is deprecated. Use backupRepository instead.

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

source code 

Backs up an individual Subversion FSFS repository. This function is deprecated. Use backupRepository instead.