ePages 7.25.0 - DE_EPAGES/Database/API/BackupMySQL.pm

Package DE_EPAGES::Database::API::BackupMySQL

Functions in this modules are used with backup/restore MySQL databases

@EXPORT_OK
BackupBinLogs
GetBinLogFiles
GetBinLogParams
DeleteOldLogs
RestoreBinLogs
IgnoreDumpsNewerThan
MyCnfDefault
GetStoreConf
GetMySQLConf
SetMySQLConf
MySQLShowVariables
GetMySQLSettings
MySQLConnectionDefault
CheckMySQLSettings
CheckLogFullArguments
GetDatabaseSize

Functions

BackupBinLogs
CheckLogFullArguments
CheckMySQLSettings
DeleteOldLogs
GetBinLogFiles
GetBinLogParams
GetDatabaseSize
GetMySQLConf
GetMySQLSettings
GetStoreConf
IgnoreDumpsNewerThan
MyCnfDefault
MySQLConnectionDefault
MySQLShowVariables
RestoreBinLogs
SetMySQLConf

BackupBinLogs

Copies binary log files to backup location; this location is created in $hSettings->{DumpDir}/binlog/$hSettings->{BinLogSubDir}

Syntax
BackupBinLogs($hSettings, $Verbose);
Example
BackupBinLogs(GetMySQLSettings($Store), $Verbose);
Input
$hSettings (ref hash)
output of GetMySQLSettings(), see below
$Verbose (string)
print messages to stdout
$Flush (boolean)
0 - do not flush binlogs, copy only (default: 1)

CheckLogFullArguments

Checks, if all necessary parameters are set for log/full backup.

Syntax
my $ErrorMsg = CheckLogFullArguments($Full,$Log,$DelLog,$MvOld);
Input
$Full (string)
value of -full script parameter
$Log (string)
value of -log script parameter
$DelLog (string)
value of -dellog script parameter
$MvOld (string)
value of -mvold script parameter
Return
$ErrorMsg (string)
error msg contains wrong parameters

CheckMySQLSettings

Checks if $hSettings contains required keys plus @Defined and @Exists.

Syntax
my $ErrorMsg = CheckMySQLSettings($hSettings, [@Defined], [@Exists], $Store, $MySQLConfigFile);
Example
my $ErrorMsg = CheckMySQLSettings(GetMySQLSettings($Store));
Input
$hSettings (ref hash)
output of GetMySQLSettings(), see above
$Defined (ref array)
keys that must be defined
$Exists (ref array)
keys that must exist
$Store (string)
store name
$MySQLConfigFile (string)
name of MySQL config file
Return
$ErrorMsg (string)
error msg contains missing settings

DeleteOldLogs

Deletes binary logfiles which are older than $Days days.

Syntax
DeleteOldLogs($DumpDir, $BinLogSubDir, $Days, $Verbose);
Example
DeleteOldLogs('/tmp', undef, 14, 1);
Input
$DumpDir (string)
destination where logfiles were backed up to
$BinLogSubDir (string)
backup to $DumpDir/binlog/$BinLogSubDir
$Days (integer)
number of days to keep old binlog files
$Verbose (string)
print messages to stdout

GetBinLogFiles

Returns all binlog files contained in the binlog index file

Syntax
my $aBinLogFiles = GetBinLogFiles($hSettings);
Example
my $aBinLogFiles = GetBinLogFiles(GetMySQLSettings($Store));
Input
$hSettings (ref hash)
output of GetMySQLSettings(), see below
Return
$aBinLogFiles (ref.array)
array whith absolute filenames

GetBinLogParams

Returns the absolute pathes for log_bin and log_bin_index

Syntax
my ($LogBin, $LogBinIndex) = GetBinLogParams( $hSettings );
Example
my ($LogBin, $LogBinIndex) = GetBinLogParams(GetMySQLSettings($Store));
Input
$hSettings (ref hash)
output of GetMySQLSettings(), see below
Return
$LogBin (string)
absolute path to log_bin (if any, else undef)
$LogBinIndex (string)
absolute path to log_bin_index (if any, else undef)

GetDatabaseSize

Returns the size in bytes (Data_length + Index_length) of the database of $StoreName.

Syntax
$SizeInBytes = GetDatabaseSize($StoreName);
Input
$StoreName (string)
name of the store which should be used (default: Backup)
Return
$SizeInBytes (integer)
database size in bytes

GetMySQLConf

Returns hash of MySQL settings from $MySQLConfigFile. In $hSettings returned parameters can just exist (no-value parameters) or be defined by a value. Thatswhy, check both exists($hSettings->{}) and/or defined($hSettings->{}). All hyphens (-) in keys in $hSettings are translated to underscores(_). You won't find $hSettings->{'log-bin'}, but $hSettings->{log_bin}.

