From: Eric Bollengier Date: Tue, 25 Apr 2017 15:22:15 +0000 (+0200) Subject: Do not purge running jobs in autoprune X-Git-Tag: Release-9.0.4~5 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=70deff66db01d3e815e5ac56ea79d37b8abb1205;p=bacula%2Fbacula Do not purge running jobs in autoprune --- diff --git a/bacula/src/cats/sql_cmds.c b/bacula/src/cats/sql_cmds.c index 76b5bec85a..2a85a87476 100644 --- a/bacula/src/cats/sql_cmds.c +++ b/bacula/src/cats/sql_cmds.c @@ -88,7 +88,7 @@ const char *client_backups = const char *sel_JobMedia = "SELECT DISTINCT JobMedia.JobId FROM JobMedia,Job" " WHERE MediaId=%s AND Job.JobId=JobMedia.JobId " - " AND Job.JobTDate<%s"; + " AND Job.JobTDate<%s AND Job.JobStatus NOT IN ('R', 'C') "; /* Delete temp tables and indexes */ const char *drop_deltabs[] = { diff --git a/bacula/src/dird/ua_purge.c b/bacula/src/dird/ua_purge.c index 3f6726016a..14a04bb28e 100644 --- a/bacula/src/dird/ua_purge.c +++ b/bacula/src/dird/ua_purge.c @@ -460,7 +460,7 @@ void purge_files_from_volume(UAContext *ua, MEDIA_DBR *mr ) bool purge_jobs_from_volume(UAContext *ua, MEDIA_DBR *mr, bool force) { POOL_MEM query(PM_MESSAGE); - db_list_ctx lst; + db_list_ctx lst_all, lst; char *jobids=NULL; int i; bool purged = false; @@ -483,25 +483,34 @@ bool purge_jobs_from_volume(UAContext *ua, MEDIA_DBR *mr, bool force) i = find_arg_with_value(ua, "jobid"); if (i >= 0 && is_a_number_list(ua->argv[i])) { jobids = ua->argv[i]; + } else { + POOL_MEM query; /* * Purge ALL JobIds */ - if (!db_get_volume_jobids(ua->jcr, ua->db, mr, &lst)) { + if (!db_get_volume_jobids(ua->jcr, ua->db, mr, &lst_all)) { ua->error_msg("%s", db_strerror(ua->db)); Dmsg0(050, "Count failed\n"); goto bail_out; } + + if (lst_all.count > 0) { + Mmsg(query, "SELECT JobId FROM Job WHERE JobId IN (%s) AND JobStatus NOT IN ('R', 'C')", + lst_all.list); + if (!db_sql_query(ua->db, query.c_str(), db_list_handler, &lst)) { + ua->error_msg("%s", db_strerror(ua->db)); + goto bail_out; + } + } jobids = lst.list; } if (*jobids) { purge_jobs_from_catalog(ua, jobids); + ua->info_msg(_("%d Job%s on Volume \"%s\" purged from catalog.\n"), + lst.count, lst.count<=1?"":"s", mr->VolumeName); } - - ua->info_msg(_("%d Job%s on Volume \"%s\" purged from catalog.\n"), - lst.count, lst.count<=1?"":"s", mr->VolumeName); - purged = is_volume_purged(ua, mr, force); bail_out: