How can I archive a directory in Perl -
i'm trying archive directory subdirectory , files. below code doesnt work properly. archived files , folders, not content of folders ! how can solve ?
my @files = glob( $backup_path.'website/*' ); $tar = archive::tar->new(); $tar->add_files(@files); $date = datetime->now(time_zone=>"local"); $tar->write($backup_path.$websitefoldername."/".$date->dmy('-')."-".$websitefoldername.".tar");
glob
(perldoc) not recurse subdirectories. need take care of or use module file::find
:
use archive::tar; use file::find qw(find); @files; find( { wanted => sub { push @files, $file::find::name } }, $backup_path.'website'); $tar = archive::tar->new(); $tar->add_files( @files ); $date = datetime->now(time_zone=>"local"); $tar->write($backup_path.$websitefoldername."/".$date->dmy('-')."-".$websitefoldername.".tar");
Comments
Post a Comment