/
ua_run.cc
2209 lines (2064 loc) · 70.1 KB
/
ua_run.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2001-2012 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2019 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
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
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
/*
* Kern Sibbald, December MMI
*/
/**
* @file
* BAREOS Director -- Run Command
*/
#include "include/bareos.h"
#include "dird.h"
#include "dird/job.h"
#include "dird/migration.h"
#include "dird/storage.h"
#include "dird/ua_db.h"
#include "dird/ua_input.h"
#include "dird/ua_select.h"
#include "dird/ua_run.h"
#include "lib/berrno.h"
#include "lib/edit.h"
#include "lib/keyword_table_s.h"
namespace directordaemon {
/* Forward referenced subroutines */
static void SelectJobLevel(UaContext* ua, JobControlRecord* jcr);
static bool DisplayJobParameters(UaContext* ua,
JobControlRecord* jcr,
RunContext& rc);
static void SelectWhereRegexp(UaContext* ua, JobControlRecord* jcr);
static bool ScanCommandLineArguments(UaContext* ua, RunContext& rc);
static bool ResetRestoreContext(UaContext* ua,
JobControlRecord* jcr,
RunContext& rc);
static int ModifyJobParameters(UaContext* ua,
JobControlRecord* jcr,
RunContext& rc);
/* Imported variables */
extern struct s_kw ReplaceOptions[];
/**
* Rerun a job by jobid. Lookup the job data and rerun the job with that data.
*
* Returns: false on error
* true if OK
*/
static inline bool reRunJob(UaContext* ua, JobId_t JobId, bool yes, utime_t now)
{
JobDbRecord jr;
char dt[MAX_TIME_LENGTH];
PoolMem cmdline(PM_MESSAGE);
jr.JobId = JobId;
ua->SendMsg("rerunning jobid %d\n", jr.JobId);
if (!ua->db->GetJobRecord(ua->jcr, &jr)) {
Jmsg(ua->jcr, M_WARNING, 0,
_("Error getting Job record for Job rerun: ERR=%s"),
ua->db->strerror());
goto bail_out;
}
/*
* Only perform rerun on JobTypes where it makes sense.
*/
switch (jr.JobType) {
case JT_BACKUP:
case JT_COPY:
case JT_MIGRATE:
break;
default:
return true;
}
if (jr.JobLevel == L_NONE) {
Mmsg(cmdline, "run job=\"%s\"", jr.Name);
} else {
Mmsg(cmdline, "run job=\"%s\" level=\"%s\"", jr.Name,
JobLevelToString(jr.JobLevel));
}
PmStrcpy(ua->cmd, cmdline);
if (jr.ClientId) {
ClientDbRecord cr;
cr.ClientId = jr.ClientId;
if (!ua->db->GetClientRecord(ua->jcr, &cr)) {
Jmsg(ua->jcr, M_WARNING, 0,
_("Error getting Client record for Job rerun: ERR=%s"),
ua->db->strerror());
goto bail_out;
}
Mmsg(cmdline, " client=\"%s\"", cr.Name);
PmStrcat(ua->cmd, cmdline);
}
if (jr.PoolId) {
PoolDbRecord pr;
pr.PoolId = jr.PoolId;
if (!ua->db->GetPoolRecord(ua->jcr, &pr)) {
Jmsg(ua->jcr, M_WARNING, 0,
_("Error getting Pool record for Job rerun: ERR=%s"),
ua->db->strerror());
goto bail_out;
}
/*
* Source pool.
*/
switch (jr.JobType) {
case JT_COPY:
case JT_MIGRATE: {
JobResource* job = NULL;
job = ua->GetJobResWithName(jr.Name, false);
if (job) {
Mmsg(cmdline, " pool=\"%s\"", job->pool->resource_name_);
PmStrcat(ua->cmd, cmdline);
}
break;
}
case JT_BACKUP:
switch (jr.JobLevel) {
case L_VIRTUAL_FULL: {
JobResource* job = NULL;
job = ua->GetJobResWithName(jr.Name, false);
if (job) {
Mmsg(cmdline, " pool=\"%s\"", job->pool->resource_name_);
PmStrcat(ua->cmd, cmdline);
}
break;
}
default:
Mmsg(cmdline, " pool=\"%s\"", pr.Name);
PmStrcat(ua->cmd, cmdline);
break;
}
}
/*
* Next pool.
*/
switch (jr.JobType) {
case JT_COPY:
case JT_MIGRATE:
Mmsg(cmdline, " nextpool=\"%s\"", pr.Name);
PmStrcat(ua->cmd, cmdline);
break;
case JT_BACKUP:
switch (jr.JobLevel) {
case L_VIRTUAL_FULL:
Mmsg(cmdline, " nextpool=\"%s\"", pr.Name);
PmStrcat(ua->cmd, cmdline);
break;
default:
break;
}
break;
}
}
if (jr.FileSetId) {
FileSetDbRecord fs;
fs.FileSetId = jr.FileSetId;
if (!ua->db->GetFilesetRecord(ua->jcr, &fs)) {
Jmsg(ua->jcr, M_WARNING, 0,
_("Error getting FileSet record for Job rerun: ERR=%s"),
ua->db->strerror());
goto bail_out;
}
Mmsg(cmdline, " fileset=\"%s\"", fs.FileSet);
PmStrcat(ua->cmd, cmdline);
}
bstrutime(dt, sizeof(dt), now);
Mmsg(cmdline, " when=\"%s\"", dt);
PmStrcat(ua->cmd, cmdline);
if (yes) { PmStrcat(ua->cmd, " yes"); }
Dmsg1(100, "rerun cmdline=%s\n", ua->cmd);
ParseUaArgs(ua);
return RunCmd(ua, ua->cmd);
bail_out:
return false;
}
/**
* Rerun a job selection.
*
* Returns: 0 on error
* 1 if OK
*/
bool reRunCmd(UaContext* ua, const char* cmd)
{
int i, j, d, h, s, u;
int days = 0;
int hours = 0;
int since_jobid = 0;
int until_jobid = 0;
JobId_t JobId;
dbid_list ids;
PoolMem query(PM_MESSAGE);
utime_t now;
time_t schedtime;
char dt[MAX_TIME_LENGTH];
char ed1[50];
char ed2[50];
bool yes = false; /* Was "yes" given on cmdline*/
bool timeframe = false; /* Should the selection happen based on timeframe? */
bool since_jobid_given = false; /* Was since_jobid given? */
bool until_jobid_given = false; /* Was until_jobid given? */
const int secs_in_day = 86400;
const int secs_in_hour = 3600;
if (!OpenClientDb(ua)) { return true; }
now = (utime_t)time(NULL);
/*
* Determine what cmdline arguments are given.
*/
j = FindArgWithValue(ua, NT_("jobid"));
d = FindArgWithValue(ua, NT_("days"));
h = FindArgWithValue(ua, NT_("hours"));
s = FindArgWithValue(ua, NT_("since_jobid"));
u = FindArgWithValue(ua, NT_("until_jobid"));
if (s > 0) {
since_jobid = str_to_int64(ua->argv[s]);
since_jobid_given = true;
}
if (u > 0) {
until_jobid = str_to_int64(ua->argv[u]);
until_jobid_given = true;
}
if (d > 0 || h > 0) { timeframe = true; }
if (FindArg(ua, NT_("yes")) > 0) { yes = true; }
if (j < 0 && !timeframe && !since_jobid_given) {
ua->SendMsg("Please specify jobid, since_jobid, hours or days\n");
goto bail_out;
}
if (j >= 0 && since_jobid_given) {
ua->SendMsg(
"Please specify either jobid or since_jobid (and optionally "
"until_jobid)\n");
goto bail_out;
}
if (j >= 0 && timeframe) {
ua->SendMsg("Please specify either jobid or timeframe\n");
goto bail_out;
}
if (timeframe || since_jobid_given) {
schedtime = now;
if (d > 0) {
days = str_to_int64(ua->argv[d]);
schedtime = now - secs_in_day * days; /* Days in the past */
}
if (h > 0) {
hours = str_to_int64(ua->argv[h]);
schedtime = now - secs_in_hour * hours; /* Hours in the past */
}
/*
* Job Query Start
*/
bstrutime(dt, sizeof(dt), schedtime);
if (since_jobid_given) {
if (until_jobid_given) {
Mmsg(query,
"SELECT JobId FROM Job WHERE JobStatus = 'f' AND JobId >= %s AND "
"JobId <= %s ORDER BY JobId",
edit_int64(since_jobid, ed1), edit_int64(until_jobid, ed2));
} else {
Mmsg(query,
"SELECT JobId FROM Job WHERE JobStatus = 'f' AND JobId >= %s "
"ORDER BY JobId",
edit_int64(since_jobid, ed1));
}
} else {
Mmsg(query,
"SELECT JobId FROM Job WHERE JobStatus = 'f' AND SchedTime > '%s' "
"ORDER BY JobId",
dt);
}
ua->db->GetQueryDbids(ua->jcr, query, ids);
ua->SendMsg("The following ids were selected for rerun:\n");
for (i = 0; i < ids.num_ids; i++) {
if (i > 0) {
ua->SendMsg(",%d", ids.DBId[i]);
} else {
ua->SendMsg("%d", ids.DBId[i]);
}
}
ua->SendMsg("\n");
if (!yes && (!GetYesno(ua, _("rerun these jobids? (yes/no): ")) ||
!ua->pint32_val)) {
goto bail_out;
}
/*
* Job Query End
*/
/*
* Loop over all selected JobIds.
*/
for (i = 0; i < ids.num_ids; i++) {
JobId = ids.DBId[i];
if (!reRunJob(ua, JobId, yes, now)) { goto bail_out; }
}
} else {
JobId = str_to_int64(ua->argv[j]);
if (!reRunJob(ua, JobId, yes, now)) { goto bail_out; }
}
return true;
bail_out:
return false;
}
/**
* For Backup and Verify Jobs
* run [job=]<job-name> level=<level-name>
*
* For Restore Jobs
* run <job-name>
*
* Returns: 0 on error
* JobId if OK
*
*/
int DoRunCmd(UaContext* ua, const char* cmd)
{
JobControlRecord* jcr = NULL;
RunContext rc;
int status, length;
bool valid_response;
bool do_pool_overrides = true;
if (!OpenClientDb(ua)) { return 0; }
if (!ScanCommandLineArguments(ua, rc)) { return 0; }
if (FindArg(ua, NT_("fdcalled")) > 0) {
jcr->file_bsock = ua->UA_sock->clone();
ua->quit = true;
}
/*
* Create JobControlRecord to run job. NOTE!!! after this point, FreeJcr()
* before returning.
*/
if (!jcr) {
jcr = new_jcr(sizeof(JobControlRecord), DirdFreeJcr);
SetJcrDefaults(jcr, rc.job);
jcr->unlink_bsr = ua->jcr->unlink_bsr; /* copy unlink flag from caller */
ua->jcr->unlink_bsr = false;
}
/*
* Transfer JobIds to new restore Job
*/
if (ua->jcr->JobIds) {
jcr->JobIds = ua->jcr->JobIds;
ua->jcr->JobIds = NULL;
}
/*
* Transfer selected restore tree to new restore Job
*/
if (ua->jcr->restore_tree_root) {
jcr->restore_tree_root = ua->jcr->restore_tree_root;
ua->jcr->restore_tree_root = NULL;
}
try_again:
if (!ResetRestoreContext(ua, jcr, rc)) { goto bail_out; }
/*
* Run without prompting?
*/
if (ua->batch || FindArg(ua, NT_("yes")) > 0) { goto start_job; }
/*
* When doing interactive runs perform the pool level overrides
* early this way the user doesn't get nasty surprisses when
* a level override changes the pool the data will be saved to
* later. We only want to do these overrides once so we use
* a tracking boolean do_pool_overrides to see if we still
* need to do this (e.g. we pass by here multiple times when
* the user interactivly changes options.
*/
if (do_pool_overrides) {
switch (jcr->getJobType()) {
case JT_BACKUP:
if (!jcr->is_JobLevel(L_VIRTUAL_FULL)) { ApplyPoolOverrides(jcr); }
break;
default:
break;
}
do_pool_overrides = false;
}
/*
* Prompt User to see if all run job parameters are correct, and
* allow him to modify them.
*/
if (!DisplayJobParameters(ua, jcr, rc)) { goto bail_out; }
/*
* Prompt User until we have a valid response.
*/
do {
if (!GetCmd(ua, _("OK to run? (yes/mod/no): "))) { goto bail_out; }
/*
* Empty line equals yes, anything other we compare
* the cmdline for the length of the given input unless
* its mod or .mod where we compare only the keyword
* and a space as it can be followed by a full cmdline
* with new cmdline arguments that need to be parsed.
*/
valid_response = false;
length = strlen(ua->cmd);
if (ua->cmd[0] == 0 || bstrncasecmp(ua->cmd, ".mod ", MIN(length, 5)) ||
bstrncasecmp(ua->cmd, "mod ", MIN(length, 4)) ||
bstrncasecmp(ua->cmd, NT_("yes"), length) ||
bstrncasecmp(ua->cmd, _("yes"), length) ||
bstrncasecmp(ua->cmd, NT_("no"), length) ||
bstrncasecmp(ua->cmd, _("no"), length)) {
valid_response = true;
}
if (!valid_response) {
ua->WarningMsg(_("Illegal response %s\n"), ua->cmd);
}
} while (!valid_response);
/*
* See if the .mod or mod has arguments.
*/
if (bstrncasecmp(ua->cmd, ".mod ", 5) ||
(bstrncasecmp(ua->cmd, "mod ", 4) && strlen(ua->cmd) > 6)) {
ParseUaArgs(ua);
rc.mod = true;
if (!ScanCommandLineArguments(ua, rc)) { return 0; }
goto try_again;
}
/*
* Allow the user to modify the settings
*/
status = ModifyJobParameters(ua, jcr, rc);
switch (status) {
case 0:
goto try_again;
case 1:
break;
case -1:
goto bail_out;
}
/*
* For interactive runs we set IgnoreLevelPoolOverrides as we already
* performed the actual overrrides.
*/
jcr->IgnoreLevelPoolOverides = true;
if (ua->cmd[0] == 0 || bstrncasecmp(ua->cmd, NT_("yes"), strlen(ua->cmd)) ||
bstrncasecmp(ua->cmd, _("yes"), strlen(ua->cmd))) {
JobId_t JobId;
Dmsg1(800, "Calling RunJob job=%x\n", jcr->res.job);
start_job:
Dmsg3(100, "JobId=%u using pool %s priority=%d\n", (int)jcr->JobId,
jcr->res.pool->resource_name_, jcr->JobPriority);
Dmsg1(900, "Running a job; its spool_data = %d\n", jcr->spool_data);
JobId = RunJob(jcr);
Dmsg4(100, "JobId=%u NewJobId=%d using pool %s priority=%d\n",
(int)jcr->JobId, JobId, jcr->res.pool->resource_name_,
jcr->JobPriority);
FreeJcr(jcr); /* release jcr */
if (JobId == 0) {
ua->ErrorMsg(_("Job failed.\n"));
} else {
char ed1[50];
ua->send->ObjectStart("run");
ua->send->ObjectKeyValue("jobid", edit_int64(JobId, ed1),
_("Job queued. JobId=%s\n"));
ua->send->ObjectEnd("run");
}
return JobId;
}
bail_out:
ua->SendMsg(_("Job not run.\n"));
FreeJcr(jcr);
return 0; /* do not run */
}
bool RunCmd(UaContext* ua, const char* cmd)
{
return (DoRunCmd(ua, ua->cmd) != 0);
}
int ModifyJobParameters(UaContext* ua, JobControlRecord* jcr, RunContext& rc)
{
int opt;
/*
* At user request modify parameters of job to be run.
*/
if (ua->cmd[0] != 0 && bstrncasecmp(ua->cmd, _("mod"), strlen(ua->cmd))) {
StartPrompt(ua, _("Parameters to modify:\n"));
AddPrompt(ua, _("Level")); /* 0 */
AddPrompt(ua, _("Storage")); /* 1 */
AddPrompt(ua, _("Job")); /* 2 */
AddPrompt(ua, _("FileSet")); /* 3 */
if (jcr->is_JobType(JT_RESTORE)) {
AddPrompt(ua, _("Restore Client")); /* 4 */
} else {
AddPrompt(ua, _("Client")); /* 4 */
}
AddPrompt(ua, _("Backup Format")); /* 5 */
AddPrompt(ua, _("When")); /* 6 */
AddPrompt(ua, _("Priority")); /* 7 */
if (jcr->is_JobType(JT_BACKUP) || jcr->is_JobType(JT_COPY) ||
jcr->is_JobType(JT_MIGRATE) || jcr->is_JobType(JT_VERIFY)) {
AddPrompt(ua, _("Pool")); /* 8 */
if (jcr->is_JobType(JT_MIGRATE) || jcr->is_JobType(JT_COPY) ||
(jcr->is_JobType(JT_BACKUP) &&
jcr->is_JobLevel(L_VIRTUAL_FULL))) { /* NextPool */
AddPrompt(ua, _("NextPool")); /* 9 */
if (jcr->is_JobType(JT_BACKUP)) {
AddPrompt(ua, _("Plugin Options")); /* 10 */
}
} else if (jcr->is_JobType(JT_VERIFY)) {
AddPrompt(ua, _("Verify Job")); /* 9 */
} else if (jcr->is_JobType(JT_BACKUP)) {
AddPrompt(ua, _("Plugin Options")); /* 9 */
}
} else if (jcr->is_JobType(JT_RESTORE)) {
AddPrompt(ua, _("Bootstrap")); /* 8 */
AddPrompt(ua, _("Where")); /* 9 */
AddPrompt(ua, _("File Relocation")); /* 10 */
AddPrompt(ua, _("Replace")); /* 11 */
AddPrompt(ua, _("JobId")); /* 12 */
AddPrompt(ua, _("Plugin Options")); /* 13 */
}
switch (DoPrompt(ua, "", _("Select parameter to modify"), NULL, 0)) {
case 0:
/* Level */
SelectJobLevel(ua, jcr);
switch (jcr->getJobType()) {
case JT_BACKUP:
if (!rc.pool_override && !jcr->is_JobLevel(L_VIRTUAL_FULL)) {
ApplyPoolOverrides(jcr, true);
rc.pool = jcr->res.pool;
rc.level_override = true;
}
break;
default:
break;
}
goto try_again;
case 1:
/* Storage */
rc.store->store = select_storage_resource(ua);
if (rc.store->store) {
PmStrcpy(rc.store->store_source, _("user selection"));
SetRwstorage(jcr, rc.store);
goto try_again;
}
break;
case 2:
/* Job */
rc.job = select_job_resource(ua);
if (rc.job) {
jcr->res.job = rc.job;
SetJcrDefaults(jcr, rc.job);
goto try_again;
}
break;
case 3:
/* FileSet */
rc.fileset = select_fileset_resource(ua);
if (rc.fileset) {
jcr->res.fileset = rc.fileset;
goto try_again;
}
break;
case 4:
/* Client */
rc.client = select_client_resource(ua);
if (rc.client) {
jcr->res.client = rc.client;
goto try_again;
}
break;
case 5:
/* Backup Format */
if (GetCmd(ua, _("Please enter Backup Format: "))) {
if (jcr->backup_format) {
free(jcr->backup_format);
jcr->backup_format = NULL;
}
jcr->backup_format = strdup(ua->cmd);
goto try_again;
}
break;
case 6:
/* When */
if (GetCmd(ua, _("Please enter desired start time as YYYY-MM-DD "
"HH:MM:SS (return for now): "))) {
if (ua->cmd[0] == 0) {
jcr->sched_time = time(NULL);
} else {
jcr->sched_time = StrToUtime(ua->cmd);
if (jcr->sched_time == 0) {
ua->SendMsg(_("Invalid time, using current time.\n"));
jcr->sched_time = time(NULL);
}
}
goto try_again;
}
break;
case 7:
/* Priority */
if (GetPint(ua, _("Enter new Priority: "))) {
if (!ua->pint32_val) {
ua->SendMsg(_("Priority must be a positive integer.\n"));
} else {
jcr->JobPriority = ua->pint32_val;
}
goto try_again;
}
break;
case 8:
/* Pool or Bootstrap depending on JobType */
if (jcr->is_JobType(JT_BACKUP) || jcr->is_JobType(JT_COPY) ||
jcr->is_JobType(JT_MIGRATE) ||
jcr->is_JobType(JT_VERIFY)) { /* Pool */
rc.pool = select_pool_resource(ua);
if (rc.pool) {
jcr->res.pool = rc.pool;
rc.level_override = false;
rc.pool_override = true;
Dmsg1(100, "Set new pool=%s\n", jcr->res.pool->resource_name_);
goto try_again;
}
} else {
/* Bootstrap */
if (GetCmd(ua, _("Please enter the Bootstrap file name: "))) {
if (jcr->RestoreBootstrap) {
free(jcr->RestoreBootstrap);
jcr->RestoreBootstrap = NULL;
}
if (ua->cmd[0] != 0) {
FILE* fd;
jcr->RestoreBootstrap = strdup(ua->cmd);
fd = fopen(jcr->RestoreBootstrap, "rb");
if (!fd) {
BErrNo be;
ua->SendMsg(_("Warning cannot open %s: ERR=%s\n"),
jcr->RestoreBootstrap, be.bstrerror());
free(jcr->RestoreBootstrap);
jcr->RestoreBootstrap = NULL;
} else {
fclose(fd);
}
}
goto try_again;
}
}
break;
case 9:
/* NextPool/Verify Job/Where/Plugin Options depending on JobType */
if (jcr->is_JobType(JT_MIGRATE) || jcr->is_JobType(JT_COPY) ||
(jcr->is_JobType(JT_BACKUP) &&
jcr->is_JobLevel(L_VIRTUAL_FULL))) { /* NextPool */
rc.next_pool = select_pool_resource(ua);
if (rc.next_pool) {
jcr->res.next_pool = rc.next_pool;
Dmsg1(100, "Set new next_pool=%s\n",
jcr->res.next_pool->resource_name_);
goto try_again;
}
} else if (jcr->is_JobType(JT_VERIFY)) { /* Verify Job */
rc.verify_job = select_job_resource(ua);
if (rc.verify_job) { jcr->res.verify_job = rc.verify_job; }
goto try_again;
} else if (jcr->is_JobType(JT_RESTORE)) { /* Where */
if (GetCmd(ua, _("Please enter the full path prefix for restore (/ "
"for none): "))) {
if (jcr->RegexWhere) { /* cannot use regexwhere and where */
free(jcr->RegexWhere);
jcr->RegexWhere = NULL;
}
if (jcr->where) {
free(jcr->where);
jcr->where = NULL;
}
if (IsPathSeparator(ua->cmd[0]) && ua->cmd[1] == '\0') {
ua->cmd[0] = 0;
}
jcr->where = strdup(ua->cmd);
goto try_again;
}
} else { /* Plugin Options */
if (GetCmd(ua, _("Please enter Plugin Options string: "))) {
if (jcr->plugin_options) {
free(jcr->plugin_options);
jcr->plugin_options = NULL;
}
jcr->plugin_options = strdup(ua->cmd);
goto try_again;
}
}
break;
case 10:
/* File relocation/Plugin Options depending on JobType */
if (jcr->is_JobType(JT_RESTORE)) {
SelectWhereRegexp(ua, jcr);
goto try_again;
} else if (jcr->is_JobType(JT_BACKUP)) {
if (GetCmd(ua, _("Please enter Plugin Options string: "))) {
if (jcr->plugin_options) {
free(jcr->plugin_options);
jcr->plugin_options = NULL;
}
jcr->plugin_options = strdup(ua->cmd);
goto try_again;
}
}
break;
case 11:
/* Replace */
StartPrompt(ua, _("Replace:\n"));
for (int i = 0; ReplaceOptions[i].name; i++) {
AddPrompt(ua, ReplaceOptions[i].name);
}
opt = DoPrompt(ua, "", _("Select replace option"), NULL, 0);
if (opt >= 0) {
rc.replace = ReplaceOptions[opt].name;
jcr->replace = ReplaceOptions[opt].token;
}
goto try_again;
case 12:
/* JobId */
rc.jid = NULL; /* force reprompt */
jcr->RestoreJobId = 0;
if (jcr->RestoreBootstrap) {
ua->SendMsg(
_("You must set the bootstrap file to NULL to be able to specify "
"a JobId.\n"));
}
goto try_again;
case 13:
/* Plugin Options */
if (GetCmd(ua, _("Please enter Plugin Options string: "))) {
if (jcr->plugin_options) {
free(jcr->plugin_options);
jcr->plugin_options = NULL;
}
jcr->plugin_options = strdup(ua->cmd);
goto try_again;
}
break;
case -1: /* error or cancel */
goto bail_out;
default:
goto try_again;
}
goto bail_out;
}
return 1;
bail_out:
return -1;
try_again:
return 0;
}
/**
* Reset the restore context.
* This subroutine can be called multiple times, so it must keep any prior
* settings.
*/
static bool ResetRestoreContext(UaContext* ua,
JobControlRecord* jcr,
RunContext& rc)
{
jcr->res.verify_job = rc.verify_job;
jcr->res.previous_job = rc.previous_job;
jcr->res.pool = rc.pool;
jcr->res.next_pool = rc.next_pool;
/*
* See if an explicit pool override was performed.
* If so set the pool_source to command line and
* set the IgnoreLevelPoolOverides so any level Pool
* overrides are ignored.
*/
if (rc.pool_name) {
PmStrcpy(jcr->res.pool_source, _("command line"));
jcr->IgnoreLevelPoolOverides = true;
} else if (!rc.level_override && jcr->res.pool != jcr->res.job->pool) {
PmStrcpy(jcr->res.pool_source, _("user input"));
}
SetRwstorage(jcr, rc.store);
if (rc.next_pool_name) {
PmStrcpy(jcr->res.npool_source, _("command line"));
jcr->res.run_next_pool_override = true;
} else if (jcr->res.next_pool != jcr->res.pool->NextPool) {
PmStrcpy(jcr->res.npool_source, _("user input"));
jcr->res.run_next_pool_override = true;
}
jcr->res.client = rc.client;
if (jcr->res.client) {
PmStrcpy(jcr->client_name, rc.client->resource_name_);
}
jcr->res.fileset = rc.fileset;
jcr->ExpectedFiles = rc.files;
if (rc.catalog) {
jcr->res.catalog = rc.catalog;
PmStrcpy(jcr->res.catalog_source, _("user input"));
}
PmStrcpy(jcr->comment, rc.comment);
if (rc.where) {
if (jcr->where) { free(jcr->where); }
jcr->where = strdup(rc.where);
rc.where = NULL;
}
if (rc.regexwhere) {
if (jcr->RegexWhere) { free(jcr->RegexWhere); }
jcr->RegexWhere = strdup(rc.regexwhere);
rc.regexwhere = NULL;
}
if (rc.when) {
jcr->sched_time = StrToUtime(rc.when);
if (jcr->sched_time == 0) {
ua->SendMsg(_("Invalid time, using current time.\n"));
jcr->sched_time = time(NULL);
}
rc.when = NULL;
}
if (rc.bootstrap) {
if (jcr->RestoreBootstrap) { free(jcr->RestoreBootstrap); }
jcr->RestoreBootstrap = strdup(rc.bootstrap);
rc.bootstrap = NULL;
}
if (rc.plugin_options) {
if (jcr->plugin_options) { free(jcr->plugin_options); }
jcr->plugin_options = strdup(rc.plugin_options);
rc.plugin_options = NULL;
}
if (rc.replace) {
jcr->replace = 0;
for (int i = 0; ReplaceOptions[i].name; i++) {
if (Bstrcasecmp(rc.replace, ReplaceOptions[i].name)) {
jcr->replace = ReplaceOptions[i].token;
}
}
if (!jcr->replace) {
ua->SendMsg(_("Invalid replace option: %s\n"), rc.replace);
return false;
}
} else if (rc.job->replace) {
jcr->replace = rc.job->replace;
} else {
jcr->replace = REPLACE_ALWAYS;
}
rc.replace = NULL;
if (rc.Priority) {
jcr->JobPriority = rc.Priority;
rc.Priority = 0;
}
if (rc.since) {
if (!jcr->stime) { jcr->stime = GetPoolMemory(PM_MESSAGE); }
PmStrcpy(jcr->stime, rc.since);
rc.since = NULL;
}
if (rc.cloned) {
jcr->cloned = rc.cloned;
rc.cloned = false;
}
/*
* If pool changed, update migration write storage
*/
if (jcr->is_JobType(JT_MIGRATE) || jcr->is_JobType(JT_COPY) ||
(jcr->is_JobType(JT_BACKUP) && jcr->is_JobLevel(L_VIRTUAL_FULL))) {
if (!SetMigrationWstorage(jcr, rc.pool, rc.next_pool,
_("Storage from Run NextPool override"))) {
return false;
}
}
rc.replace = ReplaceOptions[0].name;
for (int i = 0; ReplaceOptions[i].name; i++) {
if (ReplaceOptions[i].token == jcr->replace) {
rc.replace = ReplaceOptions[i].name;
}
}
if (rc.level_name) {
if (!GetLevelFromName(jcr, rc.level_name)) {
ua->SendMsg(_("Level \"%s\" not valid.\n"), rc.level_name);
return false;
}
rc.level_name = NULL;
}
if (rc.jid) {
if (jcr->is_JobType(JT_BACKUP) && jcr->is_JobLevel(L_VIRTUAL_FULL)) {
if (!jcr->vf_jobids) { jcr->vf_jobids = GetPoolMemory(PM_MESSAGE); }
PmStrcpy(jcr->vf_jobids, rc.jid);
} else {
/*
* Note, this is also MigrateJobId and a VerifyJobId
*/
jcr->RestoreJobId = str_to_int64(rc.jid);
}
rc.jid = NULL;
}
if (rc.backup_format) {
if (jcr->backup_format) { free(jcr->backup_format); }
jcr->backup_format = strdup(rc.backup_format);
rc.backup_format = NULL;
}
/*
* Some options are not available through the menu
* TODO: Add an advanced menu?
*/
if (rc.spool_data_set) { jcr->spool_data = rc.spool_data; }
if (rc.accurate_set) { jcr->accurate = rc.accurate; }