Compress and Remove Log Files (IIS and others)

Archive Log Files: Manually specify any folder(s) or automatically parse IIS log folders, group by day/month and archive them with 7-Zip. Verify the archives and delete the original log files. Compressed archive will be about 4.5% (or less) of the size of the original log files.

 
 
 
 
 
4.8 Star
(32)
Add to favorites
Servers
3/28/2018
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Subfolder in the archive
    1 Posts | Last post May 03, 2019
    • For people interested in having files from subfolders in the same archive,
      
      change dir $TargetArchiveFolder | where {  
      to Get-ChildItem $TargetArchiveFolder -Recurse | where { 
      
      and $null = & $7z a -t7z -stl $PPMdSwitch $ArchiveFileName `@$ArchiveList 
      to $null = & $7z a -t7z -stl -spf2 $PPMdSwitch $ArchiveFileName `@$ArchiveList
      
      See here https://sevenzip.osdn.jp/chm/cmdline/switches/spf.htm
  • No Files found to archive in IIS Locations
    2 Posts | Last post November 27, 2018
    • I have two websites on my server and when I run the powershell it always returns: 
      
      20181126: ------------------------------------------------------------------------------------------
      
      20181126: Info: No files found to archive in C:\inetpub\logs\LogFiles\W3SVC1
      
      20181126: ------------------------------------------------------------------------------------------
      
      20181126: Info: No files found to archive in C:\inetpub\logs\LogFiles\W3SVC3
      
      
      However, I have about 14 logs in each of the locations above and the script will not compress them. Any pointers?
    • Figured it out. I missed setting the ArchiveGrouping to "day"!
  • Error creating 7z file
    2 Posts | Last post June 29, 2018
    • Hi, nice script but on my W2k8R2 machine, with PShell v2 it just throws error in log without creating any zips? :
      
      There was an error creating the 7-Zip  
                          archive G:\wwwlogs-archive\Folder1\IIS-Logs-201805.7z
      
      Any ideas please?
    • Tried lots, then decided to NOT run directly from within PowerShell cmd prompt. Ran from regular dos prompt "powershell .\filename.ps1" that worked fine.
      Ugh
  • What am I doing wrong?
    2 Posts | Last post June 27, 2018
    • Hey,
      
      I'm using this to zip up backup files that look like this...
      
      Backup\File1
      Backup\File2
      Backup\Folder1\File3
      Backup\Folder2\File4
      
      I've got it archiving all the files, but using the Manual or ManualRecurse doesn't seem to do what I want and I'm hoping you can give me some suggestions.
      
      What I'd like is Backup.zip with all the files with the entire File Structure.
      
      What I seem to get is using the Manual or ManualRecurse is a zip that looks like this...
      
      File1
      File2
      
      Or...
      
      Folder1\Backup.zip
      Folder2\Backup.zip
      Folder3\Folder4\Backup.zip
      
      Is there an easy way to zip the entire directory and keep the structure?
      
      Cheers
    • Well I found one reason for it...the manualrecurse option is grouping by day (or month) and my backup has files with many years of last written by, so it's creating hundreds of individual zip files.  Is there an easy way to remove the grouping so instead of doing it by day or month, it just zips files older than x?
  • move to github?
    1 Posts | Last post June 01, 2018
    • Hi Bernie,
      It is a nice script, but is there any chance it will be migrated to GitHub and made available for community support?
      For instance, I see there are few people who not really comfortable with using 7-Zip, and I am among them. I can change the script myself, but with GitHub such effort would also benefit the community.
  • Compress-Archive
    3 Posts | Last post May 17, 2018
    • Hi,
      
      
      A big thank you for creating this very useful and comprehensive script.
      
      For the environment I am working for we are not able/allowed to deploy 7zip.
      So I have added the following snippets to your script in order to remove the requirements for 7zip.
      
      Compression Method:
      elseif ($CompressionMethod -eq "Compress-Archive") { 
          $ArchiveExtension = ".zip" 
      }
      
      Archiving the files:
      elseif ($CompressionMethod -eq "Compress-Archive") { 
                     Get-Content $ArchiveList | Compress-Archive -DestinationPath $ArchiveFileName 
                  }
      
      I'm not very experienced with PS but I managed to write the snippets above :)
      
    • Thomaspriv,
      
      Could you please provide the script after the changing the compression.
    • @Sjaina,
      
      Here you go:
      https://paste.ee/p/Y46Sj
      
      Please keep in mind that I am not experienced with PS and I probably broke some parts of the script.
      And ofcourse all credits go to Bernie.
  • Default compression Instead of 7zip
    1 Posts | Last post May 15, 2018
    • Script is really good with error handling. Could you please provide the same with windows default compression.
      
      Thanks 
  • 7-zip or widows compress
    1 Posts | Last post May 14, 2018
    • Thanks a lot for the amazing script!
      just a quick question.
      Is this work only with 7-zip or will it work with Windows default compress system?
      Regards,
      Joe
  • Idea for weekly archive
    1 Posts | Last post April 11, 2018
    • Hi, 
      
      I like your script the best out of all the ones I've tried and found.  I see your 'to do' about weekly archives and that's what I'd like to achieve as well.  My idea is to use the 'daily' archive option, but have a 2nd routine that archives (7z store option) the past 7 days of 7z files into a single archive. That could also be configurable to any number of days if desired. For me, that's a good compromise vs. trying to figure out how approach your current method?  I'm going to try to implement this myself and reply back if I'm able to.
      
      Not sure if this is helpful, but I found this on researching a 'weekly' option like you're performing the monthly now. I was looking for a function to determine weeks.
      
      https://stackoverflow.com/questions/46691143/get-the-iso-8601-week-of-year-of-a-given-date-in-powershell
      
      Regards, 
      
      Wayne
  • Renaming of Archived Files
    2 Posts | Last post March 28, 2018
    • Hi Bernie
      
      I am executing your script to compress files for a number of applications we have. So far so good, I am managing to work fine.
      
      One question, I need to rename the archive file to the same name of the current log file. to give you an example, if i have an application which is creating a log file named ipsearch.log i would like the archive file to be named the same. Can this be achieved through the following?
      
      #$TargetTypeName = "Archived_Logs_" 
      
      Thanks
      
      Mark
      
    • Hi Mark,
      
      Sorry for the delay - I again received no email from MS about this post.
      
      Currently, line 431 of the script is where the final $ArchiveFileName is defined before it's used for creating the archive. If you only have one static file that is being archived you could manually enter its name there. But if you're going through multiple directories then you'd have to change the logic of how the script builds a list of files to archive and feeds that into the archiving command. That would require a lot of rewrite that you could certainly tackle, but at that point you may as well write your own script to do so. :)
      
      Thanks,
      
      Bernie
1 - 10 of 63 Items