*/
/*
- Copyright (C) 2002-2003 Kern Sibbald and John Walker
+ Copyright (C) 2002-2004 Kern Sibbald and John Walker
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
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;
static void free_name_list(NAME_LIST *name_list);
static void get_storage_from_mediatype(UAContext *ua, NAME_LIST *name_list, RESTORE_CTX *rx);
static int select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *date);
-static void build_directory_tree(UAContext *ua, RESTORE_CTX *rx);
+static bool build_directory_tree(UAContext *ua, RESTORE_CTX *rx);
static void free_rx(RESTORE_CTX *rx);
static void split_path_and_filename(RESTORE_CTX *rx, char *fname);
static int jobid_fileindex_handler(void *ctx, int num_fields, char **row);
case 0:
goto bail_out;
case 1: /* select by jobid */
- build_directory_tree(ua, &rx);
+ if (!build_directory_tree(ua, &rx)) {
+ bsendmsg(ua, _("Restore not done.\n"));
+ goto bail_out;
+ }
break;
case 2: /* select by filename, no tree needed */
break;
if (rx.where) {
Mmsg(&ua->cmd,
"run job=\"%s\" client=\"%s\" storage=\"%s\" bootstrap=\"%s/restore.bsr\""
- " where=\"%s\"",
+ " where=\"%s\" files=%d",
job->hdr.name, rx.ClientName, rx.store?rx.store->hdr.name:"",
- working_directory, rx.where);
+ working_directory, rx.where, rx.selected_files);
} else {
Mmsg(&ua->cmd,
"run job=\"%s\" client=\"%s\" storage=\"%s\" bootstrap=\"%s/restore.bsr\"",
job->hdr.name, rx.ClientName, rx.store?rx.store->hdr.name:"",
working_directory);
}
- if (find_arg(ua, _("run")) >= 0) {
- pm_strcat(&ua->cmd, " run"); /* pass it on to the run command */
+ if (find_arg(ua, _("yes")) > 0) {
+ pm_strcat(&ua->cmd, " yes"); /* pass it on to the run command */
}
Dmsg1(400, "Submitting: %s\n", ua->cmd);
parse_ua_args(ua);
"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;
Dmsg2(100, "sllit path=%s file=%s\n", rx->path, rx->fname);
}
-static void build_directory_tree(UAContext *ua, RESTORE_CTX *rx)
+static bool build_directory_tree(UAContext *ua, RESTORE_CTX *rx)
{
TREE_CTX tree;
JobId_t JobId, last_JobId;
char *p;
char *nofname = "";
+ bool OK = true;
memset(&tree, 0, sizeof(TREE_CTX));
/*
get_storage_from_mediatype(ua, &rx->name_list, rx);
if (find_arg(ua, _("all")) < 0) {
- /* Let the user select which files to restore */
- user_select_files_from_tree(&tree);
+ /* Let the user interact in selecting which files to restore */
+ OK = user_select_files_from_tree(&tree);
}
/*
* Walk down through the tree finding all files marked to be
* extracted making a bootstrap file.
*/
- for (TREE_NODE *node=first_tree_node(tree.root); node; node=next_tree_node(node)) {
- Dmsg2(400, "FI=%d node=0x%x\n", node->FileIndex, node);
- if (node->extract) {
- Dmsg2(400, "type=%d FI=%d\n", node->type, node->FileIndex);
- add_findex(rx->bsr, node->JobId, node->FileIndex);
- rx->selected_files++;
+ if (OK) {
+ for (TREE_NODE *node=first_tree_node(tree.root); node; node=next_tree_node(node)) {
+ Dmsg2(400, "FI=%d node=0x%x\n", node->FileIndex, node);
+ if (node->extract || node->extract_dir) {
+ Dmsg2(400, "type=%d FI=%d\n", node->type, node->FileIndex);
+ add_findex(rx->bsr, node->JobId, node->FileIndex);
+ rx->selected_files++;
+ }
}
}
free_tree(tree.root); /* free the directory tree */
+ return OK;
}
CLIENT_DBR cr;
char fileset_name[MAX_NAME_LENGTH];
char ed1[50];
+ char pool_select[MAX_NAME_LENGTH];
int i;
}
}
+ /* 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.FileSet);
+ 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;
/* Now find all Incremental/Decremental Jobs after Full save */
Mmsg(&rx->query, uar_inc_dec, edit_uint64(rx->JobTDate, ed1), date,
- cr.ClientId, fsr.FileSet);
+ cr.ClientId, fsr.FileSet, pool_select);
if (!db_sql_query(ua->db, rx->query, NULL, NULL)) {
bsendmsg(ua, "%s\n", db_strerror(ua->db));
}
{
RESTORE_CTX *rx = (RESTORE_CTX *)ctx;
- rx->JobTDate = strtoll(row[1], NULL, 10);
-
+ rx->JobTDate = str_to_int64(row[1]);
return 0;
}
*/
static int fileset_handler(void *ctx, int num_fields, char **row)
{
-
/* row[0] = FileSet (name) */
if (row[0]) {
add_prompt((UAContext *)ctx, row[0]);