Hello everyone,

I am writing a small backup script that uses Net::SSH::Perl. But I started running into issues where the users disk space is larger that the amount of memory I have on the backupserver.

#!/usr/bin/perl use strict; use diagnostics; $|++; use lib "."; use ServerBackup; use Net::SSH::Perl; use FileHandle; use File::Path; use Net::SSH::Perl::Buffer; use Compress::Zlib; my $user = "root"; my $hostname = "somedomain.com"; my $ssh = Net::SSH::Perl->new($hostname, identity_files =>["$id_key_fn"], port => 22, debug => 1); $ssh->login($user); my ($home_list, $home_err, $home_exit)=$ssh->cmd($listhome); # cmd jus +t grabs users from home dir my @home_users = split " ", $home_list; foreach my $home_user (@home_users) { mkpath(['/export/home/backup/$hostname/$home_users'],0,0666); my $buffer = Net::SSH::Perl::Buffer->new; my ($home_out, $home_err, $home_exit); while (($home_out, $home_err, $home_exit) = $ssh->cmd("cd /; /usr/bin/ +nice /bin/tar cpf - /home/$home_user")) { $buffer->put_int32(10932930); my $int = $buffer->get_int32; my $gz = gzopen("/export/home/backup/$hostname/$home_user\.tar.gz", + "w"); my $tgz_user = $gz->gzwrite($int); my $home_gz_err = $gz->gzerror(); $gz->gzclose(); } }

I just want to set a buffer to a certain size then write so that I do not bring the backup server down because I used up all the available memory tarring any extremely large users to STDOUT.

No matter what I try I keep getting the same error: Can't call method "gzwrite" on an undefined value.

Any have any suggestion?

Thanks for the help.


In reply to Net::SSH::Perl::Buffer issue by sunckell

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.