需要一个bash脚本来通过压缩来存档旧文件

时间:2014-05-08 10:28:03

标签: batch-file

我是批处理脚本的新手,所以期待专业人士的帮助。

我有E:\TIBCO\Spotfire Web Player\6.0.0\Logfiles with Spotfire.Dxp.Web.*.*个文件和
       E:\TIBCO\Automation Services\6.0.0\LogFiles with Spotfire.Dxp.Automation.*.*个文件

我需要

1. move (copy & delete) all the files that are with Spotfire.Dxp.*.*.* (ex Spotfire.Dxp.*.1.*)  from the above paths to E:\TIBCO\logsArchival\rotatedDir 
2. zip all the files that are older than 60 from E:\TIBCO\logsArchival\rotatedDir to E:\TIBCO\logsArchival\ArchiveDir
3. delete the zip files that are older than 120 days from E:\TIBCO\logsArchival\ArchiveDir

all the above steps need to be written to the logs.

我有一个powershell脚本,它从命令提示符开始工作,但在从名为SafTT的调度程序代理调用时无效。逻辑需要以批处理脚本编写。

     $sysname=$env:COMPUTERNAME
     $Date = Get-Date
     $Now = Get-Date -format yyyy-MM-dd-HH-mm-ss
     $host_date=$sysname +"_"+ $Now

     $RotateDays = "60"
     $ArchiveDays="120"
     $ProjectLogsDir = "E:\TIBCO\*\6.0.0\Logfiles"
     $RotatedLogsDir = "E:\TIBCO\logsArchival\rotatedDir"
     $ArchivedLogsDir= "E:\TIBCO\logsArchival\archiveDir"
     $psLogsDir= "E:\TIBCO\logsArchival\shLogsDir"

     $LastRotate = $Date.AddDays(-$RotateDays)
     $LastArchive = $Date.AddDays(-$ArchiveDays)

     $RenameLogFiles = Get-Childitem $ProjectLogsDir -include Spotfire.Dxp.*.*.* -exclude spotfire.Dxp.web.KeepAlive.* -Recurse
     $RenameLogFiles
     $RenameLogFiles | Where-Object {!$_.PSIsContainer} |  Rename-Item -NewName { $host_date +"_"+ $_.Name.Replace(' ','_') };

     $RotatedLogFiles = Get-Childitem $ProjectLogsDir -include *_Spotfire.Dxp.*.*.* -Recurse
     $RotatedLogFiles
     $RotatedLogFiles | move-item -destination "$RotatedLogsDir"

     $ZippedLogFiles = Get-Childitem $RotatedLogsDir -include *_Spotfire.Dxp.*.*.* -Recurse | Where {$_.LastWriteTime -le "$LastRotate"}
     $ZippedLogFiles
   Zip $ArchivedLogsDir\$host_date.zip -j $ZippedLogFiles
     $ZippedLogFiles | Remove-Item -Force

     $DeleteZippedFiles = Get-Childitem $ArchivedLogsDir\*.zip -Recurse | Where {$_.LastWriteTime -le "$LastArchive"}
     $DeleteZippedFiles
     $DeleteZippedFiles | Remove-Item -Force

     $DeletePsFiles = Get-Childitem $psLogsDir\*.log -Recurse | Where {$_.LastWriteTime -le "$LastRotate"}
     $DeletePsFiles
     $DeletePsFiles | Remove-Item -Force

1 个答案:

答案 0 :(得分:1)

使用批处理文件,在其中使用powershell命令和正在运行的脚本。