ePages 6.12.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
DeleteOldLogs
RestoreBinLogs
IgnoreDumpsNewerThan
GetInnoBackupExe
MyCnfDefault
GetStoreConf
GetMySQLConf
MySQLShowVariables
GetMySQLSettings
CheckMySQLSettings
CheckLogFullArguments

Functions

BackupBinLogs
CheckLogFullArguments
CheckMySQLSettings
DeleteOldLogs
GetBinLogFiles
GetInnoBackupExe
GetMySQLConf
GetMySQLSettings
GetStoreConf
IgnoreDumpsNewerThan
MyCnfDefault
MySQLShowVariables
RestoreBinLogs

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]);
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
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

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

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

GetInnoBackupExe

Returns 1 if $InnoBackupExe is executable, 0 otherwise. If $InnoBackupExe is empty, the executable is searched in /opt/mysql/meb-3.5/bin/ibbackup and PATH and $InnoBackupExe is set. If found, returns 1, otherwise 0.

Syntax
my $Result = GetInnoBackupExe(\$InnoBackupExe);
Input
$InnoBackupExe (ref. string)
executable to check
Return
$Result (boolean)
true if found, otherwise false

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, $LVM);
Example
IgnoreDumpsNewerThan($DumpDate, GetStoreConf($Store));
Input
$DumpDate (string)
date with format YYYYMMDDHHMMSS
$hSettings (ref hash)
output of GetStoreConf(), see below
$LVM (string)
LVM device (VG-LV) (optional)

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

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