From: Holger Levsen Date: Wed, 14 Nov 2012 17:17:29 +0000 (+0100) Subject: initial skeleton for liveboot garbage collection X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=945742179aa48b1768e981c7154d108afa45cb7f;p=profitbricks%2Fjenkins-build-scripts.git initial skeleton for liveboot garbage collection --- diff --git a/keep_liveboot.py b/keep_liveboot.py new file mode 100755 index 0000000..b24a00a --- /dev/null +++ b/keep_liveboot.py @@ -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 index 0000000..0c514ee --- /dev/null +++ b/liveboot_garbage_collection.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# copyright 2012 Holger Levsen +# 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