Syntax
$hSettings = GetMySQLConf($MySQLConfigFile);
Input
$MySQLConfigFile (string)
location of my.cnf/my.ini
Return
$hSettings (ref hash)
hash with server system variables as defined in
http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html

GetMySQLSettings

Returns hash of combined output of MySQLShowVariables(), GetStoreConf() and GetMySQLConf(), see above.

Syntax
$hSettings = GetMySQLSettings($Store, $BackupStore);
Input
$Store (string)
name of the store which should be used (default: Backup)
$BackupStore (string)
database connection name (optional,
default: DatabaseBackupData($Store)->{Backup})
$MySQLConfigFile (string)
location of dedicated my.cnf/my.ini (optional)
Return
$hSettings (hash)
hash with the collected data

GetStoreConf

Returns hash of ConnectionData retrieved from DatabaseConnectionData($Store) and DatabaseBackupData($Store,$BackupStore).

Syntax
$hSettings = GetStoreConf($Store, $BackupStore);
Input
$Store (string)
name of the store which should be used (default: Backup)
$BackupStore (string)
database connection name (optional,
default: DatabaseBackupData($Store)->{Backup})
Return
$hSettings (ref.hash)
keys as in DatabaseConnectionData($Store) plus keys as in
DatabaseBackupData($Store,$BackupStore) prefixed with Backup_
plus additional keys:
  • StoreName - $Store
  • LocalDB - 1, if datasource is socket or hostname is myself
  • FileSocket - mysql file socket (from datasource)
  • TCPSocket - mysql TCP socket (from datasource)
  • SocketOptions - mysql options -S, -h, -P (from datasource)
  • StoreOptions - SocketOptions -ulogin -ppasswd
  • BackupOptions - SocketOptions -uBackup_login -pBackup_passwd

IgnoreDumpsNewerThan

Renames files newer than $DumpDate in $hSettings->{DumpDir}

Syntax
IgnoreDumpsNewerThan($DumpDate, $hSettings);
Example
IgnoreDumpsNewerThan($DumpDate, GetStoreConf($Store));
Input
$DumpDate (string)
date with format YYYYMMDDHHMMSS
$hSettings (ref hash)
output of GetStoreConf(), see below

MyCnfDefault

Returns the best guess for MySQL config file name (file might not exist) depending on $Basedir (from MySQLShowVariables()->{basedir}, see below)

Syntax
my $ConfigFileName = MyCnfDefault($BaseDir);
Input
$BaseDir (string)
MySQL base dir
Return
$ConfigFileName (string)
MySQL config file name

MySQLConnectionDefault

Returns the best guess for environment variable EPAGES_MYSQL_CONNECTION.

Syntax
$ENV{EPAGES_MYSQL_CONNECTION} = MySQLConnectionDefault();
Return
$EPAGES_MYSQL_CONNECTION (string)
environment variable value

MySQLShowVariables

Returns hash of MySQL settings for $StoreName from 'SHOW VARIABLES'. In $Settings returned parameters can just exist (no-value parameters) or be defined by a value. Thatswhy check both exists($hSettings->{}) and/or defined($hSettings->{}).

Syntax
$hSettings = MySQLShowVariables($StoreName);
Input
$StoreName (string)
name of the store which should be used (default: Backup)
Return
$hSettings (ref hash)
hash with SHOW VARIABLES as defined in
http://dev.mysql.com/doc/refman/5.5/en/show-variables.html
additional key 'connected' shows if connection works

RestoreBinLogs

Restores backed up log files at start position from the directory $hSettings->{DumpDir}/binlog/. Does nothing if dump directory does not exist.

Syntax
RestoreBinLogs($StartLogFile, $StartPosition, $EndLogFile, $EndPosition,
               $hSettings, $Verbose);
Input
$StartLogFile (string)
name of first log file to apply
$StartPosition (integer)
number of first log position to apply
$EndLogFile (string)
name of last log file to apply (optional)
$EndPosition (integer)
number of last log position to apply (optional)
$hSettings (ref hash)
output of GetStoreConf(), see below
$Verbose (string)
print messages to stdout

SetMySQLConf

Sets in /etc/my.cnf (from MyCnfDefault() or $hFlags) in [$Section] $Key=$Value. Returns success (1, if set) or failure (0, file not writeable).

Syntax
$Result = SetMySQLConf($Section, $Key, $Value, $hFlags);
Input
$Section (string)
section of /etc/my.cnf (req.)
$Key (string)
key in section (req.)
$Value (string)
value of key (req.)
$hFlags (ref.hash)
flags
  • my_cnf - use this dedicated my.cnf
  • store - try to get my.cnf from Database.d/store.conf->MySQLConfigFile

Return
$Result (boolean)
success (1) or failure (0)