many others, a complete list can be found in the file AUTHORS.
This program is Free Software; you can redistribute it and/or
modify it under the terms of version two of the GNU General Public
- License as published by the Free Software Foundation plus additions
- that are listed in the file LICENSE.
+ License as published by the Free Software Foundation and included
+ in the file LICENSE.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
const char *sql_smallest_vol =
- "SELECT MediaId FROM Media,Pool WHERE"
- " VolStatus in ('Full','Used','Error') AND Media.Enabled=1 AND"
+ "SELECT Media.MediaId FROM Media,Pool,JobMedia WHERE"
+ " Media.MediaId in (SELECT DISTINCT MediaId from JobMedia) AND"
+ " Media.VolStatus in ('Full','Used','Error') AND Media.Enabled=1 AND"
" Media.PoolId=Pool.PoolId AND Pool.Name='%s'"
" ORDER BY VolBytes ASC LIMIT 1";
const char *sql_oldest_vol =
- "SELECT MediaId FROM Media,Pool WHERE"
- " VolStatus in ('Full','Used','Error') AND Media.Enabled=1 AND"
+ "SELECT Media.MediaId FROM Media,Pool,JobMedia WHERE"
+ " Media.MediaId in (SELECT DISTINCT MediaId from JobMedia) AND"
+ " Media.VolStatus in ('Full','Used','Error') AND Media.Enabled=1 AND"
" Media.PoolId=Pool.PoolId AND Pool.Name='%s'"
" ORDER BY LastWritten ASC LIMIT 1";
char ed1[30], ed2[30];
POOL_MEM query(PM_MESSAGE);
JobId_t JobId;
- DBId_t MediaId = 0;
+ DBId_t DBId = 0;
int stat;
char *p;
idpkt ids, mid, jids;
goto ok_out;
}
pool_bytes = ctx.value;
- Dmsg2(dbglevel, "highbytes=%d pool=%d\n", (int)jcr->rpool->MigrationHighBytes,
- (int)pool_bytes);
+ Dmsg2(dbglevel, "highbytes=%lld pool=%lld\n", jcr->rpool->MigrationHighBytes,
+ pool_bytes);
if (pool_bytes < (int64_t)jcr->rpool->MigrationHighBytes) {
Jmsg(jcr, M_INFO, 0, _("No Volumes found to migrate.\n"));
goto ok_out;
}
Dmsg2(dbglevel, "Pool Occupancy ids=%d MediaIds=%s\n", ids.count, ids.list);
- /*
- * Now loop over MediaIds getting more JobIds to migrate until
- * we reduce the pool occupancy below the low water mark.
- */
+ if (!find_jobids_from_mediaid_list(jcr, &ids, "Volumes")) {
+ goto bail_out;
+ }
+ /* ids == list of jobs */
p = ids.list;
for (int i=0; i < (int)ids.count; i++) {
- stat = get_next_dbid_from_list(&p, &MediaId);
- Dmsg2(dbglevel, "get_next_dbid stat=%d MediaId=%u\n", stat, MediaId);
+ stat = get_next_dbid_from_list(&p, &DBId);
+ Dmsg2(dbglevel, "get_next_dbid stat=%d JobId=%u\n", stat, (uint32_t)DBId);
if (stat < 0) {
- Jmsg(jcr, M_FATAL, 0, _("Invalid MediaId found.\n"));
+ Jmsg(jcr, M_FATAL, 0, _("Invalid JobId found.\n"));
goto bail_out;
} else if (stat == 0) {
break;
}
+
mid.count = 1;
- Mmsg(mid.list, "%s", edit_int64(MediaId, ed1));
- if (!find_jobids_from_mediaid_list(jcr, &mid, "Volumes")) {
- continue;
- }
- if (i != 0) {
+ Mmsg(mid.list, "%s", edit_int64(DBId, ed1));
+ if (jids.count > 0) {
pm_strcat(jids.list, ",");
}
pm_strcat(jids.list, mid.list);
jids.count += mid.count;
- /* Now get the count of bytes added */
- ctx.count = 0;
/* Find count of bytes from Jobs */
Mmsg(query, sql_job_bytes, mid.list);
Dmsg1(dbglevel, "Jobbytes query: %s\n", query.c_str());
Dmsg0(dbglevel, "We should be done.\n");
break;
}
-
}
/* Transfer jids to ids, where the jobs list is expected */
ids.count = jids.count;
edit_uint64(jcr->MigrateJobId, ed1));
Dmsg1(dbglevel, "=============== Migration cmd=%s\n", ua->cmd);
parse_ua_args(ua); /* parse command */
- int stat = run_cmd(ua, ua->cmd);
- if (stat == 0) {
+ int jobid = run_cmd(ua, ua->cmd);
+ if (jobid == 0) {
Jmsg(jcr, M_ERROR, 0, _("Could not start migration job.\n"));
} else {
- Jmsg(jcr, M_INFO, 0, _("Migration JobId %d started.\n"), stat);
+ Jmsg(jcr, M_INFO, 0, _("Migration JobId %d started.\n"), jobid);
}
free_ua_context(ua);
}
goto bail_out;
}
if (ids->count == 0) {
- Jmsg(jcr, M_INFO, 0, _("No %ss found to migrate.\n"), type);
+ Jmsg(jcr, M_INFO, 0, _("No %s found to migrate.\n"), type);
ok = true; /* Not an error */
goto bail_out;
} else if (ids->count != 1) {
- Jmsg(jcr, M_FATAL, 0, _("SQL error. Expected 1 MediaId got %d\n"),
- ids->count);
+ Jmsg(jcr, M_FATAL, 0, _("SQL error. Expected 1 MediaId got %d\n"), ids->count);
goto bail_out;
}
- Dmsg1(dbglevel, "Smallest Vol Jobids=%s\n", ids->list);
+ Dmsg2(dbglevel, "%s MediaIds=%s\n", type, ids->list);
ok = find_jobids_from_mediaid_list(jcr, ids, type);
return ok;
}
+/*
+ * This routine returns:
+ * false if an error occurred
+ * true otherwise
+ * ids.count number of jobids found (may be zero)
+ */
static bool find_jobids_from_mediaid_list(JCR *jcr, idpkt *ids, const char *type)
{
bool ok = false;
Jmsg(jcr, M_INFO, 0, _("No %ss found to migrate.\n"), type);
}
ok = true;
+
bail_out:
return ok;
}