Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Need a bach script to archive old files by zipping

$
0
0

   I am new to Batch scripting so expecting the help of the professionals.

   I have E:\TIBCO\Spotfire Web Player\6.0.0\Logfiles with Spotfire.Dxp.Web.. files and E:\TIBCO\Automation         Services\6.0.0\LogFiles with Spotfire.Dxp.Automation.. files

and I need to

    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.

i have a powershell script which is working from command prompt but not working when called from a scheduler agent called SafTT. The logic needs to be written in batch script.

     $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

Thanks for your help.

Nikku




Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>