1 /*
2 BAREOS® - Backup Archiving REcovery Open Sourced
3
4 Copyright (C) 2016-2019 Bareos GmbH & Co. KG
5
6 This program is Free Software; you can redistribute it and/or
7 modify it under the terms of version three of the GNU Affero General Public
8 License as published by the Free Software Foundation and included
9 in the file LICENSE.
10
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Affero General Public License for more details.
15
16 You should have received a copy of the GNU Affero General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301, USA.
20 */
21 /*
22 * Marco van Wieringen, June 2016
23 */
24
25 /**
26 * @file
27 * responsible for doing archive jobs
28 *
29 * based on admin.c
30 */
31 #include "include/bareos.h"
32 #include "dird.h"
33 #include "dird/archive.h"
34 #include "dird/job.h"
35 #include "dird/storage.h"
36
37 namespace directordaemon {
38
39 static const int debuglevel = 100;
40
DoArchiveInit(JobControlRecord * jcr)41 bool DoArchiveInit(JobControlRecord *jcr)
42 {
43 FreeRstorage(jcr);
44 if (!AllowDuplicateJob(jcr)) {
45 return false;
46 }
47
48 return true;
49 }
50
51 /**
52 * Returns: false on failure
53 * true on success
54 */
DoArchive(JobControlRecord * jcr)55 bool DoArchive(JobControlRecord *jcr)
56 {
57 jcr->jr.JobId = jcr->JobId;
58
59 jcr->fname = (char *)GetPoolMemory(PM_FNAME);
60
61 /*
62 * Print Job Start message
63 */
64 Jmsg(jcr, M_INFO, 0, _("Start Archive JobId %d, Job=%s\n"), jcr->JobId, jcr->Job);
65
66 jcr->setJobStatus(JS_Running);
67 ArchiveCleanup(jcr, JS_Terminated);
68
69 return true;
70 }
71
72 /**
73 * Release resources allocated during archive.
74 */
ArchiveCleanup(JobControlRecord * jcr,int TermCode)75 void ArchiveCleanup(JobControlRecord *jcr, int TermCode)
76 {
77 char sdt[50], edt[50], schedt[50];
78 char term_code[100];
79 const char *TermMsg;
80 int msg_type;
81
82 Dmsg0(debuglevel, "Enter ArchiveCleanup()\n");
83
84 UpdateJobEnd(jcr, TermCode);
85
86 if (!jcr->db->GetJobRecord(jcr, &jcr->jr)) {
87 Jmsg(jcr, M_WARNING, 0, _("Error getting Job record for Job report: ERR=%s"), jcr->db->strerror());
88 jcr->setJobStatus(JS_ErrorTerminated);
89 }
90
91 msg_type = M_INFO; /* by default INFO message */
92 switch (jcr->JobStatus) {
93 case JS_Terminated:
94 TermMsg = _("Archive OK");
95 break;
96 case JS_FatalError:
97 case JS_ErrorTerminated:
98 TermMsg = _("*** Archive Error ***");
99 msg_type = M_ERROR; /* Generate error message */
100 break;
101 case JS_Canceled:
102 TermMsg = _("Archive Canceled");
103 break;
104 default:
105 TermMsg = term_code;
106 sprintf(term_code, _("Inappropriate term code: %c\n"), jcr->JobStatus);
107 break;
108 }
109
110 bstrftimes(schedt, sizeof(schedt), jcr->jr.SchedTime);
111 bstrftimes(sdt, sizeof(sdt), jcr->jr.StartTime);
112 bstrftimes(edt, sizeof(edt), jcr->jr.EndTime);
113
114 Jmsg(jcr, msg_type, 0, _("BAREOS " VERSION " (" LSMDATE "): %s\n"
115 " JobId: %d\n"
116 " Job: %s\n"
117 " Scheduled time: %s\n"
118 " Start time: %s\n"
119 " End time: %s\n"
120 " Bareos binary info: %s\n"
121 " Termination: %s\n\n"),
122 edt,
123 jcr->jr.JobId,
124 jcr->jr.Job,
125 schedt,
126 sdt,
127 edt,
128 BAREOS_JOBLOG_MESSAGE,
129 TermMsg);
130
131 Dmsg0(debuglevel, "Leave ArchiveCleanup()\n");
132 }
133 } /* namespace directordaemon */
134