Skip to content

Commit

Permalink
dird: Allow to restore from copies.
Browse files Browse the repository at this point in the history
Until now you can specify the keyword copies when doing a restore
but it will only show the copies but not actually use them for restore.
This is somewhat counter intuitive so this patch adds the code that
asks if you really want to use the copies for the restore. If you
specify the yes keyword you can skip this question.
  • Loading branch information
Marco van Wieringen committed Jun 16, 2016
1 parent f8dbb87 commit d3e8c0b
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 45 deletions.
27 changes: 18 additions & 9 deletions src/cats/sql_cmds.c
Expand Up @@ -234,8 +234,8 @@ const char *uar_full =
"FROM temp1,Job,JobMedia,Media "
"WHERE temp1.JobId=Job.JobId "
"AND Level='F' AND JobStatus IN ('T','W') AND Type='B' "
"AND Media.Enabled=1 "
"AND JobMedia.JobId=Job.JobId "
"AND Media.Enabled=1 "
"AND JobMedia.MediaId=Media.MediaId";

const char *uar_dif =
Expand Down Expand Up @@ -263,28 +263,37 @@ const char *uar_inc =
"FROM Job,JobMedia,Media,FileSet "
"WHERE Job.JobTDate>%s AND Job.StartTime<'%s' "
"AND Job.ClientId=%s "
"AND Media.Enabled=1 "
"AND JobMedia.JobId=Job.JobId "
"AND Media.Enabled=1 "
"AND JobMedia.MediaId=Media.MediaId "
"AND Job.Level='I' AND JobStatus IN ('T','W') AND Type='B' "
"AND Job.FileSetId=FileSet.FileSetId "
"AND FileSet.FileSet='%s' "
"%s";

const char *uar_list_temp =
"SELECT DISTINCT JobId,Level,JobFiles,JobBytes,StartTime,VolumeName"
" FROM temp"
" ORDER BY StartTime ASC";


const char *uar_sel_jobid_temp =
"SELECT DISTINCT JobId,StartTime FROM temp ORDER BY StartTime ASC";

const char *uar_sel_all_temp1 = "SELECT * FROM temp1";

const char *uar_sel_all_temp = "SELECT * FROM temp";


const char *uar_sel_jobid_copies =
"SELECT DISTINCT JobId,StartTime "
"FROM Job "
"WHERE Type = 'C' "
"AND (PriorJobId IN (%s)) "
"ORDER BY StartTime ASC";

const char *uar_list_jobs_by_idlist =
"SELECT DISTINCT Job.JobId,Job.Level,Job.JobFiles,Job.JobBytes,"
"Job.StartTime,Media.VolumeName "
"FROM Job,JobMedia,Media "
"WHERE Job.JobId IN (%s) "
"AND JobMedia.JobId=Job.JobId "
"AND Media.Enabled=1 "
"AND JobMedia.MediaId=Media.MediaId "
"ORDER BY StartTime ASC";

/* Select FileSet names for this Client */
const char *uar_sel_fileset =
Expand Down
3 changes: 2 additions & 1 deletion src/cats/sql_cmds.h
Expand Up @@ -46,7 +46,7 @@ extern const char CATS_IMP_EXP *uar_last_full;
extern const char CATS_IMP_EXP *uar_last_full_no_pool;
extern const char CATS_IMP_EXP *uar_full;
extern const char CATS_IMP_EXP *uar_inc;
extern const char CATS_IMP_EXP *uar_list_temp;
extern const char CATS_IMP_EXP *uar_list_jobs_by_idlist;
extern const char CATS_IMP_EXP *uar_sel_all_temp1;
extern const char CATS_IMP_EXP *uar_sel_fileset;
extern const char CATS_IMP_EXP *uar_sel_filesetid;
Expand All @@ -58,6 +58,7 @@ extern const char CATS_IMP_EXP *uar_count_files;
extern const char CATS_IMP_EXP *uar_jobids_fileindex;
extern const char CATS_IMP_EXP *uar_jobid_fileindex_from_table;
extern const char CATS_IMP_EXP *uar_sel_jobid_temp;
extern const char CATS_IMP_EXP *uar_sel_jobid_copies;

