From 945742179aa48b1768e981c7154d108afa45cb7f Mon Sep 17 00:00:00 2001 From: Holger Levsen Date: Wed, 14 Nov 2012 18:17:29 +0100 Subject: [PATCH] initial skeleton for liveboot garbage collection --- keep_liveboot.py | 30 ++++++++++++++++++++++++++++++ liveboot_garbage_collection.sh | 21 +++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100755 keep_liveboot.py create mode 100755 liveboot_garbage_collection.sh 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 -- 2.39.5