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

property basename

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

abstract 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’

abstract get_stream()[source]

Get backup stream in a handler

property host

Return host where the backup is being taken from.

run_type = None
property suffix

Backup file name suffix

twindb_backup.source.binlog_source module

Module defines MySQL binlog source class for backing them up.

class twindb_backup.source.binlog_source.BinlogParser(binlog)[source]

Bases: object

Class parses a binlog file.

Parameters

binlog (str) – path to a binlog file.

property created_at

Timestamp when the binlog was created

property end_position

Last position in the binlog

property name

Binlog base name

property start_position

Minimal position in the binlog

class twindb_backup.source.binlog_source.BinlogSource(run_type, mysql_client, binlog_file=None)[source]

Bases: twindb_backup.source.base_source.BaseSource

MySQL Binlog source.

Parameters
  • run_type (str) – The backup copy interval. hourly, daily, etc.

  • mysql_client (MySQLClient) – Instance that can be used to execute queries in MySQL.

  • binlog_file (str) – Name of the binlog file as it appears in SHOW BINARY LOGS.

get_name()[source]

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

get_stream()[source]

Stream content of one binary file.

Returns

stream of bytes with the binlog content.

class twindb_backup.source.binlog_source.BinlogV4Event(**kwargs)[source]

Bases: object

MySQL Binary log event.

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, tar_options: Optional[str] = None)[source]

Bases: twindb_backup.source.base_source.BaseSource

FileSource class describes a local directory or file. The get_stream() method will return a compressed content of it.

Parameters
  • path (str) – Path to local file or directory.

  • run_type (str) – A string “daily”, “weekly”, etc.

  • tar_options (str) – Additional options passed to tar.

apply_retention_policy(dst, config, run_type)[source]

Apply retention policy

get_name()[source]

Generate relative destination file name

Returns

file name

get_stream()[source]

Get a PIPE handler with content of the source

Returns

property media_type

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

Returns

‘file’

Return type

str

twindb_backup.source.mariadb_source module

Module defines MySQL source class for backing up local MariaDB server.

class twindb_backup.source.mariadb_source.MariaDBSource(mysql_connect_info, run_type, backup_type, **kwargs)[source]

Bases: twindb_backup.source.mysql_source.MySQLSource

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()[source]

MySQL cursor for connection to local MySQL instance.

get_connection()[source]

Connect to MySQL host and yield a connection.

Returns

MySQL connection

Raises

MySQLSourceError – if can’t connect to server

property server_vendor: twindb_backup.source.mysql_source.MySQLFlavor
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’s details

class twindb_backup.source.mysql_source.MySQLFlavor(value)[source]

Bases: str, enum.Enum

An enumeration.

MARIADB = 'mariadb'
ORACLE = 'oracle'
PERCONA = 'percona'
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

property backup_tool

The tool binary that is used for backups

property binlog_coordinate

Binary log coordinate up to that backup is taken

Returns

file name and position

Return type

tuple

property 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

property full

Check if the backup copy is a full copy.

Returns

True if it’s a full copy.

Return type

bool

property 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()[source]

Connect to MySQL host and yield a connection.

Returns

MySQL connection

Raises

MySQLSourceError – if it can’t connect to server

get_name()[source]

Generate relative destination file name

Returns

file name

get_stream()[source]

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

property 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

property lsn

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

property server_vendor: twindb_backup.source.mysql_source.MySQLFlavor
property status

Backup status on a destination

Returns

Backups status

Return type

dict

property type

Get backup copy type - full or incremental

Returns

‘full’ or ‘incremental’

Return type

str

property wsrep_provider_version

Parse Galera version from wsrep_provider_version.

Returns

Galera version

Return type

str

twindb_backup.source.remote_mariadb_source module

Module defines MySQL source class for backing up local MariaDB server.

class twindb_backup.source.remote_mariadb_source.RemoteMariaDBSource(kwargs)[source]

Bases: twindb_backup.source.remote_mysql_source.RemoteMySQLSource

get_stream()[source]

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

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()[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