X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fdird%2Frecycle.c;h=58d807a055ae5bd19d7227b6c2572d435a66df8d;hb=c47244310936864c0e9aaf1784a87c2436e58fd3;hp=2c01fe3b94f106ec9197509d6151aed98f3f39ac;hpb=eb326beecb6fc8803ab73e6395c68c5a29ac8cc2;p=bacula%2Fbacula diff --git a/bacula/src/dird/recycle.c b/bacula/src/dird/recycle.c index 2c01fe3b94..58d807a055 100644 --- a/bacula/src/dird/recycle.c +++ b/bacula/src/dird/recycle.c @@ -1,16 +1,7 @@ -/* - * - * Bacula Director -- Automatic Recycling of Volumes - * Recycles Volumes that have been purged - * - * Kern Sibbald, May MMII - * - * Version $Id$ - */ /* Bacula® - The Network Backup Solution - Copyright (C) 2002-2006 Free Software Foundation Europe e.V. + Copyright (C) 2002-2007 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -34,28 +25,21 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ +/* + * + * Bacula Director -- Automatic Recycling of Volumes + * Recycles Volumes that have been purged + * + * Kern Sibbald, May MMII + * + * Version $Id$ + */ + #include "bacula.h" #include "dird.h" #include "ua.h" -struct s_oldest_ctx { - uint32_t MediaId; - char LastWritten[30]; -}; - -static int oldest_handler(void *ctx, int num_fields, char **row) -{ - struct s_oldest_ctx *oldest = (struct s_oldest_ctx *)ctx; - - if (row[0]) { - oldest->MediaId = str_to_int64(row[0]); - bstrncpy(oldest->LastWritten, row[1]?row[1]:"", sizeof(oldest->LastWritten)); - Dmsg1(100, "New oldest %s\n", row[1]?row[1]:""); - } - return 1; -} - /* Forward referenced functions */ bool find_recycled_volume(JCR *jcr, bool InChanger, MEDIA_DBR *mr) @@ -70,50 +54,18 @@ bool find_recycled_volume(JCR *jcr, bool InChanger, MEDIA_DBR *mr) return false; } - /* * Look for oldest Purged volume */ bool recycle_oldest_purged_volume(JCR *jcr, bool InChanger, MEDIA_DBR *mr) { - struct s_oldest_ctx oldest; - char ed1[50]; - POOLMEM *query = get_pool_memory(PM_EMSG); - const char *select = - "SELECT MediaId,LastWritten FROM Media " - "WHERE PoolId=%s AND Recycle=1 AND VolStatus='Purged' " - "AND Enabled=1 AND MediaType='%s' %s" - "ORDER BY LastWritten ASC,MediaId LIMIT 1"; - - Dmsg0(100, "Enter recycle_oldest_purged_volume\n"); - oldest.MediaId = 0; - if (InChanger) { - char changer[100]; - bsnprintf(changer, sizeof(changer), "AND InChanger=1 AND StorageId=%s ", - edit_int64(mr->StorageId, ed1)); - Mmsg(query, select, edit_int64(mr->PoolId, ed1), mr->MediaType, changer); - } else { - Mmsg(query, select, edit_int64(mr->PoolId, ed1), mr->MediaType, ""); - } - - if (!db_sql_query(jcr->db, query, oldest_handler, (void *)&oldest)) { - Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db)); - Dmsg0(100, "return 0 recycle_oldest_purged_volume query\n"); - free_pool_memory(query); - return false; - } - free_pool_memory(query); - Dmsg1(100, "Oldest mediaid=%d\n", oldest.MediaId); - if (oldest.MediaId != 0) { - mr->MediaId = oldest.MediaId; - if (db_get_media_record(jcr, jcr->db, mr)) { - if (recycle_volume(jcr, mr)) { - Jmsg(jcr, M_INFO, 0, _("Recycled volume \"%s\"\n"), mr->VolumeName); - Dmsg1(100, "return 1 recycle_oldest_purged_volume Vol=%s\n", mr->VolumeName); - return true; - } + bstrncpy(mr->VolStatus, "Purged", sizeof(mr->VolStatus)); + if (db_find_next_volume(jcr, jcr->db, 1, InChanger, mr)) { + if (recycle_volume(jcr, mr)) { + Jmsg(jcr, M_INFO, 0, _("Recycled volume \"%s\"\n"), mr->VolumeName); + Dmsg1(100, "return 1 recycle_oldest_purged_volume Vol=%s\n", mr->VolumeName); + return true; } - Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db)); } Dmsg0(100, "return 0 recycle_oldest_purged_volume end\n"); return false;