Package CedarBackup2 :: Module peer :: Class LocalPeer
[hide private]
[frames] | no frames]

Class LocalPeer

source code

object --+
         |
        LocalPeer

Backup peer representing a local peer in a backup pool.

This is a class representing a local (non-network) peer in a backup pool. Local peers are backed up by simple filesystem copy operations. A local peer has associated with it a name (typically, but not necessarily, a hostname) and a collect directory.

The public methods other than the constructor are part of a "backup peer" interface shared with the RemotePeer class.

Instance Methods [hide private]
 
__init__(self, name, collectDir, ignoreFailureMode=None)
Initializes a local backup peer.
source code
 
stagePeer(self, targetDir, ownership=None, permissions=None)
Stages data from the peer into the indicated local target directory.
source code
 
checkCollectIndicator(self, collectIndicator=None)
Checks the collect indicator in the peer's staging directory.
source code
 
writeStageIndicator(self, stageIndicator=None, ownership=None, permissions=None)
Writes the stage indicator in the peer's staging directory.
source code
 
_setName(self, value)
Property target used to set the peer name.
source code
 
_getName(self)
Property target used to get the peer name.
source code
 
_setCollectDir(self, value)
Property target used to set the collect directory.
source code
 
_getCollectDir(self)
Property target used to get the collect directory.
source code
 
_setIgnoreFailureMode(self, value)
Property target used to set the ignoreFailure mode.
source code
 
_getIgnoreFailureMode(self)
Property target used to get the ignoreFailure mode.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods [hide private]
 
_copyLocalDir(sourceDir, targetDir, ownership=None, permissions=None)
Copies files from the source directory to the target directory.
source code
 
_copyLocalFile(sourceFile=None, targetFile=None, ownership=None, permissions=None, overwrite=True)
Copies a source file to a target file.
source code
Properties [hide private]
  name
Name of the peer.
  collectDir
Path to the peer's collect directory (an absolute local path).
  ignoreFailureMode
Ignore failure mode for peer.

Inherited from object: __class__

Method Details [hide private]

__init__(self, name, collectDir, ignoreFailureMode=None)
(Constructor)

source code 

Initializes a local backup peer.

Note that the collect directory must be an absolute path, but does not have to exist when the object is instantiated. We do a lazy validation on this value since we could (potentially) be creating peer objects before an ongoing backup completed.

Parameters:
  • name (String, typically a hostname) - Name of the backup peer
  • collectDir (String representing an absolute local path on disk) - Path to the peer's collect directory
  • ignoreFailureMode (One of VALID_FAILURE_MODES) - Ignore failure mode for this peer
Raises:
  • ValueError - If the name is empty.
  • ValueError - If collect directory is not an absolute path.
Overrides: object.__init__

stagePeer(self, targetDir, ownership=None, permissions=None)

source code 

Stages data from the peer into the indicated local target directory.

The collect and target directories must both already exist before this method is called. If passed in, ownership and permissions will be applied to the files that are copied.

Parameters:
  • targetDir (String representing a directory on disk) - Target directory to write data into
  • ownership (Tuple of numeric ids (uid, gid)) - Owner and group that the staged files should have
  • permissions (UNIX permissions mode, specified in octal (i.e. 0640).) - Permissions that the staged files should have
Returns:
Number of files copied from the source directory to the target directory.
Raises:
  • ValueError - If collect directory is not a directory or does not exist
  • ValueError - If target directory is not a directory, does not exist or is not absolute.
  • ValueError - If a path cannot be encoded properly.
  • IOError - If there were no files to stage (i.e. the directory was empty)
  • IOError - If there is an IO error copying a file.
  • OSError - If there is an OS error copying or changing permissions on a file
Notes:
  • The caller is responsible for checking that the indicator exists, if they care. This function only stages the files within the directory.
  • If you have user/group as strings, call the util.getUidGid function to get the associated uid/gid as an ownership tuple.

checkCollectIndicator(self, collectIndicator=None)

source code 

Checks the collect indicator in the peer's staging directory.

When a peer has completed collecting its backup files, it will write an empty indicator file into its collect directory. This method checks to see whether that indicator has been written. We're "stupid" here - if the collect directory doesn't exist, you'll naturally get back False.

If you need to, you can override the name of the collect indicator file by passing in a different name.

Parameters:
  • collectIndicator (String representing name of a file in the collect directory) - Name of the collect indicator file to check
Returns:
Boolean true/false depending on whether the indicator exists.
Raises:
  • ValueError - If a path cannot be encoded properly.

writeStageIndicator(self, stageIndicator=None, ownership=None, permissions=None)

