]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
initial skeleton for liveboot garbage collection
authorHolger Levsen <holger@layer-acht.org>
Wed, 14 Nov 2012 17:17:29 +0000 (18:17 +0100)
committerHolger Levsen <holger@layer-acht.org>
Wed, 14 Nov 2012 17:17:29 +0000 (18:17 +0100)
keep_liveboot.py [new file with mode: 0755]
liveboot_garbage_collection.sh [new file with mode: 0755]

diff --git a/keep_liveboot.py b/keep_liveboot.py
new file mode 100755 (executable)
index 0000000..b24a00a
--- /dev/null
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import os
+import re
+import pwd
+import sys
+import errno
+import datetime
+import subprocess
+import time
+import fileinput
+import psycopg2
+from common_code import *
+from cidb import *
+
+logger = logger_init()
+
+def keep_liveboot(name):
+    con = db_connect()
+    cur = con.cursor()
+    try:
+        cur.execute("SELECT keep_image FROM liveboot WHERE build_name = '%s'" % (name))
+    except psycopg2.DatabaseError as e:
+        logger.debug("SELECT keep_image FROM liveboot WHERE build_name = '%s' and keep_image = true" % (name))
+        return False
+    if cur.fetchone():
+        return True
+
+
diff --git a/liveboot_garbage_collection.sh b/liveboot_garbage_collection.sh
new file mode 100755 (executable)
index 0000000..0c514ee
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+# copyright 2012 Holger Levsen <holger@layer-acht.org>
+# GPL2 licenced
+
+set -x
+export
+
+# some settings
+AMOUNT_TO_KEEP=15
+KEPT=0
+
+for DIRECTORY in $(ls -1r) ; do
+       echo -n $DIRECTORY
+       if ! ./keep_liveboot.py "$DIRECTORY" && [ $KEPT -le $AMOUNT_TO_KEEP ] ; then
+               echo we can delete this one
+       else
+               echo keep it
+               let "KEPT=KEPT+1"
+       fi
+done