Blogs intéressants
Blog d'Omid Ameri : Dédié à la virtualisation et au système.
Sponsor

PostHeaderIcon Script | Purger les logs d’exécution Rundeck

Article publié le 16 Janvier 2018

Avec le temps, les performances de Rundeck peuvent fortement diminuer suite à l'accumulation de logs d’exécution stockée en base et générant en parallèle d'innombrables petits fichiers.

Il vous faudra donc mettre rapidement en place une solution afin de purger les logs d’exécution de Rundeck.

J'ai trouvé et modifié un petit script faisant très bien le boulot (utilisable si votre Rundeck utilise MySQL):

#!/bin/bash

#Nombre de jours de rétention des logs

KEEP=90

# A modifier si votre instance MySQL est hébergé sur une autre machine

HOST=localhost
PORT=3306
USERNAME=<user de votre base de donnée MySQL>
PASSWORD="<le mot de passe du user de votre base MySQL"
DB=<nom de la base de donnée MySQL Rundeck>

cd /var/lib/rundeck/logs/rundeck

JOBS=`find . -maxdepth 3 -path "*/job/*" -type d`

for j in $JOBS ; do
echo "Processing job $j"
ids=`find $j -iname "*.rdlog" | sed -e "s/.*\/\([0-9]*\)\.rdlog/\1/" | sort -n -r`
declare -a JOBIDS=($ids)

if [ ${#JOBIDS[@]} -gt $KEEP ]; then
for job in ${JOBIDS[@]:$KEEP};do
echo " * Deleting job: $job"
echo " rm -rf $j/logs/$job.*"
rm -rf $j/logs/$job.*
workflowid=`mysql -h $HOST -P $PORT -u$USERNAME -p$PASSWORD -s -N -e "select workflow_id from execution where id=$job" $DB`
workflowstepids=`mysql -h $HOST -P $PORT -u$USERNAME -p$PASSWORD -s -N -e "select workflow_step_id from workflow_workflow_step where workflow_commands_id=$workflowid" $DB`
declare -a WSIDS=($workflowstepids)
for workflowstepid in $WSIDS ; do
echo " mysql -h $HOST -P $PORT -u$USERNAME -p$PASSWORD -e 'delete from workflow_workflow_step where workflow_step_id=$workflowstepid' $DB"
mysql -h $HOST -P $PORT -u$USERNAME -p$PASSWORD -e "delete from workflow_workflow_step where workflow_step_id=$workflowstepid" $DB
echo " mysql -h $HOST -P $PORT -u$USERNAME -p$PASSWORD -e 'delete from workflow_step where id=$workflowstepid' $DB"
mysql -h $HOST -P $PORT -u$USERNAME -p$PASSWORD -e "delete from workflow_step where id=$workflowstepid" $DB
done
echo " mysql -h $HOST -P $PORT -u$USERNAME -p$PASSWORD -e 'delete from execution where id=$job' $DB"
mysql -h $HOST -P $PORT -u$USERNAME -p$PASSWORD -e "delete from execution where id=$job" $DB
echo " mysql -h $HOST -P $PORT -u$USERNAME -p$PASSWORD -e 'delete from base_report where jc_exec_id=$job' $DB"
mysql -h $HOST -P $PORT -u$USERNAME -p$PASSWORD -e "delete from base_report where jc_exec_id=$job" $DB
echo " mysql -h $HOST -P $PORT -u$USERNAME -p$PASSWORD -e 'delete from workflow where id=$workflowid' $DB"
mysql -h $HOST -P $PORT -u$USERNAME -p$PASSWORD -e "delete from workflow where id=$workflowid" $DB
done
fi
done

 

image_print

Une réponse à to “Script | Purger les logs d’exécution Rundeck”

Laisser un commentaire