Remove MapServer / PostgreSQL & iShare temporary files with Studio Workflow

Over time MapServer & PostgreSQL temporary files may become numerous and sizeable on disk, similarly IIS Logs. The following article outlines a method for clearing out unwanted files using Studio Workflow and either a simple bat script or the DeleteFiles Powershell script to reclaim some wasted disk capacity. (Please note, it is worth referring to the 'Application Logging' help pages for guidance on reducing MapServer and iShare application logging).

Please ensure you are only removing unwanted/ unused files, as deleting certain files could potentially cause serious issues for iShare, Windows and other programs on the server.

Using a Batch file

This example shows the removal of all MapServer log files and temporary images within a 'D:\MapServer\tmp' directory (and also a 'D:\MapServer\tmp\logs' sub directory), together with the PostgreSQL log files within the pg_log directory and the SLD .map files generated in the Windows Temp folder.

Step-by-step guide

  1. Using a text editor create a bat file, saving with a '.bat' extension e.g. 'D:\iShareData\batfiles\deltemp.bat'

    rem Remove MapServer temporary files
    del /F /Q D:\mapserver\tmp\*.png >nul 2>&1
    del /F /Q D:\mapserver\tmp\*.log >nul 2>&1
    del /F /Q D:\mapserver\tmp\logs\*.log >nul 2>&1
    
    rem Remove LIVE iShare SLD
    del /F /Q D:\Astun\iShareGIS\n.n\WebApps\WebService\SLD\*.xml >nul 2>&1
    del /F /Q D:\Astun\iShare\n.n\WebApps\WebService\SLD\*.xml >nul 2>&1
    
    rem Remove TEST iShare SLD
    del /F /Q D:\Astun\iShareGIS\n.nTest\WebApps\WebService\SLD\*.xml >nul 2>&1
    del /F /Q D:\Astun\iShare\n.nTest\WebApps\WebService\SLD\*.xml >nul 2>&1
    
    rem Remove PostgreSQL Log files
    forfiles -p "D:\PGDATA\pg_log" -s -m "*.log" -d -5 -c "cmd /c del @path" >nul 2>&1
    
    rem Remove SLD temporary .map files from Windows Temp
    del /F /Q C:\Windows\Temp\*.map >nul 2>&1
  2. You may choose to run this directly from the command line at this point to check that the correct files are removed (also looking at potential error messages within the command prompt window).

  3. Create a Studio task to run the bat file, within Studio create a new Program task (New Task > Program)

  4. Name the task, e.g. 'Delete MapServer tmp and logs' 
     
  5. Within the Task Details Panel enter (or navigate to) 'D:\iShareData\batfiles\deltemp.bat' in the Program field.

    If you are browsing to select your .bat file you will need to change the file types to be All files (*.*) otherwise you will only see .exe entries.




    Make sure to Save the task and test that it runs as expected.

  6. Finally set up a Studio Workflow Job to run this as a Scheduled task on e.g. a monthly, weekly or daily basis.

    Make sure that the account you use to run the Job has permission to delete files from all of the folders in your .bat file. If not you will see errors such as "Unable to delete files from mapserver\tmp"  and this could then cause the disk to fill up.

    It is not unusual to see an error message in the iShare logs if you run the task when no .log or .png files exist in the specified locations in your .bat file e.g. Error: Could Not Find D:\mapserver\tmp\*.png

Using the DeleteFiles Powershell Script

5.8.0+

This example shows the removal of selected IIS Logs based on the age of the files. It will check the C:\inetpub\logs\LogFiles\ folder and all sub folders for .log files over a week old. If you want to change the length of time to keep the files then all you need to do is to change the age parameter.

Step-by-step guide

  1. Create a Studio Workflow Program Task to run the Powershell Script (New Task > Program)

  2. Name the Task e.g. 'Delete IIS Logs over a week old'

  3. Use the browse button to select the powershell.exe program from the Windows folder e.g. c:\windows\syswow64\windowspowershell\v1.0\powershell.exe in the Program field.

  4. In the Additional Parameters you need to enter the following details.

    By using -recurse $true it will check all the sub folders and the -age 168 denotes the number of hours old a file needs to be before it is deleted. If you need information on all of the parameters please see Run the DeleteFiles Powershell Script.

  5. Make sure to Save the task and test that it runs as expected.

  6. Finally set up a Studio Workflow Job to run this as a Scheduled task on e.g. a monthly, weekly or daily basis.

    Make sure that the account you use to run the Job has permission to delete files from all of the C:\inetpub\logs\LogFiles\ folder.