Skip to content

Instantly share code, notes, and snippets.

@unicolet
Created April 8, 2015 10:40
Show Gist options
  • Select an option

  • Save unicolet/af648a97163ce6b44645 to your computer and use it in GitHub Desktop.

Select an option

Save unicolet/af648a97163ce6b44645 to your computer and use it in GitHub Desktop.
Shell script to purge Rundeck execution history
#!/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
@xavier8854
Copy link
Copy Markdown

Hello,
I have a problem with rundeck 3.0.23, using mysql 5.7 community edition
The first delete "delete from execution where id=$job" succeeds,
but the second "delete from base_report where jc_exec_id=${job}" fails with a constraint error :

ERROR 1451 (23000) at line 1: Cannot delete or update a parent row: a foreign key constraint fails (rundeck.referenced_execution, CONSTRAINT FK3sv28w2o5i03gxi66b80240qk FOREIGN KEY (execution_id) REFERENCES execution (id))

Have you a clue for fixing this ?
TIA,
Regards,
Xavier

@unicolet
Copy link
Copy Markdown
Author

unicolet commented Jul 10, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment