Version: 8 - Published:
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.
C:\Charon
"set OPA0 log=".\."
<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)
pluto-2019-09-02-11-51-29-000000000.log
) and not by last update timeFor more, see Powershell version, upgrade, enabling scripts execution, tips and tricks.
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:
|
-keep
= minimum number of log files to keep in all cases (default = 3, minimum = 1)-daysarc
= number of days to keep the log files before archiving (zipping) them (default = 35 days).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).log
and .zip
extension, older than "daysdel
" days, and will delete them (if possible). The script will:daysdel
" days in case they have been zipped thanks to the "daysarc
" parameter abovedaysdel
" days in case they have not been zipped (either too old, unzipped manually or if version of PowerShell is below 5.1)daysarc
". If this is not the case, the script will:daysarc + 7
" and continue-install =
installation mode as a scheduled job (see chapter "CHARON on Windows - Rotating log files cleaning#Scheduled task mode" below)-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 informationTo display the script's help text, please use either this command:
or the Powershell "get-help" command:
|
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:
|
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.
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 |
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:
|
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.
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
.
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).