Chinaunix
标题:
【求助】Perl压缩文件诡异事件
[打印本页]
作者:
不死草
时间:
2015-12-30 17:33
标题:
【求助】Perl压缩文件诡异事件
本帖最后由 不死草 于 2016-01-05 09:09 编辑
使用同一段代码,压缩相同类型的文件(SQL Serer 备份文件),一个数据库文件可以正常压缩解压;另外一个可以压缩,但是不能正常解压,解压缩报错“不支持的压缩算法”;
区别在于是两个不同数据库的文件;使用代码压缩后,不能正常手动解压的那个文件,如果是使用手动压缩,再手动解压是没问题的。
所以,请问大家有没有碰到过类似的问题。
use strict;
use File::Copy;
my ($basedir, $bakDir) = @ARGV;
#direct the base URL
chdir $basedir;
#Get current month and the last month info
my $curMonth = gettime("yyyymm");
my $lastMonth = $curMonth - 1;
my $currentime = gettime("yyyy-mm-dd hh:mi:ss");
print "0.0) Start DB Ziping on $currentime...\n";
#get all sub folders
my @dirs = glob("*.bak");
#get the latest 2 months attach files' URL
#my @dirs = ($lastMonth,$curMonth);
#Zip and backup the files
for my $i (0..$#dirs){
if(-e @dirs[$i]){
my $zipFilename = $bakDir.@dirs[$i]."\.zip";
my $j = $i + 1;
if(-e $zipFilename){}
else{
print "$j.1) Create DB Zip File ",@dirs[$i],"\.zip...\n";
zipTree(@dirs[$i],$zipFilename);
my $currentime = gettime("yyyy-mm-dd hh:mi:ss");
print "$j.2) Finished the DB Zip File ",@dirs[$i],"\.zip on $currentime\n";
}
}
}
#-------------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------------------
sub zipTree{
use Archive::Zip qw(:ERROR_CODES :CONSTANTS);
#define var
my ($basedir,$filename) = @_;
#create zip object
my $zip = Archive::Zip->new();
# add all readable files and directories below .
$zip->addTree($basedir);
# and write them into a file
$zip->writeToFileNamed($filename);
}
sub readFilenames{
my $dir=$_ ;
opendir ( DIR, $dir ) || die "Error in opening dir $dir\n";
while( (my $filename = readdir(DIR))){
print("$filename\n");
}
closedir(DIR);
}
sub gettime {
$_ = shift;
my $t = shift;
(!$t) and ($t = time);
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($t);
$year += 1900;
my $yy = substr $year,2,2;
$mon++;
s/yyyy/$year/gi;
s/yy/$yy/gi;
if ($mon < 10) { s/mm/0$mon/gi; } else { s/mm/$mon/gi; }
if ($mday < 10) { s/dd/0$mday/gi; } else { s/dd/$mday/gi; }
if ($hour < 10) { s/hh/0$hour/gi; } else { s/hh/$hour/gi; }
if ($min < 10) { s/mi/0$min/gi; } else { s/mi/$min/gi; }
if ($sec < 10) { s/ss/0$sec/gi; } else { s/ss/$sec/gi; }
$_;
}
复制代码
作者:
不死草
时间:
2016-01-29 17:49
都没有人碰到过吗?自己顶一下。
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2