source code 

Writes the stage indicator in the peer's staging directory.

When the master has completed collecting its backup files, it will write an empty indicator file into the peer's collect directory. The presence of this file implies that the staging process is complete.

If you need to, you can override the name of the stage indicator file by passing in a different name.

Parameters:
  • stageIndicator (String representing name of a file in the collect directory) - Name of the indicator file to write
  • ownership (Tuple of numeric ids (uid, gid)) - Owner and group that the indicator file should have
  • permissions (UNIX permissions mode, specified in octal (i.e. 0640).) - Permissions that the indicator file should have
Raises:
  • ValueError - If collect directory is not a directory or does not exist
  • ValueError - If a path cannot be encoded properly.
  • IOError - If there is an IO error creating the file.
  • OSError - If there is an OS error creating or changing permissions on the file

Note: If you have user/group as strings, call the util.getUidGid function to get the associated uid/gid as an ownership tuple.

_copyLocalDir(sourceDir, targetDir, ownership=None, permissions=None)
Static Method

source code 

Copies files from the source directory to the target directory.

This function is not recursive. Only the files in the directory will be copied. Ownership and permissions will be left at their default values if new values are not specified. The source and target directories are allowed to be soft links to a directory, but besides that soft links are ignored.

Parameters:
  • sourceDir (String representing a directory on disk) - Source directory
  • targetDir (String representing a directory on disk) - Target directory
  • ownership (Tuple of numeric ids (uid, gid)) - Owner and group that the copied files should have
  • permissions (UNIX permissions mode, specified in octal (i.e. 0640).) - Permissions that the staged files should have
Returns:
Number of files copied from the source directory to the target directory.
Raises:
  • ValueError - If source or target is not a directory or does not exist.
  • ValueError - If a path cannot be encoded properly.
  • IOError - If there is an IO error copying the files.
  • OSError - If there is an OS error copying or changing permissions on a files

Note: If you have user/group as strings, call the util.getUidGid function to get the associated uid/gid as an ownership tuple.

_copyLocalFile(sourceFile=None, targetFile=None, ownership=None, permissions=None, overwrite=True)
Static Method

source code 

Copies a source file to a target file.

If the source file is None then the target file will be created or overwritten as an empty file. If the target file is None, this method is a no-op. Attempting to copy a soft link or a directory will result in an exception.

Parameters:
  • sourceFile (String representing a file on disk, as an absolute path) - Source file to copy
  • targetFile (String representing a file on disk, as an absolute path) - Target file to create
  • ownership (Tuple of numeric ids (uid, gid)) - Owner and group that the copied should have
  • permissions (UNIX permissions mode, specified in octal (i.e. 0640).) - Permissions that the staged files should have
  • overwrite (Boolean true/false.) - Indicates whether it's OK to overwrite the target file.
Raises:
  • ValueError - If the passed-in source file is not a regular file.
  • ValueError - If a path cannot be encoded properly.
  • IOError - If the target file already exists.
  • IOError - If there is an IO error copying the file
  • OSError - If there is an OS error copying or changing permissions on a file
Notes:
  • If you have user/group as strings, call the util.getUidGid function to get the associated uid/gid as an ownership tuple.
  • We will not overwrite a target file that exists when this method is invoked. If the target already exists, we'll raise an exception.

_setName(self, value)

source code 

Property target used to set the peer name. The value must be a non-empty string and cannot be None.

Raises:
  • ValueError - If the value is an empty string or None.

_setCollectDir(self, value)

source code 

Property target used to set the collect directory. The value must be an absolute path and cannot be None. It does not have to exist on disk at the time of assignment.

Raises:
  • ValueError - If the value is None or is not an absolute path.
  • ValueError - If a path cannot be encoded properly.

_setIgnoreFailureMode(self, value)

source code 

Property target used to set the ignoreFailure mode. If not None, the mode must be one of the values in VALID_FAILURE_MODES.

Raises:
  • ValueError - If the value is not valid.

Property Details [hide private]

name

Name of the peer.

Get Method:
_getName(self) - Property target used to get the peer name.
Set Method:
_setName(self, value) - Property target used to set the peer name.

collectDir

Path to the peer's collect directory (an absolute local path).

Get Method:
_getCollectDir(self) - Property target used to get the collect directory.
Set Method:
_setCollectDir(self, value) - Property target used to set the collect directory.

ignoreFailureMode

Ignore failure mode for peer.

Get Method:
_getIgnoreFailureMode(self) - Property target used to get the ignoreFailure mode.
Set Method:
_setIgnoreFailureMode(self, value) - Property target used to set the ignoreFailure mode.