Repository :
http://git.fedorahosted.org/cgit/copr.git
On branch : master
---------------------------------------------------------------
commit 269d98ca4e0728a3c8c9bee5a11b9026e2bc7d52
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Thu Oct 3 12:26:37 2013 +0200
prune old builds
this add new command
/usr/sbin/copr-prune-repo
which
* remove all failed builds older than 14 days
* remove all successfull builds older than 14 days if there is newer successfull
build
and update repository metadata
It *does not* remove those build from DB (not sure if we want to remove it).
This command is executed via daily crontab.
---------------------------------------------------------------
copr-prune-repo | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++
copr.spec | 8 +++++++
crontab/copr-backend | 3 ++
3 files changed, 63 insertions(+), 0 deletions(-)
diff --git a/copr-prune-repo b/copr-prune-repo
new file mode 100755
index 0000000..8a20ea2
--- /dev/null
+++ b/copr-prune-repo
@@ -0,0 +1,52 @@
+#!/usr/bin/bash
+
+DAYS=14
+RESULTDIR=$(awk -F "=" '/^destdir/ {print $2}' /etc/copr/copr-be.conf
+
+if [ ! -d $RESULTDIR ]; then
+ echo "ERROR: destdir ($RESULTDIR) in /etc/copr/copr-be.conf does not
exist."
+ exit 1
+fi
+
+pushd $RESULTDIR >/dev/null
+for REPO in $( ls -d */*/* | grep -v '/repodata$' ); do
+ pushd $REPO >/dev/null
+
+ # Removing failed builds
+ for FAILED in $(find -name 'fail' -mtime +$DAYS); do
+ rm -rf $(dirname $FAILED)
+ echo -n .
+
+ # Query latest (sucessfull) packages
+ LATEST_PKGS=$(mktemp)
+ ERR_LOG=$(mktemp)
+ # "yum clean metadata" does not work on this custom repos
+ rm -rf $(find /var/tmp -name query)
+ rm -rf /var/tmp/createrepo*
+ rm -rf /var/cache/yum/*
+ repoquery --repofrompath=query,$RESULTDIR/$REPO --repoid=query -a --location
2>$ERR_LOG \
+ | cut -c8- > $LATEST_PKGS
+ # remove directory if it does not have repodata at all
+ grep 'Cannot retrieve repository metadata' $ERR_LOG && rm -rf
$RESULTDIR/$REPO
+
+ # Remove builds older then $DAYS days and which have newer builds available
+ for SUCCESS in $(find -name success -mtime +$DAYS); do
+ DIR=$(basename $(dirname $SUCCESS))
+ for PACKAGE in $(ls $DIR); do
+ grep $PACKAGE $LATEST_PKGS >/dev/null && continue 2
+ done
+ # package was not found in $LATEST_PKGS
+ rm -rf $DIR
+ echo -n .
+ done
+
+ rm -f $LATEST_PKGS $ERR_LOG
+ # unless we previosly deleted the repo, regen metadata
+ if [ -d $(pwd) ]; then
+ createrepo --update -q .
+ fi
+ popd >/dev/null
+done
+popd >/dev/null
+echo
+echo Done
diff --git a/copr.spec b/copr.spec
index cb05276..668acd9 100644
--- a/copr.spec
+++ b/copr.spec
@@ -59,6 +59,8 @@ Requires: python-lockfile
Requires: python-requests
Requires: logrotate
Requires: fedmsg
+Requires: gawk
+Requires: crontabs
Requires(post): systemd
Requires(preun): systemd
Requires(postun): systemd
@@ -191,10 +193,14 @@ install -d %{buildroot}%{_unitdir}
install -d %{buildroot}/%{_var}/log/copr-backend
install -d %{buildroot}/%{_var}/run/copr-backend/
install -d %{buildroot}/%{_tmpfilesdir}
+install -d %{buildroot}/%{_sbindir}
+install -d %{buildroot}%{_sysconfdir}/cron.daily
cp -a backend/* %{buildroot}%{_datadir}/copr/backend
cp -a copr-be.py %{buildroot}%{_datadir}/copr/
cp -a copr-be.conf.example %{buildroot}%{_sysconfdir}/copr/copr-be.conf
+install -p -m 755 copr-prune-repo %{buildroot}%{_sbindir}/copr-prune-repo
+install -p -m 750 crontab/copr-backend
%{buildroot}%{_sysconfdir}/cron.daily/copr-backend
cp -a backend-dist/lighttpd/* %{buildroot}%{_pkgdocdir}/lighttpd/
cp -a logrotate/* %{buildroot}%{_sysconfdir}/logrotate.d/
@@ -328,6 +334,8 @@ fi
%config(noreplace) %{_sysconfdir}/copr/copr-be.conf
%{_unitdir}/copr-backend.service
%{_tmpfilesdir}/copr-backend.conf
+%{_sbindir}/copr-prune-repo
+%config(noreplace) %{_sysconfdir}/cron.daily/copr-backend
%{_datadir}/copr/backend
%{_datadir}/copr/copr-be.py*
diff --git a/crontab/copr-backend b/crontab/copr-backend
new file mode 100644
index 0000000..586d45b
--- /dev/null
+++ b/crontab/copr-backend
@@ -0,0 +1,3 @@
+#!/usr/bin/sh
+
+/usr/sbin/copr-prune-repo >/var/log/copr.log 2>&1