in reply to tar help

First step: code tags:

#!/usr/bin/perl use Archive::Tar; my $tar = Archive::Tar->new; $tar->add_files('/var/lib/mysql/club -R'); $tar->write('club_db.tar'); use Net::FTP; print "putting the file on the server\n"; $ftpobj = Net::FTP -> new ("192.168.1.21"); $ftpobj -> login("my_name","my_pass"); $ftpobj -> binary; $ftpobj -> put ("club_db.tar"); $ftpobj -> quit;
Second step: try it with one file:
#!/usr/bin/perl use Archive::Tar; use Net::FTP; my $tar = Archive::Tar->new; $tar->add_files('/var/lib/mysql/club/foo'); $tar->write('club_db.tar'); print "putting the file on the server\n"; $ftpobj = Net::FTP->new ("192.168.1.21"); $ftpobj->login("my_name","my_pass"); $ftpobj->binary; $ftpobj->put ("club_db.tar"); $ftpobj->quit;
third step, try it with two files:
my $tar = Archive::Tar->new; $tar->add_files( '/var/lib/mysql/club/foo', '/var/lib/mysql/club/bar'); $tar->write('club_db.tar');
fourth step ...

figure out how to go from 2 files to n files. I would suggest first looking at IO::Dir if the directory contains no sub directories or File::Find if it does.

-derby

Replies are listed 'Best First'.
Re^2: tar help
by snyder (Initiate) on Mar 21, 2006 at 21:48 UTC
    I have already achieved success with your first 3 recommendations. What I did find useful was your advice on the IO::Dir with the code below I can print to screen the files I wish to tar.
    #!/usr/bin/perl use IO::Dir; tie %dir, 'IO::Dir', "/var/lib/mysql/club"; foreach (keys %dir) { print $_, " " ,"\n"; }
    how would I use this to achieve my objective?
      my @files; tie %dir, 'IO::Dir', "/var/lib/mysql/club"; foreach (keys %dir) { next if $_ eq "."; next if $_ eq ".."; push( @files, "/var/lib/mysql/club/" . $_ ); } my $tar = Archive::Tar->new; $tar->add_files( @files ); $tar->write('club_db.tar');

      but .... don't forget to check for errors

      -derby
        thanks, it is throwing an error but I am going to monkey with it. in an effort to understand the code piece by piece did you create an empty list/variable with the below
        my @files;