barman.lockfile module#
This module is the lock manager for Barman
- class barman.lockfile.ConfigUpdateLock(lock_directory)View on GitHub#
Bases:
LockFile
This lock protects barman from multiple executions of config-update command
Creates a
.config-update.lock
lock file under the givenlock_directory
.- __init__(lock_directory)View on GitHub#
Initialize a new
ConfigUpdateLock
object.- Parameters:
str (lock_directory) – where to create the
.config-update.lock
file.
- class barman.lockfile.GlobalCronLock(lock_directory)View on GitHub#
Bases:
LockFile
This lock protects cron from multiple executions.
Creates a global ‘.cron.lock’ lock file under the given lock_directory.
- __init__(lock_directory)View on GitHub#
- class barman.lockfile.LockFile(filename, raise_if_fail=True, wait=False)View on GitHub#
Bases:
object
Ensures that there is only one process which is running against a specified LockFile. It supports the Context Manager interface, allowing the use in with statements.
- with LockFile(‘file.lock’) as locked:
- if not locked:
print “failed”
- else:
<do something>
You can also use exceptions on failures
- try:
- with LockFile(‘file.lock’, True):
<do something>
- except LockFileBusy, e, file:
print “failed to lock %s” % file
- LOCK_PATTERN = None#
If defined in a subclass, it must be a compiled regular expression which matches the lock filename.
It must provide named groups for the constructor parameters which produce the same lock name. I.e.:
>>> ServerWalReceiveLock('/tmp', 'server-name').filename '/tmp/.server-name-receive-wal.lock' >>> ServerWalReceiveLock.LOCK_PATTERN = re.compile( r'\.(?P<server_name>.+)-receive-wal\.lock') >>> m = ServerWalReceiveLock.LOCK_PATTERN.match( '.server-name-receive-wal.lock') >>> ServerWalReceiveLock('/tmp', **(m.groupdict())).filename '/tmp/.server-name-receive-wal.lock'
- __init__(filename, raise_if_fail=True, wait=False)View on GitHub#
- acquire(raise_if_fail=None, wait=None, update_pid=True)View on GitHub#
Creates and holds on to the lock file.
When raise_if_fail, a LockFileBusy is raised if the lock is held by someone else and a LockFilePermissionDenied is raised when the user executing barman have insufficient rights for the creation of a LockFile.
Returns True if lock has been successfully acquired, False otherwise.
- classmethod build_if_matches(path)View on GitHub#
Factory method that creates a lock instance if the path matches the lock filename created by the actual class
- Parameters:
path – the full path of a LockFile
- Returns:
- get_owner_pid()View on GitHub#
Test whether a lock is already held by a process.
Returns the PID of the owner process or None if the lock is available.
- Return type:
int|None
- Raises:
LockFileParsingError – when the lock content is garbled
LockFilePermissionDenied – when the lockfile is not accessible
- release()View on GitHub#
Releases the lock.
If the lock is not held by the current process it does nothing.
- class barman.lockfile.ServerBackupIdLock(lock_directory, server_name, backup_id)View on GitHub#
Bases:
LockFile
This lock protects from changing a backup that is in use.
Creates a ‘.<SERVER>-<BACKUP_ID>.lock’ lock file under the given lock_directory for a BACKUP of a SERVER.
- __init__(lock_directory, server_name, backup_id)View on GitHub#
- class barman.lockfile.ServerBackupLock(lock_directory, server_name)View on GitHub#
Bases:
LockFile
This lock protects a server from multiple executions of backup command
Creates a ‘.<SERVER>-backup.lock’ lock file under the given lock_directory for the named SERVER.
- __init__(lock_directory, server_name)View on GitHub#
- class barman.lockfile.ServerBackupSyncLock(lock_directory, server_name, backup_id)View on GitHub#
Bases:
LockFile
This lock protects from multiple executions of the sync command on the same backup.
Creates a ‘.<SERVER>-<BACKUP>-sync-backup.lock’ lock file under the given lock_directory for a BACKUP of a SERVER.
- __init__(lock_directory, server_name, backup_id)View on GitHub#
- class barman.lockfile.ServerCronLock(lock_directory, server_name)View on GitHub#
Bases:
LockFile
This lock protects a server from multiple executions of cron command
Creates a ‘.<SERVER>-cron.lock’ lock file under the given lock_directory for the named SERVER.
- __init__(lock_directory, server_name)View on GitHub#
- class barman.lockfile.ServerWalArchiveLock(lock_directory, server_name)View on GitHub#
Bases:
LockFile
This lock protects a server from multiple executions of wal-archive command
Creates a ‘.<SERVER>-archive-wal.lock’ lock file under the given lock_directory for the named SERVER.
- __init__(lock_directory, server_name)View on GitHub#
- class barman.lockfile.ServerWalReceiveLock(lock_directory, server_name)View on GitHub#
Bases:
LockFile
This lock protects a server from multiple executions of receive-wal command
Creates a ‘.<SERVER>-receive-wal.lock’ lock file under the given lock_directory for the named SERVER.
- LOCK_PATTERN = re.compile('\\.(?P<server_name>.+)-receive-wal\\.lock')#
If defined in a subclass, it must be a compiled regular expression which matches the lock filename.
It must provide named groups for the constructor parameters which produce the same lock name. I.e.:
>>> ServerWalReceiveLock('/tmp', 'server-name').filename '/tmp/.server-name-receive-wal.lock' >>> ServerWalReceiveLock.LOCK_PATTERN = re.compile( r'\.(?P<server_name>.+)-receive-wal\.lock') >>> m = ServerWalReceiveLock.LOCK_PATTERN.match( '.server-name-receive-wal.lock') >>> ServerWalReceiveLock('/tmp', **(m.groupdict())).filename '/tmp/.server-name-receive-wal.lock'
- __init__(lock_directory, server_name)View on GitHub#
- class barman.lockfile.ServerWalSyncLock(lock_directory, server_name)View on GitHub#
Bases:
LockFile
This lock protects from multiple executions of the sync-wal command
Creates a ‘.<SERVER>-sync-wal.lock’ lock file under the given lock_directory for the named SERVER.
- __init__(lock_directory, server_name)View on GitHub#
- class barman.lockfile.ServerXLOGDBLock(lock_directory, server_name)View on GitHub#
Bases:
LockFile
This lock protects a server’s xlogdb access
Creates a ‘.<SERVER>-xlogdb.lock’ lock file under the given lock_directory for the named SERVER.
- __init__(lock_directory, server_name)View on GitHub#