Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Appropriate usage of IO::CaptureOutput for a mysqldump and gzip?

by loothi (Novice)
on Oct 15, 2012 at 16:19 UTC ( #999113=perlquestion: print w/ replies, xml ) Need Help??
loothi has asked for the wisdom of the Perl Monks concerning the following question:

Hiya.

Messing about with this module IO::CaptureOutput.

I want to do a mysqldump and redirect the raw SQL through gzip. I used to do this with the system command

system("mysqldump --add-drop-table -h $global_host -u $user -p'".$pass."' $db_name  | gzip > $backup_file")

...but if the mysqldump fails, I was still getting a success exit code so I thought I'd split it into the two commands so it's more robust for debugging. Is this method below a decent way to do this? I haven't written any code in ages and am wondering if anyone can check this for me (just the concept, as it's just a snippet and I'd use strict etc in the real script).

#!/usr/bin/perl use IO::CaptureOutput qw/capture_exec capture/; sub mysqldump { system('mysqldump --add-drop-table -h localhost -u myuser -pmypass + mydb '); } capture \&mysqldump, undef, \$stderr, 'outfile.sql'; if ($stderr) { print "FAILED: $stderr\n"; }else{ @args = ('gzip','outfile.sql'); ($stdout, $stderr, $success, $exit_code) = capture_exec(@args) +; if (!$success) { print "Failed gzip: $stderr\n"; } else { print "Success gzip\n"; } }
ta. Loothi.

Comment on Appropriate usage of IO::CaptureOutput for a mysqldump and gzip?
Select or Download Code
Re: Appropriate usage of IO::CaptureOutput for a mysqldump and gzip?
by remiah (Hermit) on Oct 15, 2012 at 19:02 UTC

    Hello loothi.

    I am afraid for the database size. Dumps becomes very large and the buffer also becomes large. How about using --result-file and --log-error option of mysqldump?

    For capturing output of other programes, I see Capture::Tiny examples here at monk many times. I would like to give it a try, but, not yet.

    regards

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://999113]
Approved by herveus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2014-12-21 04:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (102 votes), past polls