]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/admin.c
More definitive fix for update slots bug
[bacula/bacula] / bacula / src / dird / admin.c
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2003-2012 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version three of the GNU Affero General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU Affero General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of Kern Sibbald.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*
29  *
30  *   Bacula Director -- admin.c -- responsible for doing admin jobs
31  *
32  *     Kern Sibbald, May MMIII
33  *
34  *  Basic tasks done here:
35  *     Display the job report.
36  *
37  */
38
39 #include "bacula.h"
40 #include "dird.h"
41 #include "ua.h"
42
43
44 bool do_admin_init(JCR *jcr)
45 {
46    free_rstorage(jcr);
47    if (!allow_duplicate_job(jcr)) {
48       return false;
49    }
50    return true;
51 }
52
53 /*
54  *  Returns:  false on failure
55  *            true  on success
56  */
57 bool do_admin(JCR *jcr)
58 {
59
60    jcr->jr.JobId = jcr->JobId;
61
62    jcr->fname = (char *)get_pool_memory(PM_FNAME);
63
64    /* Print Job Start message */
65    Jmsg(jcr, M_INFO, 0, _("Start Admin JobId %d, Job=%s\n"),
66         jcr->JobId, jcr->Job);
67
68    jcr->setJobStatus(JS_Running);
69    admin_cleanup(jcr, JS_Terminated);
70    return true;
71 }
72
73
74 /*
75  * Release resources allocated during backup.
76  */
77 void admin_cleanup(JCR *jcr, int TermCode)
78 {
79    char sdt[50], edt[50];
80    char term_code[100];
81    const char *term_msg;
82    int msg_type;
83    MEDIA_DBR mr;
84
85    Dmsg0(100, "Enter backup_cleanup()\n");
86
87    update_job_end(jcr, TermCode);
88
89    if (!db_get_job_record(jcr, jcr->db, &jcr->jr)) {
90       Jmsg(jcr, M_WARNING, 0, _("Error getting Job record for Job report: ERR=%s"),
91          db_strerror(jcr->db));
92       jcr->setJobStatus(JS_ErrorTerminated);
93    }
94
95    msg_type = M_INFO;                 /* by default INFO message */
96    switch (jcr->JobStatus) {
97    case JS_Terminated:
98       term_msg = _("Admin OK");
99       break;
100    case JS_FatalError:
101    case JS_ErrorTerminated:
102       term_msg = _("*** Admin Error ***");
103       msg_type = M_ERROR;          /* Generate error message */
104       break;
105    case JS_Canceled:
106       term_msg = _("Admin Canceled");
107       break;
108    default:
109       term_msg = term_code;
110       sprintf(term_code, _("Inappropriate term code: %c\n"), jcr->JobStatus);
111       break;
112    }
113    bstrftime(sdt, sizeof(sdt), jcr->jr.StartTime);
114    bstrftime(edt, sizeof(edt), jcr->jr.EndTime);
115
116    Jmsg(jcr, msg_type, 0, _("Bacula " VERSION " (" LSMDATE "): %s\n"
117 "  JobId:                  %d\n"
118 "  Job:                    %s\n"
119 "  Start time:             %s\n"
120 "  End time:               %s\n"
121 "  Termination:            %s\n\n"),
122         edt,
123         jcr->jr.JobId,
124         jcr->jr.Job,
125         sdt,
126         edt,
127         term_msg);
128
129    Dmsg0(100, "Leave admin_cleanup()\n");
130 }