sunckell has asked for the wisdom of the Perl Monks concerning the following question:

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.

Replies are listed 'Best First'.
Re: Net::SSH::Perl::Buffer issue
by krisahoch (Deacon) on Sep 05, 2002 at 15:29 UTC

    sunckell,

    The following code ...

    mkpath(['/export/home/backup/$hostname/$home_users'], 0, 0666);
    does not interpolate. You are creating a path called /export/home/backup/$hostname/$home_users. Change the single quotes ' to double quotes ". That may be the problem.

    Another problem may arise after you fix this. That is the fact that you are using $homeusers. You have declared @home_users. In this case I think that you mean to use $home_user

    my @home_users< = split " ", $home_list; foreach my $home_user< (@home_users) { #Do you mean $home_user here? because $home_users is not declared. mkpath(['/export/home/backup/$hostname/$home_users'], 0, 0666);

    HTH - Kristofer Hoch

    Updated: Grammar needed to be fixed for easier reading.

Re: Net::SSH::Perl::Buffer issue
by kvale (Monsignor) on Sep 05, 2002 at 15:24 UTC
    Before calling the gzwrite method, you will want to check whether the gzopen succeeded.

    -Mark