Last active
February 17, 2018 09:58
-
-
Save remijouannet/b748a28f78306ff931976983ca5933d4 to your computer and use it in GitHub Desktop.
Shell script to purge Rundeck execution history, mysql
This file contains 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/bash | |
# keep last 30 executions for each job | |
set -e | |
KEEP=60 | |
MYSQLHOST=mysql | |
MYSQLUSER=rundeck | |
MYSQLPASSWORD=password | |
MYSQLDB=rundeck | |
cd /var/lib/rundeck/logs/rundeck | |
which mysql && mysql -h $MYSQLHOST --user=$MYSQLUSER --password=$MYSQLPASSWORD $MYSQLDB -e 'select count(*) from execution' | |
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` | |
echo $ids | |
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 " mysql delete from execution where id=$job" | |
mysql -h $MYSQLHOST --user=$MYSQLUSER --password=$MYSQLPASSWORD $MYSQLDB -e "DELETE FROM execution WHERE id='${job}' AND (SELECT count_retry FROM (SELECT count(*) AS count_retry FROM execution WHERE retry_execution_id='${job}') AS e) = 0;" | |
echo " mysql delete from base_report where jc_exec_id=${job}" | |
mysql -h $MYSQLHOST --user=$MYSQLUSER --password=$MYSQLPASSWORD $MYSQLDB -e "delete from base_report where jc_exec_id='${job}'" | |
done | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment