Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

by loothi (Novice)
on Oct 15, 2012 at 16:19 UTC ( [id://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.

Replies are listed 'Best First'.
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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-19 12:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found