2013-09-07 2 views
1

Windows 2003/2008에서 폴더 압축을 켜고 끈 상태에서 다음을 실행하면 0 바이트 파일이 왼쪽에 표시됩니다 ..PowerShell - Zip 파일 생성시 0 바이트 파일이 남음

로그는 Apache Tomcat 로그입니다. 나머지 0 바이트 파일 인 것으로부터 .0 또는 1로 끝납니다.

이 기능을 사용하지 않도록주의하십시오 - 해결 된 해결책은 아래 내 대답에 있습니다!

function create7zip([String] $aZip, [String] $aDir, $DTNew){ 
If ((Get-Item "$aDir").length -eq 0) { 
    Remove-Item -Force $aDir 
} else { 
    [string]$pathToZipExe = "D:\WORK\SCRIPTS\7za.exe"; 
    [Array]$arguments = "a", "-tzip", "$aZip", "$aDir", "-r"; 
    & $pathToZipExe $arguments; 
    Start-Sleep -s 3 
    if ($DTNew) { 
     (dir $aZip).lastwritetime = $DTNew 
    } 
    Remove-Item -Force $aDir 
} 

}

에 의해 "라는"입니다 :

# 3 ARCHIVE LOGS 
$server = gc env:computername 
$date = Get-Date -f yyyy-MM-dd 
$ZipFolder = "D:\logs\ArchiveTemp\" 
$ZipFolder2 = "D:\logs\ArchiveTemp\AudForen\" 
$ZipFolder3 = "D:\logs\ArchiveTemp\Tomcat\" 
$company = "COMPANY" 
$DataCenter = "ANYTOWN" 
# LOAD IN THE FUNCTION TO DETECT TOMCAT INFO 
$ScriptDir = Split-Path $MyInvocation.MyCommand.Path 
. (Join-Path $ScriptDir tomcat.ps1) 
. (Join-Path $ScriptDir sftp.ps1) 
. (Join-Path $ScriptDir zip.ps1) 
. (Join-Path $ScriptDir testlock.ps1) 
$returnvalue = TomcatLog 
$LogLocation = $returnvalue[2] # LogDir 
if (Test-Path -Path $LogLocation) 
{ 
    $files = Get-ChildItem $LogLocation 
    foreach ($file in $files) 
    { 
     $FLName = $file.Name 
     $FLPath = $file.FullName 
     $CharacterCount = [regex]::matches($FLName, "-").count 
     if ($CharacterCount -gt 1) 
     { 
      $YearVar = $FLName.Split("-")[0] 
      $YearVar = $YearVar.Substring($YearVar.Length-4, 4) 
      $MonthVar = $FLName.Split("-")[1] 
      $DayVar = $FLName.Split("-")[2] 
      $DateVar = $YearVar + "-" + $MonthVar + "-" + $DayVar 
      $DateVar = $DateVar.Substring(0, 10) 
      $DateAdNm = Get-Date (Get-Date $DateVar).AddDays(1) -format yyyyMMdd 
      $DateAd = Get-Date (Get-Date $DateVar).AddDays(1) -format yyyy-MM-dd 
      if (!($DateVar -eq $date)) 
      { 
       if ($FLName -match 'audit|forensic') 
       { 
        If (!(TestFileLock $FLPath -eq -true)) 
        { 
        $AuditLogZip = $ZipFolder2 + "{0:yyyy-MM-dd}_{1}_{2}@{3}.zip" -f $DateAdNm, $company, $server, $DataCenter 
        #compress $AuditLogZip $FLPath $DateAd 
        create7zip $AuditLogZip $FLPath $DateAd 
        SFTP $AuditLogZip 
        } 
       } 
       elseif ($CharacterCount -gt 2) 
       { 
        $HourVar = $FLName.Split("-")[3] 
        if ($HourVar -gt 11) 
        { 
         $HourVar = $HourVar - 12 
         $HourVar = $HourVar.ToString("00") 
        } 
        if ($HourVar -gt 0) 
        { 
        $Var = $MonthVar + "-" + $DayVar + "-" + $YearVar +"-"+$HourVar+"-00-00-compressed.zip" 
        } 
        If (!(TestFileLock $FLPath -eq -true)) 
        { 
        #$HourlyZip = $ZipFolder + "{0:yyyy-MM-dd}-{1}{2}-00-00-compressed.zip" -f $server, (Get-Date($DateVar) -format yyyy-MM-dd) 
        #compress $HourlyZip $FLPath (Get-Date($DateVar) -format yyyy-MM-dd) 
        #Write-host $HourlyZip $FLPath (Get-Date($DateVar) -format yyyy-MM-dd) 
        $HourlyZip = $ZipFolder + "{0}-{1}" -f $server, $Var 
        #compress $HourlyZip $FLPath (Get-Date($DateVar) -format yyyy-MM-dd) 
        create7zip $HourlyZip $FLPath (Get-Date($DateVar) -format yyyy-MM-dd) 
        } 
       } 
       else 
       { 
        If (!(TestFileLock $FLPath -eq -true)) 
        { 
        $TomCatZip = $ZipFolder3 + "{0}-Tomcat-{1:yyyy-MM-dd}-compressed.zip" -f $server, (Get-Date($DateVar) -format yyyy-MM-dd) 
        #compress $TomCatZip $FLPath (Get-Date($DateVar) -format yyyy-MM-dd) 
        #Write-host $TomCatZip $FLPath (Get-Date($DateVar) -format yyyy-MM-dd) 
        create7zip $TomCatZip $FLPath (Get-Date($DateVar) -format yyyy-MM-dd) 
        } 
       } 
      } 
     } 
     else 
     { 
     $CurrentDate = Get-Date 
     $CurrentDate = $CurrentDate.AddHours(-($CurrentDate.Hour)) 
     $CurrentDate = $CurrentDate.AddMinutes(-($CurrentDate.Minute)) 
     $fileaffected = Get-ChildItem $FLPath | select LastWriteTime 
     If ($fileaffected.LastWriteTime -lt $CurrentDate) { 
     #write-host "we are going to move the file $FLPath $fileaffected.LastWriteTime" 
      If (!(TestFileLock $FLPath -eq -true)) 
      { 
      $TomCatZip = $ZipFolder3 + "{0}-Tomcat-{1:yyyy-MM-dd}-compressed.zip" -f $server, (Get-Date($DateVar) -format yyyy-MM-dd) 
      #compress $TomCatZip $FLPath (Get-Date($DateVar) -format yyyy-MM-dd) 
      create7zip $TomCatZip $FLPath (Get-Date($DateVar) -format yyyy-MM-dd) 
      Write-host $TomCatZip $FLPath (Get-Date($DateVar) -format yyyy-MM-dd) 
      } 
     #} else { 
     #write-host "we are going to leave the file $FLPath $fileaffected.LastWriteTime" 
     } 
     #If ($file.LastWriteTime -lt $DatetoMove) { 
     # $TomCatZip = $ZipFolder3 + "{0}-Tomcat-{1:yyyy-MM-dd}-compressed.zip" -f $server, (Get-Date($DateVar) -format yyyy-MM-dd) 
     # compress $TomCatZip $FLPath (Get-Date($DateVar) -format yyyy-MM-dd) 
     # } 
     } 
    } 
} 

