Question

I have a script that does the following:

  1. Creates a temp direcory
  2. Copies any folders from a log folder that are more than 1 day old to a temp folder
  3. Uses 7-Zip to zip the folders within the temp folder
  4. Transfers the zip files from the temp directory and back to the log folder
  5. Deletes the temp directory

The script I run is below:

@echo off
rem create temp directory

mkdir C:\temp\%computername%\

rem copy logs older than 1 days
robocopy \\%computername%\logs C:\temp\%computername%\ /s /zb /minage:1

for /d %%x in ("C:\temp\%computername%\*.*") do start "C:\Program Files\7-Zip\7z.exe" /b /low /wait "C:\Program Files\7-Zip\7z.exe" a -tzip "%%x.zip" "%%x\"                                                

rem move 7z files back to log directory
robocopy C:\temp\%computername%\ \\%computername%\Logs *.zip /s /zb /mov

rem delete temp directory
rmdir /S /Q C:\temp\%computername%\                                 

Doing the task this way could leave me open to problems as the C drive on the machine this is run on could fill up as the files are first copied before compressing.

I would like to just select the files older than 1 day old and compress them within the logs folder but cannot work out how to do this.

Was it helpful?

Solution 2

I solved the problem of the C drive possibly filling by changing the job to just zip the files in the same directory as the logs currently exist so that the impact of copying the folders was eliminated. Thanks to all for all help given.

OTHER TIPS

According to the robocopy docs, you can use the "/l" command to specify that files are to be logged only, and not actually copied. This can provide you with the "filter on minage" functionality that you need, by returning the UNC path of the old log files (and just specify this in your 7-zip command instead of the temp local copy.)

Note, however, that you may run out of space on your C drive even if you compress them directly, instead of copying them locally first. This is just buying you some time. You might also want to consider adding some "free disk space check" code at the beginning of this script (or as a separate monitoring service) to alert you when it's time to clean up.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top