Version: 8 - Published 

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.

(info) This document relates to script versions 1.11 & 1.12.

Installation

Restrictions


(info) 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

(info) 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


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

PS C:\Charon> .\charon_logarchive.ps1 -help

or the Powershell "get-help" command:

PS C:\Charon> get-help c:\charon\charon_logarchive.ps1 -full


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.

Script execution

Interactive mode

Example 1 - default parameters:

PS C:\Charon> .\charon_logarchive.ps1

Example 2 - custom parameters:

PS C:\Charon> .\charon_logarchive.ps1 -daysarc 120 -daysdel 365

Example 3 - using configuration file:

PS C:\Charon> .\charon_logarchive.ps1 -ini c:\charon\pluto.ini

Scheduled task mode

The script provides an auto-installer to create a scheduled job that will run each day at 1:00 AM.

Open a PowerShell window as Administrator (mandatory), run the following command and answer the questions:

PS C:\Charon> .\charon_logarchive.ps1 -install

Example:

PS C:\Charon> .\charon_logarchive.ps1 -install

[Info] Data folder found: 'C:\Program Files\CHARON\Toolkit\LogArchiver'
Please specify the following attributes
Number of days to keep the log files before archiving (zipping) them [100] :

Number of days to keep the log and zipped files before deletion [180] :

Minimum number of log files to keep in all cases [5] :

[Info] Scheduled task created in \CHARON folder, name: 'Charon logs archiving'
[Info] Runs everyday at 01:00 AM.

To change the settings after the scheduled job has been created, it is possible to rerun the script with "-install" option, this will update the already existing job.

(info) The installation will create a configuration file in the Charon installation folder under "Toolkit\LogArchiver" (usually "C:\Program Files\CHARON\Toolkit\LogArchiver") and named charon_logarchive.ini.

(lightbulb) The script script creates a log file named charon_logarchive.<ddd>.log" in the installation folder where <ddd> represents the weekday (so a week rotation).