Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

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\ +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, @$; }

Replies are listed 'Best First'.
Re: Another way to catch rsync STDERR
by salva (Abbot) on Dec 24, 2012 at 13:11 UTC
    use Net::OpenSSH!
    my $ssh = Net::OpenSSH->new('', 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!
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?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1010183]
Approved by McDarren
[chickenman]: Thank you, I am looking for enlightenment! ;)
[chickenman]: Unfortunatly no standard, Its the Output of some command
[Discipulus]: ouch! it outputs always same fields?
[harishnv]: Can someone give me a solution fast

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (9)
As of 2018-02-20 08:17 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (268 votes). Check out past polls.