CedarBackup3.extend.subversion
==============================

.. py:module:: CedarBackup3.extend.subversion

.. autoapi-nested-parse::

   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>









Module Contents
---------------

.. py:data:: logger

.. py:data:: SVNLOOK_COMMAND
   :value: ['svnlook']


.. py:data:: SVNADMIN_COMMAND
   :value: ['svnadmin']


.. py:data:: REVISION_PATH_EXTENSION
   :value: 'svnlast'


.. py:class:: RepositoryDir(repositoryType=None, directoryPath=None, collectMode=None, compressMode=None, relativeExcludePaths=None, excludePatterns=None)

   Class representing Subversion repository directory.

   A repository directory is a directory that contains one or more Subversion
   repositories.

   The following restrictions exist on data in this class:

      - The directory path must be absolute.
      - The collect mode must be one of the values in :any:`VALID_COLLECT_MODES`.
      - The compress mode must be one of the values in :any:`VALID_COMPRESS_MODES`.

   The repository type value is kept around just for reference.  It doesn't
   affect the behavior of the backup.

   Relative exclusions are allowed here.  However, there is no configured
   ignore file, because repository dir backups are not recursive.



   .. py:attribute:: repositoryType
      :value: None



   .. py:attribute:: directoryPath
      :value: None



   .. py:attribute:: collectMode
      :value: None



   .. py:attribute:: compressMode
      :value: None



   .. py:attribute:: relativeExcludePaths
      :value: None



   .. py:attribute:: excludePatterns
      :value: None



   .. py:method:: __repr__()

      Official string representation for class instance.



   .. py:method:: __str__()

      Informal string representation for class instance.



   .. py:method:: __eq__(other)

      Equals operator, iplemented in terms of original Python 2 compare operator.



   .. py:method:: __lt__(other)

      Less-than operator, iplemented in terms of original Python 2 compare operator.



   .. py:method:: __gt__(other)

      Greater-than operator, iplemented in terms of original Python 2 compare operator.



   .. py:method:: __cmp__(other)

      Original Python 2 comparison operator.
      :param other: Other object to compare to

      :returns: -1/0/1 depending on whether self is ``<``, ``=`` or ``>`` other



.. py:class:: Repository(repositoryType=None, repositoryPath=None, collectMode=None, compressMode=None)

   Class representing generic Subversion repository configuration..

   The following restrictions exist on data in this class:

      - The respository path must be absolute.
      - The collect mode must be one of the values in :any:`VALID_COLLECT_MODES`.
      - The compress mode must be one of the values in :any:`VALID_COMPRESS_MODES`.

   The repository type value is kept around just for reference.  It doesn't
   affect the behavior of the backup.



   .. py:attribute:: repositoryType
      :value: None



   .. py:attribute:: repositoryPath
      :value: None



   .. py:attribute:: collectMode
      :value: None



   .. py:attribute:: compressMode
      :value: None



   .. py:method:: __repr__()

      Official string representation for class instance.



   .. py:method:: __str__()

      Informal string representation for class instance.



   .. py:method:: __eq__(other)

      Equals operator, iplemented in terms of original Python 2 compare operator.



   .. py:method:: __lt__(other)

      Less-than operator, iplemented in terms of original Python 2 compare operator.



   .. py:method:: __gt__(other)

      Greater-than operator, iplemented in terms of original Python 2 compare operator.



   .. py:method:: __cmp__(other)

      Original Python 2 comparison operator.
      :param other: Other object to compare to

      :returns: -1/0/1 depending on whether self is ``<``, ``=`` or ``>`` other



.. py:class:: SubversionConfig(collectMode=None, compressMode=None, repositories=None, repositoryDirs=None)

   Class representing Subversion configuration.

   Subversion configuration is used for backing up Subversion repositories.

   The following restrictions exist on data in this class:

      - The collect mode must be one of the values in :any:`VALID_COLLECT_MODES`.
      - The compress mode must be one of the values in :any:`VALID_COMPRESS_MODES`.
      - The repositories list must be a list of ``Repository`` objects.
      - The repositoryDirs list must be a list of ``RepositoryDir`` objects.

   For the two lists, validation is accomplished through the
   :any:`util.ObjectTypeList` list implementation that overrides common list
   methods and transparently ensures that each element has the correct type.

   *Note:* Lists within this class are "unordered" for equality comparisons.



   .. py:attribute:: collectMode
      :value: None



   .. py:attribute:: compressMode
      :value: None



   .. py:attribute:: repositories
      :value: None



   .. py:attribute:: repositoryDirs
      :value: None



   .. py:method:: __repr__()

      Official string representation for class instance.



   .. py:method:: __str__()

      Informal string representation for class instance.



   .. py:method:: __eq__(other)

      Equals operator, iplemented in terms of original Python 2 compare operator.



   .. py:method:: __lt__(other)

      Less-than operator, iplemented in terms of original Python 2 compare operator.



   .. py:method:: __gt__(other)

      Greater-than operator, iplemented in terms of original Python 2 compare operator.



   .. py:method:: __cmp__(other)

      Original Python 2 comparison operator.
      Lists within this class are "unordered" for equality comparisons.
      :param other: Other object to compare to

      :returns: -1/0/1 depending on whether self is ``<``, ``=`` or ``>`` other



