CHARON on Windows - Rotating log files cleaning

CHARON on Windows - Rotating log files cleaning

Version: 8 - PublishedJan 11, 2023 

Table of contents

Description

This Powershell script looks for defined virtual machines in the Charon Virtual Machines Manager and for those that have the log rotation feature enabled, it zip files older than a defined number of days and delete others older than a defined number of days (greater than the one for zipping files). In all cases it will keep at least the latest log files (by default the 3 latest log files are kept). It can also manage console log files.

This document relates to script versions 1.11 & 1.12.

Installation

  • Create a folder dedicated to store the scripts, for example: "C:\Charon"

  • Download the Powershell script file from our SFTP server (please ask us connection credentials if you have no access) and move it to this folder.

Restrictions

  • Powershell V4.0 minimum is required for script to work (V2.0 and V3.0 not tested)

  • Powershell V5.1 minimum is required for the archive (zip) functionality. Archiving is skipped otherwise, only deletion will work.

  • Charon-AXP/VAX/PDP version 4.8 minimum

  • Preferably run the script as administrator to avoid permission issues while zipping or deleting files

  • OPA0 log files:

    • They are taken into account only if they are of course also rotating files

    • To use the virtual machine home directory, the OPA0 log file can be specified as: set OPA0 log=".\."

    • Only default log file names will be taken into account: <configuration_name>-OPA0-xxxxxx.log

  • SHUTDOWN log files are taken into account if the Charon Clean Shutdown utility is installed (and their are using the default naming)

  • Retention is based on date found in file names (example: pluto-2019-09-02-11-51-29-000000000.log) and not by last update time

 

 For more, see Powershell version, upgrade, enabling scripts execution, tips and tricks.

Allow execution on the Windows server

To run PowerShell scripts (files that end with .ps1), you must first set the execution policy to Unrestricted (This operation has to be done once).

To do so, open a PowerShell window as an Administrator and use the following command:

PS C:\Charon> Set-ExecutionPolicy Unrestricted

The ExecutionPolicy can also be set to "RemoteSigned". In this case the .ps1 script files will have to be unblocked as described below.

If you are still prompted to allow for execution of the script, please run the following command to unblock the downloaded charon_logarchive.ps1 file:

PS C:\Charon> Unblock-File -path c:\charon\charon_logarchive.ps1

Parameters

  • Retention parameters:

    • -keep    = minimum number of log files to keep in all cases (default = 3, minimum = 1)

      • Overrides the next 2 parameters

      • Keeps the most recent ones

    • -daysarc = number of days to keep the log files before archiving (zipping) them (default = 35 days)

      • The script will look for all log files with .log extension, older than "daysarc" days, and will zip them (if possible)

    • -daysdel = number of days to keep the log and zipped files before deletion (default = 90 days)

      • The script will look for all log files with .log and .zip extension, older than "daysdel" days, and will delete them (if possible). The script will:

        • delete all zipped files older than "daysdel" days in case they have been zipped thanks to the "daysarc" parameter above

        • delete all log files older than "daysdel" days in case they have not been zipped (either too old, unzipped manually or if version of PowerShell is below 5.1)

      • Value must be greater than "daysarc". If this is not the case, the script will:

        • display a warning message,

        • force the value to be "daysarc + 7" and continue

    • -install = installation mode as a scheduled job (see chapter "Scheduled task mode" below)

  • Others:

    • -ini <file> = optional configuration file (see below) containing customized values for the retention parameters (keep, daysarc, daysdel). Please note if retention parameters are passed, they will overwrite the file content.

    • -help = display usage information

 

To display the script's help text, please use either this command:

or the Powershell "get-help" command:

Optional configuration file

If you prefer to use a configuration file rather than passing parameters in the command line, a simple file with recommended extension .ini can be created. This file contains values for the 3 retention parameters defined above. Comments are allowed with a leading # character.

Example with file named pluto.ini:

#keep=5

daysarc=90

daysdel=180

Log file

All operations are displayed on the screen and logged in a log file located in the same folder as the Powershell script. The log file is named charon_logarchive.<ddd>.log where ddd corresponds to the first 3 characters of the day of the week (language settings dependent). If the file is older than 1 day, it is reset, allowing a rotation of one week.



© Stromasys, 1999-2025  - All the information is provided on the best effort basis, and might be changed anytime without notice. Information provided does not mean Stromasys commitment to any features described. 
Need fast, reliable migration? We have done it countless times. Talk to an expert