Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Another way to catch rsync STDERR

by PsySkeletor (Initiate)
on Dec 24, 2012 at 11:33 UTC ( #1010183=perlquestion: print w/ replies, xml ) Need Help??
PsySkeletor has asked for the wisdom of the Perl Monks concerning the following question:

Hi folks. Im seeking your wisdom, please, enlight me. This its a piece of the code im using, its a perl script to run backups from linux servers from everything. The problem its, i want to know if something fails using rsync. I took a look to the Rsync module on CPAN and it would give me the option to catch up the stderr, so it could be nice, but its mandatory that i use a ssh certificate instead a password / login to access the remote rsync server. And perl wrapper rsync module doesnt give this thing. Anyone knows how i can catch back the results of the rsync ? There's another possibility than parse the $_ while i am reading it?
# MYSQL BACKUP my @bk_mysql = qx(/usr/bin/mysql -u $uMy -p$pMy -e 'show databases'); foreach $1 (@bk_mysql){ chomp $1; $fMy = "mysql_-$1-$tLog"; $mysqlC ++; print "$mysqlC MySQL Database $1\n"; qx (mysqldump -u $uMy -p$pMy $1 | gzip -9 > $foMy/$fMy.gz ); print "Compressing file $fMy\n"; qx (/usr/bin/rsync -avzP -e "ssh -i /root/.ssh/rsyncstrato" $ +foMy/$fMy.gz account-xxxx\@rsync.hidrive.strato.com:/users/account-xx +xx/backups/mysql/$tLog/ ); print "Sending Backup to Cloud..\n"; qx (rm $foMy/$fMy.gz); print "Backup file uploaded and deleted $foMy/$fMy\n"; printf LOG "DB DONE -> $foMy/$fMy\n"; push @mysql_re, $fMy; push @mysql_status, @$; }

Comment on Another way to catch rsync STDERR
Download Code
Re: Another way to catch rsync STDERR
by Corion (Pope) on Dec 24, 2012 at 12:47 UTC

    Have you tried supplying the commands needed for rsync certificate authentication through the ->defopts method?

Re: Another way to catch rsync STDERR
by salva (Monsignor) on Dec 24, 2012 at 13:11 UTC
    use Net::OpenSSH!
    my $ssh = Net::OpenSSH->new('rsync.hidrive.strato.com', user => 'account-xxxx', key_path => '/root/.ssh/rsyncstrato'); $ssh->error and die "unable to connect to remote host: " . $ssh->error +; $ssh->rsync_put({stderr_file => 'rsync.log'}, "$foMy/$fMy.gz", "/users/account-xxxx/backeups/mysql/$tLog/") or die "rsync failed: " $ssh->error;
    BTW, it is not a good idea to use rsync for something that is generated on the fly and then compressed. That usually makes the rsync algorithm useless and inefficient. Just send the file uncompressed.

    Another way to optimize rsync transfers is to place an old version of the file being transferrer (i.e. the backup from the previous day) at the destination.

      Thanks it seems pretty nice to do it using a perl module instead a qx call. The problem to send the backup uncompresses its, they are mysql backups, it means, uncompressed, around 10 databases of around 1 - 1.5 gb. Compressed, 40 / 50 mb per databases. It worth using it compressed even the rsync protocol doesnt work at full power. In fact, im using the rsync protocol because its the easier way to do the backup against hidrive.strato. The other options like SCP and SFTP doesnt work very well. Im going to try it now!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2014-07-26 20:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (179 votes), past polls