.. py:class:: LocalConfig(xmlData=None, xmlPath=None, validate=True)

   Class representing this extension's configuration document.

   This is not a general-purpose configuration object like the main Cedar
   Backup configuration object.  Instead, it just knows how to parse and emit
   Subversion-specific configuration values.  Third parties who need to read
   and write configuration related to this extension should access it through
   the constructor, ``validate`` and ``addConfig`` methods.

   *Note:* Lists within this class are "unordered" for equality comparisons.



   .. py:attribute:: subversion
      :value: None



   .. py:method:: __repr__()

      Official string representation for class instance.



   .. py:method:: __str__()

      Informal string representation for class instance.



   .. py:method:: __eq__(other)

      Equals operator, iplemented in terms of original Python 2 compare operator.



   .. py:method:: __lt__(other)

      Less-than operator, iplemented in terms of original Python 2 compare operator.



   .. py:method:: __gt__(other)

      Greater-than operator, iplemented in terms of original Python 2 compare operator.



   .. py:method:: __cmp__(other)

      Original Python 2 comparison operator.
      Lists within this class are "unordered" for equality comparisons.
      :param other: Other object to compare to

      :returns: -1/0/1 depending on whether self is ``<``, ``=`` or ``>`` other



   .. py:method:: validate()

      Validates configuration represented by the object.

      Subversion configuration must be filled in.  Within that, the collect
      mode and compress mode are both optional, but the list of repositories
      must contain at least one entry.

      Each repository must contain a repository path, and then must be either
      able to take collect mode and compress mode configuration from the parent
      ``SubversionConfig`` object, or must set each value on its own.

      :raises ValueError: If one of the validations fails



   .. py:method:: addConfig(xmlDom, parentNode)

      Adds a <subversion> configuration section as the next child of a parent.

      Third parties should use this function to write configuration related to
      this extension.

      We add the following fields to the document::

         collectMode    //cb_config/subversion/collectMode
         compressMode   //cb_config/subversion/compressMode

      We also add groups of the following items, one list element per
      item::

         repository     //cb_config/subversion/repository
         repository_dir //cb_config/subversion/repository_dir

      :param xmlDom: DOM tree as from ``impl.createDocument()``
      :param parentNode: Parent that the section should be appended to



.. py:function:: executeAction(configPath, options, config)

   Executes the Subversion backup action.

   :param configPath: Path to configuration file on disk
   :type configPath: String representing a path on disk
   :param options: Program command-line options
   :type options: Options object
   :param config: Program configuration
   :type config: Config object

   :raises ValueError: Under many generic error conditions
   :raises IOError: If a backup could not be written for some reason


.. py:function:: backupRepository(repositoryPath, backupFile, startRevision=None, endRevision=None)

   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.

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

   *Note:* 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``.

   :param repositoryPath: Path to Subversion repository to back up
   :type repositoryPath: String path representing Subversion repository on disk
   :param backupFile: Python file object to use for writing backup
   :type backupFile: Python file object as from ``open`` or ``file``
   :param startRevision: Starting repository revision to back up (for incremental backups)
   :type startRevision: Integer value >= 0
   :param endRevision: Ending repository revision to back up (for incremental backups)
   :type endRevision: Integer value >= 0

   :raises ValueError: If some value is missing or invalid
   :raises IOError: If there is a problem executing the Subversion dump


.. py:function:: getYoungestRevision(repositoryPath)

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

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

   :param repositoryPath: Path to Subversion repository to look in
   :type repositoryPath: String path representing Subversion repository on disk

   :returns: Youngest revision as an integer

   :raises ValueError: If there is a problem parsing the ``svnlook`` output
   :raises IOError: If there is a problem executing the ``svnlook`` command


.. py:class:: BDBRepository(repositoryPath=None, collectMode=None, compressMode=None)

   Bases: :py:obj:`Repository`


   Class representing Subversion BDB (Berkeley Database) repository configuration.
   This object is deprecated.  Use a simple :any:`Repository` instead.


   .. py:method:: __repr__()

      Official string representation for class instance.



.. py:class:: FSFSRepository(repositoryPath=None, collectMode=None, compressMode=None)

   Bases: :py:obj:`Repository`


   Class representing Subversion FSFS repository configuration.
   This object is deprecated.  Use a simple :any:`Repository` instead.


   .. py:method:: __repr__()

      Official string representation for class instance.



.. py:function:: backupBDBRepository(repositoryPath, backupFile, startRevision=None, endRevision=None)

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


.. py:function:: backupFSFSRepository(repositoryPath, backupFile, startRevision=None, endRevision=None)

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


