* At the same time, we select "orphanned" jobs
* (i.e. no files, ...) for deletion.
*/
+#ifdef old_way
const char *select_backup_del =
"SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
"FROM Job,DelCandidates "
"AND Job.ClientId=%s "
"AND Job.Type='g')";
+#else
+/* Faster way */
+const char *select_backup_del =
+ "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
+ "FROM Job,DelCandidates "
+ "WHERE (Job.JobId=DelCandidates.JobId AND ((DelCandidates.JobFiles=0) OR "
+ "(DelCandidates.JobStatus!='T'))) OR "
+ "(Job.JobTDate>%s "
+ "AND Job.ClientId=%s "
+ "AND Job.Level='F' AND Job.JobStatus='T' AND Job.Type IN ('B','M') "
+ "AND Job.FileSetId=DelCandidates.FileSetId)";
+
+/* Select Jobs from the DelCandidates table that have a
+ * more recent InitCatalog -- i.e. are not the only InitCatalog
+ * This is the list of Jobs to delete for a Verify Job.
+ */
+const char *select_verify_del =
+ "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
+ "FROM Job,DelCandidates "
+ "WHERE (Job.JobId=DelCandidates.JobId AND DelCandidates.JobStatus!='T') OR "
+ "(Job.JobTDate>%s "
+ "AND Job.ClientId=%s "
+ "AND Job.Type='V' AND Job.Level='V' AND Job.JobStatus='T' "
+ "AND Job.FileSetId=DelCandidates.FileSetId)";
+
+
+/* Select Jobs from the DelCandidates table.
+ * This is the list of Jobs to delete for a Restore Job.
+ */
+const char *select_restore_del =
+ "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
+ "FROM Job,DelCandidates "
+ "WHERE (Job.JobId=DelCandidates.JobId AND DelCandidates.JobStatus!='T') OR "
+ "(Job.JobTDate>%s "
+ "AND Job.ClientId=%s "
+ "AND Job.Type='R')";
+
+/* Select Jobs from the DelCandidates table.
+ * This is the list of Jobs to delete for an Admin Job.
+ */
+const char *select_admin_del =
+ "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
+ "FROM Job,DelCandidates "
+ "WHERE (Job.JobId=DelCandidates.JobId AND DelCandidates.JobStatus!='T') OR "
+ "(Job.JobTDate>%s "
+ "AND Job.ClientId=%s "
+ "AND Job.Type='D')";
+
+/*
+ * Select Jobs from the DelCandidates table.
+ * This is the list of Jobs to delete for an Migrate Job.
+ */
+const char *select_migrate_del =
+ "SELECT DISTINCT DelCandidates.JobId,DelCandidates.PurgedFiles "
+ "FROM Job,DelCandidates "
+ "WHERE (Job.JobId=DelCanditates.JobId AND DelCandidates.JobStatus!='T') OR "
+ "(Job.JobTDate>%s "
+ "AND Job.ClientId=%s "
+ "AND Job.Type='g')";
+
+#endif
+
/* ======= ua_restore.c */
const char *uar_count_files =
"SELECT JobFiles FROM Job WHERE JobId=%s";
static void eliminate_orphaned_jobmedia_records()
{
- const char *query;
+ const char *query = "SELECT JobMedia.JobMediaId,Job.JobId FROM JobMedia "
+ "LEFT OUTER JOIN Job ON (JobMedia.JobId=Job.JobId) "
+ "WHERE Job.JobId IS NULL LIMIT 300000";
printf(_("Checking for orphaned JobMedia entries.\n"));
- query = "SELECT JobMedia.JobMediaId,Job.JobId FROM JobMedia "
- "LEFT OUTER JOIN Job ON (JobMedia.JobId=Job.JobId) "
- "WHERE Job.JobId IS NULL";
if (!make_id_list(query, &id_list)) {
exit(1);
}
- printf(_("Found %d orphaned JobMedia records.\n"), id_list.num_ids);
- if (id_list.num_ids && verbose && yes_no(_("Print them? (yes/no): "))) {
- for (int i=0; i < id_list.num_ids; i++) {
- char ed1[50];
- bsnprintf(buf, sizeof(buf),
+ /* Loop doing 300000 at a time */
+ while (id_list.num_ids != 0) {
+ printf(_("Found %d orphaned JobMedia records.\n"), id_list.num_ids);
+ if (id_list.num_ids && verbose && yes_no(_("Print them? (yes/no): "))) {
+ for (int i=0; i < id_list.num_ids; i++) {
+ char ed1[50];
+ bsnprintf(buf, sizeof(buf),
"SELECT JobMedia.JobMediaId,JobMedia.JobId,Media.VolumeName FROM JobMedia,Media "
"WHERE JobMedia.JobMediaId=%s AND Media.MediaId=JobMedia.MediaId",
- edit_int64(id_list.Id[i], ed1));
- if (!db_sql_query(db, buf, print_jobmedia_handler, NULL)) {
- printf("%s\n", db_strerror(db));
+ edit_int64(id_list.Id[i], ed1));
+ if (!db_sql_query(db, buf, print_jobmedia_handler, NULL)) {
+ printf("%s\n", db_strerror(db));
+ }
}
}
- }
- if (quit) {
- return;
- }
+ if (quit) {
+ return;
+ }
- if (fix && id_list.num_ids > 0) {
- printf(_("Deleting %d orphaned JobMedia records.\n"), id_list.num_ids);
- delete_id_list("DELETE FROM JobMedia WHERE JobMediaId=%s", &id_list);
+ if (fix && id_list.num_ids > 0) {
+ printf(_("Deleting %d orphaned JobMedia records.\n"), id_list.num_ids);
+ delete_id_list("DELETE FROM JobMedia WHERE JobMediaId=%s", &id_list);
+ }
+ if (!make_id_list(query, &id_list)) {
+ exit(1);
+ }
}
}
static void eliminate_orphaned_file_records()
{
- const char *query;
+ const char *query = "SELECT File.FileId,Job.JobId FROM File "
+ "LEFT OUTER JOIN Job ON (File.JobId=Job.JobId) "
+ "WHERE Job.JobId IS NULL LIMIT 300000";
printf(_("Checking for orphaned File entries. This may take some time!\n"));
- query = "SELECT File.FileId,Job.JobId FROM File "
- "LEFT OUTER JOIN Job ON (File.JobId=Job.JobId) "
- "WHERE Job.JobId IS NULL";
if (verbose > 1) {
printf("%s\n", query);
}
if (!make_id_list(query, &id_list)) {
exit(1);
}
- printf(_("Found %d orphaned File records.\n"), id_list.num_ids);
- if (name_list.num_ids && verbose && yes_no(_("Print them? (yes/no): "))) {
- for (int i=0; i < id_list.num_ids; i++) {
- char ed1[50];
- bsnprintf(buf, sizeof(buf),
+ /* Loop doing 300000 at a time */
+ while (id_list.num_ids != 0) {
+ printf(_("Found %d orphaned File records.\n"), id_list.num_ids);
+ if (name_list.num_ids && verbose && yes_no(_("Print them? (yes/no): "))) {
+ for (int i=0; i < id_list.num_ids; i++) {
+ char ed1[50];
+ bsnprintf(buf, sizeof(buf),
"SELECT File.FileId,File.JobId,Filename.Name FROM File,Filename "
"WHERE File.FileId=%s AND File.FilenameId=Filename.FilenameId",
- edit_int64(id_list.Id[i], ed1));
- if (!db_sql_query(db, buf, print_file_handler, NULL)) {
- printf("%s\n", db_strerror(db));
+ edit_int64(id_list.Id[i], ed1));
+ if (!db_sql_query(db, buf, print_file_handler, NULL)) {
+ printf("%s\n", db_strerror(db));
+ }
}
}
- }
- if (quit) {
- return;
- }
- if (fix && id_list.num_ids > 0) {
- printf(_("Deleting %d orphaned File records.\n"), id_list.num_ids);
- delete_id_list("DELETE FROM File WHERE FileId=%s", &id_list);
+ if (quit) {
+ return;
+ }
+ if (fix && id_list.num_ids > 0) {
+ printf(_("Deleting %d orphaned File records.\n"), id_list.num_ids);
+ delete_id_list("DELETE FROM File WHERE FileId=%s", &id_list);
+ }
+ if (!make_id_list(query, &id_list)) {
+ exit(1);
+ }
}
}
static void eliminate_orphaned_path_records()
{
- const char *query;
+ const char *query = "SELECT DISTINCT Path.PathId,File.PathId FROM Path "
+ "LEFT OUTER JOIN File ON (Path.PathId=File.PathId) "
+ "WHERE File.PathId IS NULL LIMIT 300000";
printf(_("Checking for orphaned Path entries. This may take some time!\n"));
- query = "SELECT DISTINCT Path.PathId,File.PathId FROM Path "
- "LEFT OUTER JOIN File ON (Path.PathId=File.PathId) "
- "WHERE File.PathId IS NULL";
if (verbose > 1) {
printf("%s\n", query);
}
if (!make_id_list(query, &id_list)) {
exit(1);
}
- printf(_("Found %d orphaned Path records.\n"), id_list.num_ids);
- if (id_list.num_ids && verbose && yes_no(_("Print them? (yes/no): "))) {
- for (int i=0; i < id_list.num_ids; i++) {
- char ed1[50];
- bsnprintf(buf, sizeof(buf), "SELECT Path FROM Path WHERE PathId=%s",
- edit_int64(id_list.Id[i], ed1));
- db_sql_query(db, buf, print_name_handler, NULL);
+ /* Loop doing 300000 at a time */
+ while (id_list.num_ids != 0) {
+ printf(_("Found %d orphaned Path records.\n"), id_list.num_ids);
+ if (id_list.num_ids && verbose && yes_no(_("Print them? (yes/no): "))) {
+ for (int i=0; i < id_list.num_ids; i++) {
+ char ed1[50];
+ bsnprintf(buf, sizeof(buf), "SELECT Path FROM Path WHERE PathId=%s",
+ edit_int64(id_list.Id[i], ed1));
+ db_sql_query(db, buf, print_name_handler, NULL);
+ }
+ }
+ if (quit) {
+ return;
+ }
+ if (fix && id_list.num_ids > 0) {
+ printf(_("Deleting %d orphaned Path records.\n"), id_list.num_ids);
+ delete_id_list("DELETE FROM Path WHERE PathId=%s", &id_list);
+ }
+ if (!make_id_list(query, &id_list)) {
+ exit(1);
}
- }
- if (quit) {
- return;
- }
- if (fix && id_list.num_ids > 0) {
- printf(_("Deleting %d orphaned Path records.\n"), id_list.num_ids);
- delete_id_list("DELETE FROM Path WHERE PathId=%s", &id_list);
}
}
static void eliminate_orphaned_filename_records()
{
- const char *query;
+ const char *query = "SELECT Filename.FilenameId,File.FilenameId FROM Filename "
+ "LEFT OUTER JOIN File ON (Filename.FilenameId=File.FilenameId) "
+ "WHERE File.FilenameId IS NULL LIMIT 300000";
printf(_("Checking for orphaned Filename entries. This may take some time!\n"));
- query = "SELECT Filename.FilenameId,File.FilenameId FROM Filename "
- "LEFT OUTER JOIN File ON (Filename.FilenameId=File.FilenameId) "
- "WHERE File.FilenameId IS NULL";
if (verbose > 1) {
printf("%s\n", query);
}
if (!make_id_list(query, &id_list)) {
exit(1);
}
- printf(_("Found %d orphaned Filename records.\n"), id_list.num_ids);
- if (id_list.num_ids && verbose && yes_no(_("Print them? (yes/no): "))) {
- for (int i=0; i < id_list.num_ids; i++) {
- char ed1[50];
- bsnprintf(buf, sizeof(buf), "SELECT Name FROM Filename WHERE FilenameId=%s",
- edit_int64(id_list.Id[i], ed1));
- db_sql_query(db, buf, print_name_handler, NULL);
+ /* Loop doing 300000 at a time */
+ while (id_list.num_ids != 0) {
+ printf(_("Found %d orphaned Filename records.\n"), id_list.num_ids);
+ if (id_list.num_ids && verbose && yes_no(_("Print them? (yes/no): "))) {
+ for (int i=0; i < id_list.num_ids; i++) {
+ char ed1[50];
+ bsnprintf(buf, sizeof(buf), "SELECT Name FROM Filename WHERE FilenameId=%s",
+ edit_int64(id_list.Id[i], ed1));
+ db_sql_query(db, buf, print_name_handler, NULL);
+ }
+ }
+ if (quit) {
+ return;
+ }
+ if (fix && id_list.num_ids > 0) {
+ printf(_("Deleting %d orphaned Filename records.\n"), id_list.num_ids);
+ delete_id_list("DELETE FROM Filename WHERE FilenameId=%s", &id_list);
+ }
+ if (!make_id_list(query, &id_list)) {
+ exit(1);
}
- }
- if (quit) {
- return;
- }
- if (fix && id_list.num_ids > 0) {
- printf(_("Deleting %d orphaned Filename records.\n"), id_list.num_ids);
- delete_id_list("DELETE FROM Filename WHERE FilenameId=%s", &id_list);
}
}