Thread Dateien und Ordner packen
(4 answers)
Opened by karl34 at 2012-08-02 21:55
Willst du so was machen?
Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 #!/usr/bin/perl use strict; use warnings; use Cwd; use Archive::Tar; use File::Find; use File::Spec; use POSIX qw(strftime); my $strVereichnisZiel = "/home/mein_user/sicherung/"; my $VerzPfadNow = cwd(); my $datum = strftime("%Y_%m_%d" , localtime() ); my $archiveFile = File::Spec->join( $strVereichnisZiel, sprintf( 'sicherung_%s.tar.bz2', $datum ) ); my $tar = Archive::Tar->new; find({ wanted => sub{ return if( /(\.|\.sh|\.sh~)$/ ); my $path = $File::Find::name; return if( -d $path ); my ( $file ) = $tar->add_files( $path ); my $name = File::Spec->abs2rel( $path, $VerzPfadNow ); $file->rename( $name ); }, no_chdir => 1, }, $VerzPfadNow ); $tar->write( $archiveFile, COMPRESS_BZIP ); Edit: Tippfehler: sprintf nicht printf Last edited: 2012-08-05 20:13:34 +0200 (CEST) |