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/jcr_private.h"
36 #include "dird/storage.h"
37
38 namespace directordaemon {
39
40 static const int debuglevel = 100;
41
DoArchiveInit(JobControlRecord * jcr)42 bool DoArchiveInit(JobControlRecord* jcr)
43 {
44 FreeRstorage(jcr);
45 if (!AllowDuplicateJob(jcr)) { return false; }
46
47 return true;
48 }
49
50 /**
51 * Returns: false on failure
52 * true on success
53 */
DoArchive(JobControlRecord * jcr)54 bool DoArchive(JobControlRecord* jcr)
55 {
56 jcr->impl->jr.JobId = jcr->JobId;
57
58 jcr->impl->fname = (char*)GetPoolMemory(PM_FNAME);
59
60 /*
61 * Print Job Start message
62 */
63 Jmsg(jcr, M_INFO, 0, _("Start Archive JobId %d, Job=%s\n"), jcr->JobId,
64 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->impl->jr)) {
87 Jmsg(jcr, M_WARNING, 0,
88 _("Error getting Job record for Job report: ERR=%s"),
89 jcr->db->strerror());
90 jcr->setJobStatus(JS_ErrorTerminated);
91 }
92
93 msg_type = M_INFO; /* by default INFO message */
94 switch (jcr->JobStatus) {
95 case JS_Terminated:
96 TermMsg = _("Archive OK");
97 break;
98 case JS_FatalError:
99 case JS_ErrorTerminated:
100 TermMsg = _("*** Archive Error ***");
101 msg_type = M_ERROR; /* Generate error message */
102 break;
103 case JS_Canceled:
104 TermMsg = _("Archive Canceled");
105 break;
106 default:
107 TermMsg = term_code;
108 sprintf(term_code, _("Inappropriate term code: %c\n"), jcr->JobStatus);
109 break;
110 }
111
112 bstrftimes(schedt, sizeof(schedt), jcr->impl->jr.SchedTime);
113 bstrftimes(sdt, sizeof(sdt), jcr->impl->jr.StartTime);
114 bstrftimes(edt, sizeof(edt), jcr->impl->jr.EndTime);
115
116 Jmsg(jcr, msg_type, 0,
117 _("BAREOS %s (%s): %s\n"
118 " JobId: %d\n"
119 " Job: %s\n"
120 " Scheduled time: %s\n"
121 " Start time: %s\n"
122 " End time: %s\n"
123 " Bareos binary info: %s\n"
124 " Termination: %s\n\n"),
125 kBareosVersionStrings.Full, kBareosVersionStrings.ShortDate, edt,
126 jcr->impl->jr.JobId, jcr->impl->jr.Job, schedt, sdt, edt,
127 kBareosVersionStrings.JoblogMessage, TermMsg);
128
129 Dmsg0(debuglevel, "Leave ArchiveCleanup()\n");
130 }
131 } /* namespace directordaemon */
132