Ejemplo n.º 1
0
def main():
    fh = FileHelper()
    dbh = DBHelper()

    sql_savedbuffer = "select * from ITEMS where buffer_status = 88 order by id"
    sql_updatebufferstatus = "UPDATE ITEMS SET BUFFER_STATUS = 89 WHERE ID = %s"
    usage = fh.bufferusage()
    print(usage)

    try:
        db = dbh.getDictCursor()
        cursor = db["cursor"]
        cursor.execute(sql_savedbuffer)
        result = cursor.fetchall()

        for file in result:
            # if usage <= 0.8:
            #    break
            fh.removefrombuffer(file["HASH"], file["BACKUPGROUP_ID"])
            usage = fh.bufferusage()
            cursor.execute(sql_updatebufferstatus, (file["ID"]))
            print("removed %s from buffer for BG %s " %
                  (file["HASH"], file["BACKUPGROUP_ID"]))
            print(usage)

    except Exception as e:
        print("Exception")  # sql error
        print(e)
        tb = e.__traceback__
        traceback.print_tb(tb)
Ejemplo n.º 2
0
    def cleanupBuffer(self):
        fh = FileHelper()
        dbh = DBHelper()
        logger = self.log

        sql_savedbuffer = "select * from ITEMS where (DRIVE1_ID > 0  and DRIVE2_ID > 0) and buffer_status = 1 order by id "
        sql_updatebufferstatus = "UPDATE ITEMS SET BUFFER_STATUS = 2 WHERE ID = %s"
        usage = fh.bufferusage()
        print(usage)

        try:
            db = dbh.getDictCursor()
            cursor = db["cursor"]
            cursor.execute(sql_savedbuffer)
            result = cursor.fetchall()

            for file in result:
                if usage <= 0.8:
                    break
                fh.removefrombuffer(file["HASH"], file["BACKUPGROUP_ID"])
                usage = fh.bufferusage()
                cursor.execute(sql_updatebufferstatus, (file["ID"]))
                print("removed %s from buffer for BG %s " %
                      (file["HASH"], file["BACKUPGROUP_ID"]))
                print(usage)
                logger.info({
                    'action': 'Removed from Buffer',
                    'hash': file["HASH"],
                    'bachup_group': file["BACKUPGROUP_ID"],
                    "size": file["FILESIZE"]
                })

        except Exception as e:
            print("Exception")  # sql error
            print(e)
            tb = e.__traceback__
            traceback.print_tb(tb)