extern const char CATS_IMP_EXP *select_recent_version[];
extern const char CATS_IMP_EXP *select_recent_version_with_basejob[];
Expand Down
11 changes: 4 additions & 7 deletions src/dird/ua_cmds.c
Expand Up @@ -2035,18 +2035,16 @@ static bool delete_job_id_range(UAContext *ua, char *tok)
*/
if ((j2 - j1) > 25) {
bsnprintf(buf, sizeof(buf),
_("Are you sure you want to delete %d JobIds ? (yes/no): "),
j2 - j1);
if (!get_yesno(ua, buf)) {
_("Are you sure you want to delete %d JobIds ? (yes/no): "), j2 - j1);
if (!get_yesno(ua, buf) || !ua->pint32_val) {
return true;
}
}
for (j = j1; j <= j2; j++) {
do_job_delete(ua, j);
}
} else {
ua->warning_msg(_("Illegal JobId range %s - %s should define increasing JobIds, ignored\n"),
tok, tok2);
ua->warning_msg(_("Illegal JobId range %s - %s should define increasing JobIds, ignored\n"), tok, tok2);
}
} else {
ua->warning_msg(_("Illegal JobId range %s - %s, ignored\n"), tok, tok2);
Expand Down Expand Up @@ -2087,8 +2085,7 @@ static bool delete_volume(UAContext *ua)
if (find_arg(ua, "yes") >= 0) {
ua->pint32_val = 1; /* Have "yes" on command line already" */
} else {
bsnprintf(buf, sizeof(buf), _("Are you sure you want to delete Volume \"%s\"? (yes/no): "),
mr.VolumeName);
bsnprintf(buf, sizeof(buf), _("Are you sure you want to delete Volume \"%s\"? (yes/no): "), mr.VolumeName);
if (!get_yesno(ua, buf)) {
return true;
}
Expand Down
3 changes: 1 addition & 2 deletions src/dird/ua_label.c
Expand Up @@ -397,8 +397,7 @@ static void label_from_barcodes(UAContext *ua, int drive,
}

if (!yes &&
( !get_yesno(ua, _("Do you want to label these Volumes? (yes|no): ")) ||
(ua->pint32_val == 0))) {
(!get_yesno(ua, _("Do you want to label these Volumes? (yes|no): ")) || !ua->pint32_val)) {
goto bail_out;
}

Expand Down
6 changes: 2 additions & 4 deletions src/dird/ua_prune.c
Expand Up @@ -253,8 +253,7 @@ static bool prune_directory(UAContext *ua, CLIENTRES *client)
*/
if (!client) {
if (!get_yesno(ua, _("No client restriction given really remove "
"directory for all clients (yes/no): ")) ||
ua->pint32_val == 0) {
"directory for all clients (yes/no): ")) || !ua->pint32_val) {
if (!(client = get_client_resource(ua))) {
return false;
}
Expand Down Expand Up @@ -338,8 +337,7 @@ static bool prune_directory(UAContext *ua, CLIENTRES *client)
* them anymore.
*/
if (!client) {
if (!get_yesno(ua, _("Cleanup orphaned path records (yes/no):")) ||
ua->pint32_val == 0) {
if (!get_yesno(ua, _("Cleanup orphaned path records (yes/no):")) || !ua->pint32_val) {
retval = true;
goto bail_out;
}
Expand Down
53 changes: 40 additions & 13 deletions src/dird/ua_restore.c
Expand Up @@ -1109,8 +1109,10 @@ static bool ask_for_fileregex(UAContext *ua, RESTORE_CTX *rx)
"so file selection is not possible.\n"
"Most likely your retention policy pruned the files.\n"));
if (get_yesno(ua, _("\nDo you want to restore all the files? (yes|no): "))) {
if (ua->pint32_val == 1)
if (ua->pint32_val) {
return true;
}

while (get_cmd(ua, _("\nRegexp matching files to restore? (empty to abort): "))) {
if (ua->cmd[0] == '\0') {
break;
Expand All @@ -1135,6 +1137,7 @@ static bool ask_for_fileregex(UAContext *ua, RESTORE_CTX *rx)
}
}
}

return false;
}

Expand Down Expand Up @@ -1303,17 +1306,20 @@ static bool build_directory_tree(UAContext *ua, RESTORE_CTX *rx)
*/
static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *date)
{
bool ok = false;
FILESET_DBR fsr;
int i;
CLIENT_DBR cr;
char fileset_name[MAX_NAME_LENGTH];
FILESET_DBR fsr;
bool ok = false;
char ed1[50], ed2[50];
char pool_select[MAX_NAME_LENGTH];
int i;
char fileset_name[MAX_NAME_LENGTH];

/* Create temp tables */
/*
* Create temp tables
*/
db_sql_query(ua->db, uar_del_temp);
db_sql_query(ua->db, uar_del_temp1);

if (!db_sql_query(ua->db, uar_create_temp[db_get_type_index(ua->db)])) {
ua->error_msg("%s\n", db_strerror(ua->db));
}
Expand All @@ -1338,8 +1344,7 @@ static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *dat
if (i >= 0 && is_name_valid(ua->argv[i], &ua->errmsg)) {
bstrncpy(fsr.FileSet, ua->argv[i], sizeof(fsr.FileSet));
if (!db_get_fileset_record(ua->jcr, ua->db, &fsr)) {
ua->error_msg(_("Error getting FileSet \"%s\": ERR=%s\n"), fsr.FileSet,
db_strerror(ua->db));
ua->error_msg(_("Error getting FileSet \"%s\": ERR=%s\n"), fsr.FileSet, db_strerror(ua->db));
i = -1;
}
} else if (i >= 0) { /* name is invalid */
Expand All @@ -1363,7 +1368,7 @@ static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *dat
if (!db_get_fileset_record(ua->jcr, ua->db, &fsr)) {
ua->warning_msg(_("Error getting FileSet record: %s\n"), db_strerror(ua->db));
ua->send_msg(_("This probably means you modified the FileSet.\n"
"Continuing anyway.\n"));
"Continuing anyway.\n"));
}
}