7 - 우편 번호의 두 버전을 시도 해 봤나 .. D : \ 작업 \ 스크립트> 7Z

7-Zip 9.22 beta 저작권 (c) 1999-2011 Igor Pavlov 2011-04-18

뿐만 아니라 : D : \ 작업 \ 스크립트> 7za

7 - 우편 번호 (A) 9.20 저작권 (C) 1,999에서 2,010 사이 이고르 파블로프 2010-11-18

주 - 우리는 톰캣과하지를 실행 IIS (ISAPI 리디렉션 없음) - 따라서 관련성이 없습니다 : http://support.microsoft.com/kb/817442하지만 폴더 압축이 설정되어 있습니다.

폴더가 압축되어 있고 0 바이트 파일이 계속 표시됩니다.

VirusScan이 방해 받고있는 것으로 의심되었지만 VBS에서 유사한 코드를 실행할 수 있으며 완벽하게 작동합니다.

VBS에서 벗어나는 주된 이유는 회사에서 코드 서명 vbs에 위임을하고 PowerShell이 ​​제외 되었기 때문입니다.

감사합니다,

켄트

이 소리로
+0

어떻게 당신이 실행? –

+0

Windows 작업 스케줄러 : PowerShell -file "D : \ Work \ ps \ zip_up_files.ps1" – Leptonator

+0

문제 링크 : https://github.com/PowerShell/Microsoft.PowerShell.Archive/issues/27 –

답변

0

으로 바보, 난 내 자신의 문제를 해결했다. 이것은 VBS에서 제대로 작동하고 있지만 PowerShell에서는 잘 작동하지 않는다는 사실이 나를 괴롭혔습니다. 다시 돌아가서 코드를 다시 살펴 보았습니다. 우리는 PowerShell을 파이프 라이닝 언어임을 기억해야

..

우리는 기능이 약간의 주위에 물건을 이동해야

..

참고 : 우리는 지금 우리가 이후에 추가 된 파일을 제거 Zip 파일을 다시 찍기 전에 Zip 파일. 또한 ..

function create7zip([String] $aZip, [String] $aDir, $DTNew){ If ((Get-Item "$aDir").length -eq 0) { 
Remove-Item -Force $aDir } else { 
[string]$pathToZipExe = "D:\WORK\SCRIPTS\7za.exe"; 
[Array]$arguments = "-tzip", "-y", "a", "$aZip", "$aDir"; 
& $pathToZipExe $arguments; 
Remove-Item -Force $aDir } if ($DTNew) { 
    (dir $aZip).lastwritetime = $DTNew } } 

7-ZIP의 스위치의 일부를 조정 그리고 지금은 잘 작동합니다.

감사합니다,

켄트