RUNDECK job maintenance

Learn more about Rundeck.

Now that I have a fair number of jobs scheduled by Rundeck, how do I periodically prune the job execution history and keep only the last, say, 30 executions for each job?

Rundeck currently has no such feature and the following RFE has been opened to track its progress.

In the meanwhile on my Rundeck setups I use the following script, which, so far (fingers crossed), has not caused any problem:

#!/bin/sh
# setup ~/.pgpass to allow passwordless connection to postgres
# keep last 30 executions for each job
KEEP=30
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.*
echo " psql -h YOURDBHOST 'delete from execution where id=$job'"
psql -h YOURDBHOST -U rundeck rundeck -c "delete from execution where id=$job"
echo " psql -h YOURDBHOST -U rundeck rundeck -c 'delete from base_report where jc_exec_id=${job}::text'"
psql -h YOURDBHOST -U rundeck rundeck -c "delete from base_report where jc_exec_id=${job}::text"
done
fi
done
view raw rd-clean.sh hosted with ❤ by GitHub

Requirements

Rundeck with postgres backend, psql client configured for passwordless authentication with ~/.pgpass.
Substitute YOURDBHOST with the name of the postgres database host.


Popular posts

Mirth: recover space when mirthdb grows out of control

From 0 to ZFS replication in 5m with syncoid

1/4/2000 to 1/4/2025: the beginning