X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fdird%2Frecycle.c;h=f034fae717526289488cb2149ae3a1d2b990f910;hb=ee7264d0897b1720b53779062938a6abc404007b;hp=0ce19e02f0f4eaa0a026723d6962a40e3cd57c81;hpb=c72f56e4069b5f2a73a60b8c3a97681cf80dca36;p=bacula%2Fbacula diff --git a/bacula/src/dird/recycle.c b/bacula/src/dird/recycle.c index 0ce19e02f0..f034fae717 100644 --- a/bacula/src/dird/recycle.c +++ b/bacula/src/dird/recycle.c @@ -1,7 +1,7 @@ /* * * Bacula Director -- Automatic Recycling of Volumes - * Recycles Volumes that have been purged + * Recycles Volumes that have been purged * * Kern Sibbald, May MMII * @@ -9,22 +9,17 @@ */ /* - Copyright (C) 2002 Kern Sibbald and John Walker + Copyright (C) 2002-2006 Kern Sibbald This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. + modify it under the terms of the GNU General Public License + version 2 as amended with additional clauses defined in the + file LICENSE in the main source directory. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + the file LICENSE for additional details. */ @@ -42,13 +37,9 @@ static int oldest_handler(void *ctx, int num_fields, char **row) struct s_oldest_ctx *oldest = (struct s_oldest_ctx *)ctx; if (row[0]) { - Dmsg2(100, "oldest_handler %s %s\n", row[0], row[1]); - } - /* Find oldest Media record */ - if (row[1] && strcmp(row[1], oldest->LastWritten) < 0) { - oldest->MediaId = atoi(row[0]); - bstrncpy(oldest->LastWritten, row[1], sizeof(oldest->LastWritten)); - Dmsg1(100, "New oldest %s\n", row[1]); + 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; } @@ -60,8 +51,8 @@ int find_recycled_volume(JCR *jcr, bool InChanger, MEDIA_DBR *mr) bstrncpy(mr->VolStatus, "Recycle", sizeof(mr->VolStatus)); if (db_find_next_volume(jcr, jcr->db, 1, InChanger, mr)) { jcr->MediaId = mr->MediaId; - Dmsg1(20, "Find_next_vol MediaId=%d\n", jcr->MediaId); - pm_strcpy(&jcr->VolumeName, mr->VolumeName); + Dmsg1(20, "Find_next_vol MediaId=%u\n", jcr->MediaId); + pm_strcpy(jcr->VolumeName, mr->VolumeName); return 1; } return 0; @@ -74,29 +65,28 @@ int find_recycled_volume(JCR *jcr, bool InChanger, MEDIA_DBR *mr) int 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); - char *select1 = - "SELECT MediaId,LastWritten FROM Media " - "WHERE PoolId=%u AND Recycle=1 AND VolStatus='Purged' " - "AND MediaType='%s' AND InChanger=1"; - char *select2 = + const char *select = "SELECT MediaId,LastWritten FROM Media " - "WHERE PoolId=%u AND Recycle=1 AND VolStatus='Purged' " - "AND MediaType='%s'"; - + "WHERE PoolId=%s AND Recycle=1 AND VolStatus='Purged' " + "AND MediaType='%s' %s" + "ORDER BY LastWritten ASC,MediaId LIMIT 1"; Dmsg0(100, "Enter recycle_oldest_purged_volume\n"); oldest.MediaId = 0; - bstrncpy(oldest.LastWritten, "9999-99-99 99:99:99", sizeof(oldest.LastWritten)); if (InChanger) { - Mmsg(&query, select1, mr->PoolId, mr->MediaType); + 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, select2, mr->PoolId, mr->MediaType); + 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, "Exit 0 recycle_oldest_purged_volume query\n"); + Dmsg0(100, "return 0 recycle_oldest_purged_volume query\n"); free_pool_memory(query); return 0; } @@ -105,16 +95,16 @@ int recycle_oldest_purged_volume(JCR *jcr, bool InChanger, MEDIA_DBR *mr) 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, "Exit 1 recycle_oldest_purged_volume Vol=%s\n", mr->VolumeName); - return 1; - } + 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 1; + } } Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db)); } - Dmsg0(100, "Exit 0 recycle_oldest_purged_volume end\n"); - return 0; + Dmsg0(100, "return 0 recycle_oldest_purged_volume end\n"); + return 0; } /* @@ -126,5 +116,6 @@ int recycle_volume(JCR *jcr, MEDIA_DBR *mr) mr->VolJobs = mr->VolFiles = mr->VolBlocks = mr->VolErrors = 0; mr->VolBytes = 1; mr->FirstWritten = mr->LastWritten = 0; + mr->set_first_written = true; return db_update_media_record(jcr, jcr->db, mr); }