bool db_find_failed_job_since(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM *stime, int &JobLevel);
/* sql_get.c */
+bool db_get_volume_jobids(JCR *jcr, B_DB *mdb,
+ MEDIA_DBR *mr, db_list_ctx *lst);
bool db_get_base_file_list(JCR *jcr, B_DB *mdb,
DB_RESULT_HANDLER *result_handler,void *ctx);
int db_get_path_record(JCR *jcr, B_DB *mdb);
* This routine will purge (delete) all records
* associated with a particular Volume. It will
* not delete the media record itself.
+ * TODO: This function is broken and it doesn't purge
+ * File, BaseFiles, Log, ...
+ * We call it from relabel and delete volume=, both ensure
+ * that the volume is properly purged.
*/
static int do_media_purge(B_DB *mdb, MEDIA_DBR *mr)
{
return ret;
}
+/* Get JobIds associated with a volume */
+bool db_get_volume_jobids(JCR *jcr, B_DB *mdb,
+ MEDIA_DBR *mr, db_list_ctx *lst)
+{
+ char ed1[50];
+ bool ret=false;
+
+ db_lock(mdb);
+ Mmsg(mdb->cmd, "SELECT DISTINCT JobId FROM JobMedia WHERE MediaId=%s",
+ edit_int64(mr->MediaId, ed1));
+ ret = db_sql_query(mdb, mdb->cmd, db_list_handler, lst);
+ db_unlock(mdb);
+ return ret;
+}
+
#endif /* HAVE_SQLITE3 || HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL || HAVE_INGRES || HAVE_DBI */
{
MEDIA_DBR mr;
char buf[1000];
+ db_list_ctx lst;
if (!select_media_dbr(ua, &mr)) {
return 1;
return 1;
}
}
- if (ua->pint32_val) {
- db_delete_media_record(ua->jcr, ua->db, &mr);
+ if (!ua->pint32_val) {
+ return 1;
+ }
+
+ /* If not purged, do it */
+ if (strcmp(mr.VolStatus, "Purged") != 0) {
+ if (!db_get_volume_jobids(ua->jcr, ua->db, &mr, &lst)) {
+ ua->error_msg(_("Can't list jobs on this volume\n"));
+ return 1;
+ }
+ if (lst.count) {
+ purge_jobs_from_catalog(ua, lst.list);
+ }
}
+
+ db_delete_media_record(ua->jcr, ua->db, &mr);
return 1;
}
bool purge_jobs_from_volume(UAContext *ua, MEDIA_DBR *mr, bool force)
{
POOL_MEM query(PM_MESSAGE);
- struct del_ctx del;
+ db_list_ctx lst;
+ char *jobids=NULL;
int i;
bool purged = false;
bool stat;
- JOB_DBR jr;
- char ed1[50];
stat = strcmp(mr->VolStatus, "Append") == 0 ||
strcmp(mr->VolStatus, "Full") == 0 ||
return 0;
}
- memset(&jr, 0, sizeof(jr));
- memset(&del, 0, sizeof(del));
- del.max_ids = 1000;
- del.JobId = (JobId_t *)malloc(sizeof(JobId_t) * del.max_ids);
-
/*
* Check if he wants to purge a single jobid
*/
i = find_arg_with_value(ua, "jobid");
- if (i >= 0) {
- del.num_ids = 1;
- del.JobId[0] = str_to_int64(ua->argv[i]);
+ if (i >= 0 && is_a_number_list(ua->argv[i])) {
+ jobids = ua->argv[i];
} else {
/*
* Purge ALL JobIds
*/
- Mmsg(query, "SELECT DISTINCT JobId FROM JobMedia WHERE MediaId=%s",
- edit_int64(mr->MediaId, ed1));
- if (!db_sql_query(ua->db, query.c_str(), file_delete_handler, (void *)&del)) {
+ if (!db_get_volume_jobids(ua->jcr, ua->db, mr, &lst)) {
ua->error_msg("%s", db_strerror(ua->db));
Dmsg0(050, "Count failed\n");
goto bail_out;
}
+ jobids = lst.list;
}
- purge_job_list_from_catalog(ua, del);
+ if (*jobids) {
+ purge_jobs_from_catalog(ua, jobids);
+ }
- ua->info_msg(_("%d File%s on Volume \"%s\" purged from catalog.\n"), del.num_del,
- del.num_del==1?"":"s", mr->VolumeName);
+ ua->info_msg(_("%d File%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:
- if (del.JobId) {
- free(del.JobId);
- }
return purged;
}