-
-
Save gerard-kanters/1a7e6d470888f057495b6e2ad140d3bd to your computer and use it in GitHub Desktop.
Shell script to purge Rundeck execution history
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# keep last 6000 executions for each job, about 1 week if running minute jobs | |
KEEP=6000 | |
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 "delete from execution where id=$job" | |
mysql -u rundeck -pXXXXXX -D rundeck -e "delete from execution where id=$job;" | |
echo "delete from base_report where jc_exec_id=$job" | |
mysql -u rundeck -pXXXXXX -D rundeck -e "delete from base_report where jc_exec_id=$job;" | |
done | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment