From d5f9f254035b8cb442991a8d4c5a01372f9f974d Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 19 May 2003 21:13:16 +0000 Subject: [PATCH] Prune jobs with no JobFiles or that err git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@520 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/kernstodo | 8 +++++--- bacula/src/dird/sql_cmds.c | 23 +++++++---------------- bacula/src/dird/ua_prune.c | 11 ++++------- bacula/src/dird/ua_purge.c | 28 +++++++++++++++------------- bacula/src/version.h | 4 ++-- 5 files changed, 33 insertions(+), 41 deletions(-) diff --git a/bacula/kernstodo b/bacula/kernstodo index 16c9253bdb..d069123d4c 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -24,11 +24,12 @@ For 1.31 release: - Default duration with no qualifier is sec should be 1 day - Getting the following on all directories on Win32 19-May-2003 01:14 tibs-fd: Could not access c:/cygwin/home/kern/rxvt: ERR=Permission denied -- Make sure Bacula prunes/purges canceled and failed jobs too! - Find a solution for the multiple FileSet problem (when it is changed). Add date? - Cancel waiting for Client connect in SD if FD goes away. -- Testing Tibs job erred and hung director on Storage resource. +- Testing Tibs job erred and hung director on Storage resource. This was + because there were a whole pile of jobs hanging around in the SD + waiting for a connection from the FD that was never coming. - Make restore more robust in counting error and not immediately bailing out. Also print error message once, but try to continue. - Make SD keep track of Files, Bytes during restore. @@ -868,4 +869,5 @@ Done: (see kernsdone for more) - Make default duration days if no qualifier (e.g. s) is specified. - BSDI fix finding gcc version - When the FD errs (e.g. disk full) have a more graceful shutdown. - +- Make sure Bacula prunes/purges canceled and failed jobs too and all + jobs with zero JobFiles. diff --git a/bacula/src/dird/sql_cmds.c b/bacula/src/dird/sql_cmds.c index 492519ea3a..e1aa5674a4 100644 --- a/bacula/src/dird/sql_cmds.c +++ b/bacula/src/dird/sql_cmds.c @@ -86,29 +86,18 @@ char *insert_delcand = * more recent backup -- i.e. are not the only backup. * This is the list of Jobs to delete for a Backup Job. */ -#ifdef xxx char *select_backup_del = "SELECT DelCandidates.JobId " "FROM Job,DelCandidates " "WHERE (DelCandidates.JobFiles=0) OR " - "(NOT DelCandidates.JobStatus='T') OR " + "(DelCandidates.JobStatus!='T') OR " "(Job.JobTDate>%s " "AND Job.ClientId=%u " "AND Job.Type='B' " "AND Job.Level='F' " "AND Job.JobStatus='T' " - "AND Job.FileSetId=DelCandidates.FileSetId)"; -#else -char *select_backup_del = - "SELECT DelCandidates.JobId " - "FROM Job,DelCandidates " - "WHERE (Job.JobTDate>%s " - "AND Job.ClientId=%u " - "AND Job.Type='B' " - "AND Job.Level='F' " - "AND Job.JobStatus='T' " - "AND Job.FileSetId=DelCandidates.FileSetId)"; -#endif + "AND Job.FileSetId=DelCandidates.FileSetId) " + "GROUP BY JobId"; /* Select Jobs from the DelCandidates table that have a * more recent InitCatalog -- i.e. are not the only InitCatalog @@ -122,7 +111,8 @@ char *select_verify_del = "AND Job.Type='V' " "AND Job.Level='V' " "AND Job.JobStatus='T' " - "AND Job.FileSetId=DelCandidates.FileSetId"; + "AND Job.FileSetId=DelCandidates.FileSetId " + "GROUP BY JobId"; /* Select Jobs from the DelCandidates table. @@ -133,7 +123,8 @@ char *select_restore_del = "FROM Job,DelCandidates " "WHERE Job.JobTDate>%s " "AND Job.ClientId=%u " - "AND Job.Type='R'"; + "AND Job.Type='R' " + "GROUP BY JobId"; diff --git a/bacula/src/dird/ua_prune.c b/bacula/src/dird/ua_prune.c index b8d312b286..447f468dc7 100644 --- a/bacula/src/dird/ua_prune.c +++ b/bacula/src/dird/ua_prune.c @@ -237,7 +237,7 @@ int prune_files(UAContext *ua, CLIENT *client) db_lock(ua->db); memset(&cr, 0, sizeof(cr)); memset(&del, 0, sizeof(del)); - strcpy(cr.Name, client->hdr.name); + bstrncpy(cr.Name, client->hdr.name, sizeof(cr.Name)); if (!db_create_client_record(ua->jcr, ua->db, &cr)) { db_unlock(ua->db); return 0; @@ -359,7 +359,7 @@ int prune_jobs(UAContext *ua, CLIENT *client, int JobType) db_lock(ua->db); memset(&cr, 0, sizeof(cr)); memset(&del, 0, sizeof(del)); - strcpy(cr.Name, client->hdr.name); + bstrncpy(cr.Name, client->hdr.name, sizeof(cr.Name)); if (!db_create_client_record(ua->jcr, ua->db, &cr)) { db_unlock(ua->db); return 0; @@ -391,7 +391,7 @@ int prune_jobs(UAContext *ua, CLIENT *client, int JobType) } /* Count Files to be deleted */ - strcpy(query, cnt_DelCand); + pm_strcpy(&query, cnt_DelCand); Dmsg1(100, "select sql=%s\n", query); cnt.count = 0; if (!db_sql_query(ua->db, query, count_handler, (void *)&cnt)) { @@ -437,9 +437,7 @@ int prune_jobs(UAContext *ua, CLIENT *client, int JobType) * Then delete the Job entry, and finally and JobMedia records. */ for (i=0; i < del.num_ids; i++) { - Dmsg1(100, "Delete JobId=%d\n", del.JobId[i]); -#define xxx -#ifdef xxx + Dmsg1(050, "Delete JobId=%d\n", del.JobId[i]); if (!del.PurgedFiles[i]) { Mmsg(&query, del_File, del.JobId[i]); if (!db_sql_query(ua->db, query, NULL, (void *)NULL)) { @@ -459,7 +457,6 @@ int prune_jobs(UAContext *ua, CLIENT *client, int JobType) bsendmsg(ua, "%s", db_strerror(ua->db)); } Dmsg1(050, "Del sql=%s\n", query); -#endif } bsendmsg(ua, _("Pruned %d %s for client %s from catalog.\n"), del.num_ids, del.num_ids==1?_("Job"):_("Jobs"), client->hdr.name); diff --git a/bacula/src/dird/ua_purge.c b/bacula/src/dird/ua_purge.c index b77c2b079b..f943fbcd0f 100644 --- a/bacula/src/dird/ua_purge.c +++ b/bacula/src/dird/ua_purge.c @@ -205,8 +205,10 @@ int purgecmd(UAContext *ua, char *cmd) } return 1; case 2: /* client */ - client = select_client_resource(ua); - purge_files_from_client(ua, client); + client = get_client_resource(ua); + if (client) { + purge_files_from_client(ua, client); + } return 1; case 3: /* Volume */ if (select_media_dbr(ua, &mr)) { @@ -218,8 +220,10 @@ int purgecmd(UAContext *ua, char *cmd) case 1: switch(find_arg_keyword(ua, jobs_keywords)) { case 0: /* client */ - client = select_client_resource(ua); - purge_jobs_from_client(ua, client); + client = get_client_resource(ua); + if (client) { + purge_jobs_from_client(ua, client); + } return 1; case 1: /* Volume */ if (select_media_dbr(ua, &mr)) { @@ -238,18 +242,16 @@ int purgecmd(UAContext *ua, char *cmd) } switch (do_keyword_prompt(ua, _("Choose item to purge"), keywords)) { case 0: /* files */ - client = select_client_resource(ua); - if (!client) { - return 1; + client = get_client_resource(ua); + if (client) { + purge_files_from_client(ua, client); } - purge_files_from_client(ua, client); break; case 1: /* jobs */ - client = select_client_resource(ua); - if (!client) { - return 1; + client = get_client_resource(ua); + if (client) { + purge_jobs_from_client(ua, client); } - purge_jobs_from_client(ua, client); break; case 2: /* Volume */ if (select_media_dbr(ua, &mr)) { @@ -355,7 +357,7 @@ int purge_jobs_from_client(UAContext *ua, CLIENT *client) memset(&cr, 0, sizeof(cr)); memset(&del, 0, sizeof(del)); - strcpy(cr.Name, client->hdr.name); + bstrncpy(cr.Name, client->hdr.name, sizeof(cr.Name)); if (!db_create_client_record(ua->jcr, ua->db, &cr)) { return 0; } diff --git a/bacula/src/version.h b/bacula/src/version.h index 85459f8637..499457ade4 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -1,8 +1,8 @@ /* */ #define VERSION "1.31" #define VSTRING "1" -#define BDATE "18 May 2003" -#define LSMDATE "18May03" +#define BDATE "19 May 2003" +#define LSMDATE "19May03" /* Debug flags */ #define DEBUG 1 -- 2.39.5