extern void print_bsr(UAContext *ua, RBSR *bsr);
/* Imported variables */
-extern char *uar_list_jobs, *uar_file, *uar_sel_files;
-extern char *uar_del_temp, *uar_del_temp1, *uar_create_temp;
-extern char *uar_create_temp1, *uar_last_full, *uar_full;
-extern char *uar_inc_dec, *uar_list_temp, *uar_sel_jobid_temp;
-extern char *uar_sel_all_temp1, *uar_sel_fileset, *uar_mediatype;
+extern char *uar_list_jobs, *uar_file, *uar_sel_files;
+extern char *uar_del_temp, *uar_del_temp1, *uar_create_temp;
+extern char *uar_create_temp1, *uar_last_full, *uar_full;
+extern char *uar_inc_dec, *uar_list_temp, *uar_sel_jobid_temp;
+extern char *uar_sel_all_temp1, *uar_sel_fileset, *uar_mediatype;
extern char *uar_jobid_fileindex;
POOLMEM *JobIds; /* User entered string of JobIds */
STORE *store;
JOB *restore_job;
+ POOL *pool;
int restore_jobs;
uint32_t selected_files;
char *where;
}
if (!open_db(ua)) {
- free_rx(&rx);
- return 0;
+ goto bail_out;
}
/* Ensure there is at least one Restore Job */
bsendmsg(ua, _(
"No Restore Job Resource found. You must create at least\n"
"one before running this command.\n"));
- free_rx(&rx);
- return 0;
+ goto bail_out;
}
/*
*/
switch (user_select_jobids_or_files(ua, &rx)) {
case 0:
- free_rx(&rx);
- return 0; /* error */
+ goto bail_out;
case 1: /* select by jobid */
build_directory_tree(ua, &rx);
break;
if (rx.bsr->JobId) {
if (!complete_bsr(ua, rx.bsr)) { /* find Vol, SessId, SessTime from JobIds */
bsendmsg(ua, _("Unable to construct a valid BSR. Cannot continue.\n"));
- free_rx(&rx);
- return 0;
+ goto bail_out;
}
write_bsr_file(ua, rx.bsr);
- bsendmsg(ua, _("\n%u file%s selected to restore.\n\n"), rx.selected_files,
+ bsendmsg(ua, _("\n%u file%s selected to be restored.\n\n"), rx.selected_files,
rx.selected_files==1?"":"s");
} else {
- bsendmsg(ua, _("No files selected to restore.\n"));
- free_rx(&rx);
- return 0;
+ bsendmsg(ua, _("No files selected to be restored.\n"));
+ goto bail_out;
}
if (rx.restore_jobs == 1) {
job = select_restore_job_resource(ua);
}
if (!job) {
- bsendmsg(ua, _("No Restore Job resource found!\n"));
- free_rx(&rx);
- return 0;
+ goto bail_out;
}
get_client_name(ua, &rx);
+ if (!rx.ClientName) {
+ bsendmsg(ua, _("No Restore Job resource found!\n"));
+ goto bail_out;
+ }
/* Build run command */
if (rx.where) {
bsendmsg(ua, _("Restore command done.\n"));
free_rx(&rx);
return 1;
+
+bail_out:
+ free_rx(&rx);
+ return 0;
+
}
static void free_rx(RESTORE_CTX *rx)
}
memset(&cr, 0, sizeof(cr));
if (!get_client_dbr(ua, &cr)) {
- free_rx(rx);
return 0;
}
bstrncpy(rx->ClientName, cr.Name, sizeof(rx->ClientName));
"before", /* 2 */
"file", /* 3 */
"select", /* 4 */
+ "pool", /* 5 */
NULL
};
}
done = true;
break;
+ case 5: /* pool specified */
+ i = find_arg_with_value(ua, "pool");
+ if (i >= 0) {
+ rx->pool = (POOL *)GetResWithName(R_POOL, ua->argv[i]);
+ } else {
+ bsendmsg(ua, _("Error: Pool resource \"%s\" does not exist.\n"), ua->argv[i]);
+ }
+ break;
default:
break;
}
}
jr.JobId = JobId;
if (!db_get_job_record(ua->jcr, ua->db, &jr)) {
- bsendmsg(ua, _("Unable to get Job record. ERR=%s\n"), db_strerror(ua->db));
+ bsendmsg(ua, _("Unable to get Job record for JobId=%u: ERR=%s\n"),
+ JobId, db_strerror(ua->db));
return 0;
}
rx->TotalFiles += jr.JobFiles;
return 1;
}
+/*
+ * Get date from user
+ */
static int get_date(UAContext *ua, char *date, int date_len)
{
bsendmsg(ua, _("The restored files will the most current backup\n"
return 1;
}
+/*
+ * Insert a single file, or read a list of files from a file
+ */
static void insert_one_file(UAContext *ua, RESTORE_CTX *rx, char *date)
{
FILE *ffd;
}
rx->selected_files++;
/*
- * Find the FileSets for this JobId and add to the name_list
+ * Find the MediaTypes for this JobId and add to the name_list
*/
Mmsg(&rx->query, uar_mediatype, rx->JobId);
if (!db_sql_query(ua->db, rx->query, unique_name_list_handler, (void *)&rx->name_list)) {
bsendmsg(ua, "%s", db_strerror(ua->db));
}
/*
- * Find the FileSets for this JobId and add to the name_list
+ * Find the MediaTypes for this JobId and add to the name_list
*/
Mmsg(&rx->query, uar_mediatype, JobId);
if (!db_sql_query(ua->db, rx->query, unique_name_list_handler, (void *)&rx->name_list)) {
CLIENT_DBR cr;
char fileset_name[MAX_NAME_LENGTH];
char ed1[50];
+ char pool_select[MAX_NAME_LENGTH];
+ int i;
/* Create temp tables */
bstrncpy(rx->ClientName, cr.Name, sizeof(rx->ClientName));
/*
- * Select FileSet
+ * Get FileSet
*/
- Mmsg(&rx->query, uar_sel_fileset, cr.ClientId, cr.ClientId);
- start_prompt(ua, _("The defined FileSet resources are:\n"));
- if (!db_sql_query(ua->db, rx->query, fileset_handler, (void *)ua)) {
- bsendmsg(ua, "%s\n", db_strerror(ua->db));
+ memset(&fsr, 0, sizeof(fsr));
+ i = find_arg_with_value(ua, "FileSet");
+ if (i >= 0) {
+ bstrncpy(fsr.FileSet, ua->argv[i], sizeof(fsr.FileSet));
+ if (!db_get_fileset_record(ua->jcr, ua->db, &fsr)) {
+ bsendmsg(ua, _("Error getting FileSet \"%s\": ERR=%s\n"), fsr.FileSet,
+ db_strerror(ua->db));
+ i = -1;
+ }
}
- if (do_prompt(ua, _("FileSet"), _("Select FileSet resource"),
+ if (i < 0) { /* fileset not found */
+ Mmsg(&rx->query, uar_sel_fileset, cr.ClientId, cr.ClientId);
+ start_prompt(ua, _("The defined FileSet resources are:\n"));
+ if (!db_sql_query(ua->db, rx->query, fileset_handler, (void *)ua)) {
+ bsendmsg(ua, "%s\n", db_strerror(ua->db));
+ }
+ if (do_prompt(ua, _("FileSet"), _("Select FileSet resource"),
fileset_name, sizeof(fileset_name)) < 0) {
- goto bail_out;
- }
- fsr.FileSetId = atoi(fileset_name); /* Id is first part of name */
- if (!db_get_fileset_record(ua->jcr, ua->db, &fsr)) {
- bsendmsg(ua, _("Error getting FileSet record: %s\n"), db_strerror(ua->db));
- bsendmsg(ua, _("This probably means you modified the FileSet.\n"
+ goto bail_out;
+ }
+
+ bstrncpy(fsr.FileSet, fileset_name, sizeof(fsr.FileSet));
+ if (!db_get_fileset_record(ua->jcr, ua->db, &fsr)) {
+ bsendmsg(ua, _("Error getting FileSet record: %s\n"), db_strerror(ua->db));
+ bsendmsg(ua, _("This probably means you modified the FileSet.\n"
"Continuing anyway.\n"));
+ }
}
+ /* If Pool specified, add PoolId specification */
+ pool_select[0] = 0;
+ if (rx->pool) {
+ POOL_DBR pr;
+ memset(&pr, 0, sizeof(pr));
+ bstrncpy(pr.Name, rx->pool->hdr.name, sizeof(pr.Name));
+ if (db_get_pool_record(ua->jcr, ua->db, &pr)) {
+ bsnprintf(pool_select, sizeof(pool_select), "AND Media.PoolId=%u ", pr.PoolId);
+ } else {
+ bsendmsg(ua, _("Pool \"%s\" not found, using any pool.\n"), pr.Name);
+ }
+ }
/* Find JobId of last Full backup for this client, fileset */
- Mmsg(&rx->query, uar_last_full, cr.ClientId, cr.ClientId, date, fsr.FileSetId);
+ Mmsg(&rx->query, uar_last_full, cr.ClientId, cr.ClientId, date, fsr.FileSet,
+ pool_select);
if (!db_sql_query(ua->db, rx->query, NULL, NULL)) {
bsendmsg(ua, "%s\n", db_strerror(ua->db));
goto bail_out;
bsendmsg(ua, "%s\n", db_strerror(ua->db));
goto bail_out;
}
- /* Note, this is needed as I don't seem to get the callback
+ /* Note, this is needed because I don't seem to get the callback
* from the call just above.
*/
rx->JobTDate = 0;
/* Now find all Incremental/Decremental Jobs after Full save */
Mmsg(&rx->query, uar_inc_dec, edit_uint64(rx->JobTDate, ed1), date,
- cr.ClientId, fsr.FileSetId);
+ cr.ClientId, fsr.FileSet, pool_select);
if (!db_sql_query(ua->db, rx->query, NULL, NULL)) {
bsendmsg(ua, "%s\n", db_strerror(ua->db));
}
return stat;
}
+
/* Return next JobId from comma separated list */
static int next_jobid_from_list(char **p, uint32_t *JobId)
{
{
RESTORE_CTX *rx = (RESTORE_CTX *)ctx;
- rx->JobTDate = strtoll(row[1], NULL, 10);
-
+ rx->JobTDate = str_to_int64(row[1]);
return 0;
}
/*
- * Callback handler build fileset prompt list
+ * Callback handler build FileSet name prompt list
*/
static int fileset_handler(void *ctx, int num_fields, char **row)
{
- char prompt[MAX_NAME_LENGTH+200];
-
- snprintf(prompt, sizeof(prompt), "%s %s %s", row[0], row[1], row[2]);
- add_prompt((UAContext *)ctx, prompt);
+ /* row[0] = FileSet (name) */
+ if (row[0]) {
+ add_prompt((UAContext *)ctx, row[0]);
+ }
return 0;
}
static void get_storage_from_mediatype(UAContext *ua, NAME_LIST *name_list, RESTORE_CTX *rx)
{
- char name[MAX_NAME_LENGTH];
- STORE *store = NULL;
-
if (name_list->num_ids > 1) {
bsendmsg(ua, _("Warning, the JobIds that you selected refer to more than one MediaType.\n"
"Restore is not possible. The MediaTypes used are:\n"));
return;
}
- start_prompt(ua, _("The defined Storage resources are:\n"));
- LockRes();
- while ((store = (STORE *)GetNextRes(R_STORAGE, (RES *)store))) {
- if (strcmp(store->media_type, name_list->name[0]) == 0) {
- add_prompt(ua, store->hdr.name);
- }
- }
- UnlockRes();
- do_prompt(ua, _("Storage"), _("Select Storage resource"), name, sizeof(name));
- rx->store = (STORE *)GetResWithName(R_STORAGE, name);
+ rx->store = get_storage_resource(ua, false /* don't use default */);
+
if (!rx->store) {
bsendmsg(ua, _("\nWarning. Unable to find Storage resource for\n"
"MediaType %s, needed by the Jobs you selected.\n"