]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/admin.c
Update version
[bacula/bacula] / bacula / src / dird / admin.c
1 /*
2  *
3  *   Bacula Director -- admin.c -- responsible for doing admin jobs
4  *
5  *     Kern Sibbald, May MMIII
6  *
7  *  Basic tasks done here:
8  *     Display the job report.
9  *
10  *   Version $Id$
11  */
12
13 /*
14    Copyright (C) 2000-2004 Kern Sibbald and John Walker
15
16    This program is free software; you can redistribute it and/or
17    modify it under the terms of the GNU General Public License as
18    published by the Free Software Foundation; either version 2 of
19    the License, or (at your option) any later version.
20
21    This program is distributed in the hope that it will be useful,
22    but WITHOUT ANY WARRANTY; without even the implied warranty of
23    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24    General Public License for more details.
25
26    You should have received a copy of the GNU General Public
27    License along with this program; if not, write to the Free
28    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
29    MA 02111-1307, USA.
30
31  */
32
33 #include "bacula.h"
34 #include "dird.h"
35 #include "ua.h"
36
37
38 bool do_admin_init(JCR *jcr)
39 {
40    return true;
41 }
42
43 /*
44  *  Returns:  false on failure
45  *            true  on success
46  */
47 bool do_admin(JCR *jcr)
48 {
49
50    jcr->jr.JobId = jcr->JobId;
51
52    jcr->fname = (char *)get_pool_memory(PM_FNAME);
53
54    /* Print Job Start message */
55    Jmsg(jcr, M_INFO, 0, _("Start Admin JobId %d, Job=%s\n"),
56         jcr->JobId, jcr->Job);
57
58    set_jcr_job_status(jcr, JS_Running);
59    admin_cleanup(jcr, JS_Terminated);
60    return true;
61 }
62
63
64 /*
65  * Release resources allocated during backup.
66  */
67 void admin_cleanup(JCR *jcr, int TermCode)
68 {
69    char sdt[50], edt[50];
70    char term_code[100];
71    const char *term_msg;
72    int msg_type;
73    MEDIA_DBR mr;
74
75    Dmsg0(100, "Enter backup_cleanup()\n");
76    memset(&mr, 0, sizeof(mr));
77    set_jcr_job_status(jcr, TermCode);
78
79    update_job_end_record(jcr);        /* update database */
80
81    if (!db_get_job_record(jcr, jcr->db, &jcr->jr)) {
82       Jmsg(jcr, M_WARNING, 0, _("Error getting job record for stats: %s"),
83          db_strerror(jcr->db));
84       set_jcr_job_status(jcr, JS_ErrorTerminated);
85    }
86
87    msg_type = M_INFO;                 /* by default INFO message */
88    switch (jcr->JobStatus) {
89    case JS_Terminated:
90       term_msg = _("Admin OK");
91       break;
92    case JS_FatalError:
93    case JS_ErrorTerminated:
94       term_msg = _("*** Admin Error ***");
95       msg_type = M_ERROR;          /* Generate error message */
96       break;
97    case JS_Canceled:
98       term_msg = _("Admin Canceled");
99       break;
100    default:
101       term_msg = term_code;
102       sprintf(term_code, _("Inappropriate term code: %c\n"), jcr->JobStatus);
103       break;
104    }
105    bstrftime(sdt, sizeof(sdt), jcr->jr.StartTime);
106    bstrftime(edt, sizeof(edt), jcr->jr.EndTime);
107
108    Jmsg(jcr, msg_type, 0, _("Bacula " VERSION " (" LSMDATE "): %s\n"
109 "  JobId:                  %d\n"
110 "  Job:                    %s\n"
111 "  Start time:             %s\n"
112 "  End time:               %s\n"
113 "  Termination:            %s\n\n"),
114         edt,
115         jcr->jr.JobId,
116         jcr->jr.Job,
117         sdt,
118         edt,
119         term_msg);
120
121    Dmsg0(100, "Leave admin_cleanup()\n");
122 }