twindb_backup.source package

Submodules

twindb_backup.source.base_source module

Module defines base source class.

class twindb_backup.source.base_source.BaseSource(run_type)[source]

Bases: object

Base source for backup

basename

Return file name (w/o directory part) of the backup.

get_name()[source]

Name that will be used to store backup copy from this source.

get_prefix()[source]

Get prefix of the backup copy. It includes hostname and run type.

Returns:Backup name prefix like ‘db-10/daily’
get_stream()[source]

Get backup stream in a handler

host

Return host where the backup is being taken from.

run_type = None
suffix

Backup file name suffix

twindb_backup.source.exceptions module

Module for backup source exceptions

exception twindb_backup.source.exceptions.BinlogSourceError[source]

Bases: twindb_backup.source.exceptions.SourceError

Exceptions in Binlog source

exception twindb_backup.source.exceptions.MySQLSourceError[source]

Bases: twindb_backup.source.exceptions.SourceError

Exceptions in MySQL source

exception twindb_backup.source.exceptions.RemoteMySQLSourceError[source]

Bases: twindb_backup.source.exceptions.MySQLSourceError

Exceptions in remote MySQL source

exception twindb_backup.source.exceptions.SourceError[source]

Bases: twindb_backup.exceptions.TwinDBBackupError

General source error

twindb_backup.source.file_source module

Module defines File source class for backing up local directories.

class twindb_backup.source.file_source.FileSource(path, run_type)[source]

Bases: twindb_backup.source.base_source.BaseSource

FileSource class

apply_retention_policy(dst, config, run_type)[source]

Apply retention policy

get_name()[source]

Generate relative destination file name

Returns:file name
get_stream(**kwds)[source]

Get a PIPE handler with content of the source

Returns:
media_type

Get media type. Media type is a general term that describes what you backup. For directories media_type is ‘file’.

Returns:‘file’

twindb_backup.source.mysql_source module

Module defines MySQL source class for backing up local MySQL.

class twindb_backup.source.mysql_source.MySQLClient(defaults_file, connect_timeout=10, hostname='127.0.0.1')[source]

Bases: object

Class to send queries to MySQL

cursor(**kwds)[source]

MySQL cursor for connection to local MySQL instance.

get_connection(**kwds)[source]

Connect to MySQL host and yield a connection.

Returns:MySQL connection
Raises:MySQLSourceError – if can’t connect to server
variable(varname)[source]

Read MySQL variable and return its value

class twindb_backup.source.mysql_source.MySQLConnectInfo(defaults_file, connect_timeout=10, cursor=<class 'pymysql.cursors.DictCursor'>, hostname='127.0.0.1')[source]

Bases: object

MySQL connection details

class twindb_backup.source.mysql_source.MySQLMasterInfo(host, port, user, password, binlog, binlog_pos)[source]

Bases: object

MySQL master details

class twindb_backup.source.mysql_source.MySQLSource(mysql_connect_info, run_type, backup_type, **kwargs)[source]

Bases: twindb_backup.source.base_source.BaseSource

MySQLSource class

apply_retention_policy(dst, config, run_type, status)[source]

Delete old backup copies.

Parameters:
  • dst (BaseDestination) – Destination where the backups are stored.
  • config (TwinDBBackupConfig) – Tool configuration
  • run_type (str) – Run type.
  • status (Status) – Backups status.
Returns:

Updated status.

Return type:

Status

binlog_coordinate

Binary log coordinate up to that backup is taken

Returns:file name and position
Return type:tuple
datadir

Return datadir path on MySQL server

disable_wsrep_desync()[source]

Wait till wsrep_local_recv_queue is zero and disable wsrep_local_recv_queue then

enable_wsrep_desync()[source]

Try to enable wsrep_desync

Returns:True if wsrep_desync was enabled. False if not supported
full

Check if the backup copy is a full copy.

Returns:True if it’s a full copy.
Return type:bool
galera

Check if local MySQL instance is a Galera cluster

Returns:True if it’s a Galera.
Return type:bool
static get_binlog_coordinates(err_log_path)[source]

Parse innobackupex log and return binary log coordinate

Parameters:err_log_path (str) – path to the innobackupex log
Returns:Binlog coordinate.
Return type:tuple
get_connection(**kwds)[source]

Connect to MySQL host and yield a connection.

Returns:MySQL connection
Raises:MySQLSourceError – if can’t connect to server
get_name()[source]

Generate relative destination file name

Returns:file name
get_stream(**kwds)[source]

Get a PIPE handler with content of the source :return:

incremental

Check if the backup copy is an incremental copy.

Returns:True if it’s an incremental copy.
Return type:bool
is_galera()[source]

Check if local MySQL instance is a Galera cluster

Returns:True if it’s a Galera.
Return type:bool
lsn

The latest LSN of the taken backup :return: LSN :rtype: int

status

Backup status on a destination

Returns:Backups status
Return type:dict
type

Get backup copy type - full or incremental

Returns:‘full’ or ‘incremental’
Return type:str
wsrep_provider_version

Parse Galera version from wsrep_provider_version.

Returns:Galera version
Return type:str

twindb_backup.source.remote_mysql_source module

Module defines MySQL source class for backing up remote MySQL.

class twindb_backup.source.remote_mysql_source.RemoteMySQLSource(kwargs)[source]

Bases: twindb_backup.source.mysql_source.MySQLSource

Remote MySQLSource class

apply_backup(datadir)[source]

Apply backup of destination server

Parameters:datadir – Path to datadir
Returns:Binlog file name and position
Return type:tuple
Raises:RemoteMySQLSourceError – if any error.
clone(dest_host, port, compress=False)[source]

Send backup to destination host

Parameters:
  • dest_host (str) – Destination host
  • port (int) – Port to sending backup
  • compress (bool) – If True compress stream
Raises:

RemoteMySQLSourceError – if any error

clone_config(dst)[source]

Clone config to destination server

Parameters:dst (Ssh) – Destination server
get_stream(**kwds)[source]

Get a PIPE handler with content of the source :return:

setup_slave(master_info)[source]

Change master

Parameters:master_info (MySQLMasterInfo) – Master details.

Module contents