Expand All @@ -1373,11 +1378,11 @@ static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *dat
pool_select[0] = 0;
if (rx->pool) {
POOL_DBR pr;

memset(&pr, 0, sizeof(pr));
bstrncpy(pr.Name, rx->pool->name(), sizeof(pr.Name));
if (db_get_pool_record(ua->jcr, ua->db, &pr)) {
bsnprintf(pool_select, sizeof(pool_select), "AND Media.PoolId=%s ",
edit_int64(pr.PoolId, ed1));
bsnprintf(pool_select, sizeof(pool_select), "AND Media.PoolId=%s ", edit_int64(pr.PoolId, ed1));
} else {
ua->warning_msg(_("Pool \"%s\" not found, using any pool.\n"), pr.Name);
}
Expand Down Expand Up @@ -1456,7 +1461,6 @@ static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *dat
* Get the JobIds from that list
*/
rx->last_jobid[0] = rx->JobIds[0] = 0;

if (!db_sql_query(ua->db, uar_sel_jobid_temp, jobid_handler, (void *)rx)) {
ua->warning_msg("%s\n", db_strerror(ua->db));
}
Expand All @@ -1467,12 +1471,34 @@ static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *dat
* Display a list of all copies
*/
db_list_copies_records(ua->jcr, ua->db, "", rx->JobIds, ua->send, HORZ_LIST);

if (find_arg(ua, NT_("yes")) > 0) {
ua->pint32_val == 1;
} else {
get_yesno(ua, _("\nDo you want to restore from these copies? (yes|no): "));
}

if (ua->pint32_val) {
POOL_MEM JobIds(PM_FNAME);

/*
* Change the list of jobs needed to do the restore to the copies of the Job.
*/
pm_strcpy(JobIds, rx->JobIds);
rx->last_jobid[0] = rx->JobIds[0] = 0;
Mmsg(rx->query, uar_sel_jobid_copies, JobIds.c_str());
if (!db_sql_query(ua->db, rx->query, jobid_handler, (void *)rx)) {
ua->warning_msg("%s\n", db_strerror(ua->db));
}
}
}

/*
* Display a list of Jobs selected for this restore
*/
db_list_sql_query(ua->jcr, ua->db, uar_list_temp, ua->send, HORZ_LIST, true);
Mmsg(rx->query, uar_list_jobs_by_idlist, rx->JobIds);
db_list_sql_query(ua->jcr, ua->db, rx->query, ua->send, HORZ_LIST, true);

