Paste P7781

clean.sh
ActivePublic

Authored by thcipriani on Nov 8 2018, 10:52 PM.
#!/usr/bin/env bash
# remove builds older than 60 days for 25 largest build directories
while read dir; do
sudo find ${dir} -maxdepth 1 -type d -regex '.*/[1-9][0-9]+' -mtime +60 -exec rm -r "{}" \;
done < <(du -chs /srv/jenkins/builds/* | sort -rh | head -n26 | tail -n25 | awk '{print $2}')
# remove builds older than 30 days for 10 largest build directories
while read dir; do
sudo find ${dir} -maxdepth 1 -type d -regex '.*/[1-9][0-9]+' -mtime +30 -exec rm -r "{}" \;
done < <(du -chs /srv/jenkins/builds/* | sort -rh | head -n11 | tail -n10 | awk '{print $2}')
# remove builds older than 21 days for 5 largest build directories
while read dir; do
sudo find ${dir} -maxdepth 1 -type d -regex '.*/[1-9][0-9]+' -mtime +21 -exec rm -r "{}" \;
done < <(du -chs /srv/jenkins/builds/* | sort -rh | head -n6 | tail -n5 | awk '{print $2}')