From: Kern Sibbald Date: Wed, 17 Jul 2002 20:16:19 +0000 (+0000) Subject: change autorecycle.c name to recycle.c X-Git-Tag: Release-1.23~10 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=f1effb00a41185c1d0adc838d09367d5d5a34672;p=bacula%2Fbacula change autorecycle.c name to recycle.c git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@60 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/dird/Makefile.in b/bacula/src/dird/Makefile.in index f0551221be..cf86fe2561 100644 --- a/bacula/src/dird/Makefile.in +++ b/bacula/src/dird/Makefile.in @@ -23,11 +23,11 @@ dummy: # SVRSRCS = dird.c authenticate.c autoprune.c \ - autorecycle.c backup.c \ + backup.c \ catreq.c dird_conf.c \ fd_cmds.c getmsg.c job.c \ mountreq.c msgchan.c newvol.c \ - run_conf.c restore.c \ + recycle.c restore.c run_conf.c \ scheduler.c ua_cmds.c \ ua_dotcmds.c \ ua_db_query.c ua_retention.c \ @@ -36,11 +36,11 @@ SVRSRCS = dird.c authenticate.c autoprune.c \ ua_select.c ua_server.c \ ua_status.c verify.c SVROBJS = dird.o authenticate.o autoprune.o \ - autorecycle.o backup.o \ + backup.o \ catreq.o dird_conf.o \ fd_cmds.o getmsg.o job.o \ mountreq.o msgchan.o newvol.o \ - run_conf.o restore.o \ + recycle.o restore.o run_conf.o \ scheduler.o ua_cmds.o \ ua_dotcmds.o \ ua_db_query.o ua_retention.o \ diff --git a/bacula/src/dird/recycle.c b/bacula/src/dird/recycle.c new file mode 100644 index 0000000000..9a65048f73 --- /dev/null +++ b/bacula/src/dird/recycle.c @@ -0,0 +1,109 @@ +/* + * + * Bacula Director -- Automatic Recycling of Volumes + * Recycles Volumes that have been purged + * + * Kern Sibbald, May MMII + * + * Version $Id$ + */ + +/* + Copyright (C) 2002 Kern Sibbald and John Walker + + 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. + + 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. + + */ + +#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]) { + 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]); + strcpy(oldest->LastWritten, row[1]); + Dmsg1(100, "New oldest %s\n", row[1]); + } + return 1; +} + +/* Forward referenced functions */ + +int find_recycled_volume(JCR *jcr, MEDIA_DBR *mr) +{ + strcpy(mr->VolStatus, "Recycle"); + if (db_find_next_volume(jcr->db, 1, mr)) { + jcr->MediaId = mr->MediaId; + Dmsg1(20, "Find_next_vol MediaId=%d\n", jcr->MediaId); + strcpy(jcr->VolumeName, mr->VolumeName); + return 1; + } + return 0; +} + + +/* + * Look for oldest Purged volume + */ +int recycle_a_volume(JCR *jcr, MEDIA_DBR *mr) +{ + struct s_oldest_ctx oldest; + POOLMEM *query = get_pool_memory(PM_EMSG); + char *select = +"SELECT MediaId, LastWritten FROM Media " +"WHERE PoolId=%d AND Recycle=1 AND VolStatus=\"Purged\" " +"AND MediaType=\"%s\""; + + Dmsg0(100, "Enter recycle_a_volume\n"); + oldest.MediaId = 0; + strcpy(oldest.LastWritten, "9999-99-99 99:99:99"); + Mmsg(&query, select, mr->PoolId, 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_a_volume query\n"); + free_pool_memory(query); + return 0; + } + 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->db, mr)) { + strcpy(mr->VolStatus, "Recycle"); + if (db_update_media_record(jcr->db, mr)) { + Jmsg(jcr, M_INFO, 0, "Recycled volume %s\n", mr->VolumeName); + Dmsg1(100, "Exit 1 recycle_a_volume Vol=%s\n", mr->VolumeName); + return 1; + } + } + Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db)); + } + Dmsg0(100, "Exit 0 recycle_a_volume end\n"); + return 0; +}