ok = true;
} else {
ua->warning_msg(_("No jobs found.\n"));
Expand All @@ -1481,6 +1507,7 @@ static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *dat
bail_out:
db_sql_query(ua->db, uar_del_temp);
db_sql_query(ua->db, uar_del_temp1);

return ok;
}

Expand Down
5 changes: 3 additions & 2 deletions src/dird/ua_run.c
Expand Up @@ -309,7 +309,8 @@ bool rerun_cmd(UAContext *ua, const char *cmd)
}
ua->send_msg("\n");

if (!yes && (!get_yesno(ua, _("rerun these jobids? (yes/no): ")) || ua->pint32_val == 0 )) {
if (!yes &&
(!get_yesno(ua, _("rerun these jobids? (yes/no): ")) || !ua->pint32_val)) {
goto bail_out;
}
/*
Expand Down Expand Up @@ -672,7 +673,7 @@ int modify_job_parameters(UAContext *ua, JCR *jcr, RUN_CTX &rc)
case 7:
/* Priority */
if (get_pint(ua, _("Enter new Priority: "))) {
if (ua->pint32_val == 0) {
if (!ua->pint32_val) {
ua->send_msg(_("Priority must be a positive integer.\n"));
} else {
jcr->JobPriority = ua->pint32_val;
Expand Down
6 changes: 3 additions & 3 deletions src/dird/ua_select.c
Expand Up @@ -1535,7 +1535,7 @@ alist *select_jobs(UAContext *ua, const char *reason)
* Only ask for confirmation when not in batch mode and there is no yes on the cmdline.
*/
if (!ua->batch && find_arg(ua, NT_("yes")) == -1) {
if (!get_yesno(ua, _("Confirm cancel (yes/no): ")) || ua->pint32_val == 0) {
if (!get_yesno(ua, _("Confirm cancel (yes/no): ")) || !ua->pint32_val) {
goto bail_out;
}
}
Expand Down Expand Up @@ -1570,12 +1570,12 @@ alist *select_jobs(UAContext *ua, const char *reason)
char nbuf[1000];

bsnprintf(nbuf, sizeof(nbuf), _("Cancel: %s\n\n%s"), buf, _("Confirm cancel?"));
if (!get_yesno(ua, nbuf) || ua->pint32_val == 0) {
if (!get_yesno(ua, nbuf) || !ua->pint32_val) {
goto bail_out;
}
} else {
if (njobs == 1) {
if (!get_yesno(ua, _("Confirm cancel (yes/no): ")) || ua->pint32_val == 0) {
if (!get_yesno(ua, _("Confirm cancel (yes/no): ")) || !ua->pint32_val) {
goto bail_out;
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/dird/ua_update.c
Expand Up @@ -713,7 +713,7 @@ static bool update_volume(UAContext *ua)

case 6: /* Recycle */
ua->info_msg(_("Current recycle flag is: %s\n"),
mr.Recycle==1?_("yes"):_("no"));
(mr.Recycle == 1) ? _("yes") : _("no"));
if (!get_yesno(ua, _("Enter new Recycle status: "))) {
return false;
}
Expand All @@ -730,8 +730,7 @@ static bool update_volume(UAContext *ua)

case 8: /* InChanger */
ua->info_msg(_("Current InChanger flag is: %d\n"), mr.InChanger);
bsnprintf(buf, sizeof(buf), _("Set InChanger flag for Volume \"%s\": yes/no: "),
mr.VolumeName);
bsnprintf(buf, sizeof(buf), _("Set InChanger flag for Volume \"%s\": yes/no: "), mr.VolumeName);
if (!get_yesno(ua, buf)) {
return false;
}
Expand Down Expand Up @@ -760,7 +759,7 @@ static bool update_volume(UAContext *ua)
VolFiles = ua->pint32_val;
if (VolFiles != (int)(mr.VolFiles + 1)) {
ua->warning_msg(_("Normally, you should only increase Volume Files by one!\n"));
if (!get_yesno(ua, _("Increase Volume Files? (yes/no): ")) || ua->pint32_val == 0) {
if (!get_yesno(ua, _("Increase Volume Files? (yes/no): ")) || !ua->pint32_val) {
break;
}
}
Expand Down

0 comments on commit d3e8c0b

Please sign in to comment.