Question

When I perform following in perl, I allways get the error code "0". Even if for example the mysql database does not exist, or the password is wrong, etc.

@args = ("mysqldump -u root -ppassword database1 | gzip -c > /usr/local/bin/database.gzip");
system(@args) == 0
        or die "Command failed: @args \nError Code: $? \n";

My goal is to catch any error of the mysqldump command, so I can make sure if the backup was successfuly.

Was it helpful?

Solution

I guess it is the pipe that is giving this problem. You might be getting the exit status of

"gzip -c > /usr/local/bin/database.gzip" 

You might have to split the dump and gzip part into two.

use

`mysqldump -u root -ppassword database1 > ./dump.txt`;
if ($? == 0){
    `gzip -9 ./dump.txt`;
    }
else{
die "errored";
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top