If you want to do both: Log the mysqldump
and gzip
you can do something like this:
By modifying sub create_backup
sub create_backup {
my $sqlDumpFile = "$dirTemp/$fileTemp";
$logp->info("creating temp mysqldump...");
my $backupCmd = "mysqldump -R --triggers -u $dbToken01 -p$dbToken02 -v --quick --single-transaction $dbSchema 2>&1 | tee $sqlDumpFile";
my $dumpOutput = `$backupCmd`;
$logp->info($dumpOutput);
`gzip $sqlDumpFile`; # note you will have renamed this file to "filename".gz
}
Update
If you want to only log Error then you can do something like this.
IPC::Run
can make your life easier here.
sub create_backup {
require IPC::Run qw(run); # or load this at the top of you script...
my ($in, $out, $err);
my $backupCmd = "mysqldump";
my $sqlDumpFile = "$dirTemp/$fileTemp";
$logp->info("creating temp mysqldump...");
run([$backupCmd, '-R', '--triggers', '-u', $dbToken01, '-p', $dbToken02,
'-v', '--quick', '--single-transaction', $dbSchema, '>', $sqlDumpFile],
\$in, \$out, \$err);
if( $err ) {
$logp->info($err);
# do other stuff?
# Eg. `unlink($sqlDumpFile);
} else {
`gzip $sqlDumpFile`; # note you will have renamed this file to "filename".gz
}
}