]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/admin.c
Apply Preben 'Peppe' Guldberg <peppe@wielders.org>
[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 /* Forward referenced functions */
39 static void admin_cleanup(JCR *jcr, int TermCode);
40
41 /* External functions */
42
43 /*
44  *  Returns:  0 on failure
45  *            1 on success
46  */
47 int 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 0;
61 }
62
63 /*
64  * Release resources allocated during backup.
65  */
66 static void admin_cleanup(JCR *jcr, int TermCode)
67 {
68    char sdt[50], edt[50];
69    char term_code[100];
70    const char *term_msg;
71    int msg_type;
72    MEDIA_DBR mr;
73
74    Dmsg0(100, "Enter backup_cleanup()\n");
75    memset(&mr, 0, sizeof(mr));
76    set_jcr_job_status(jcr, TermCode);
77
78    update_job_end_record(jcr);        /* update database */
79
80    if (!db_get_job_record(jcr, jcr->db, &jcr->jr)) {
81       Jmsg(jcr, M_WARNING, 0, _("Error getting job record for stats: %s"),
82          db_strerror(jcr->db));
83       set_jcr_job_status(jcr, JS_ErrorTerminated);
84    }
85
86    msg_type = M_INFO;                 /* by default INFO message */
87    switch (jcr->JobStatus) {
88    case JS_Terminated:
89       term_msg = _("Admin OK");
90       break;
91    case JS_FatalError:
92    case JS_ErrorTerminated:
93       term_msg = _("*** Admin Error ***");
94       msg_type = M_ERROR;          /* Generate error message */
95       break;
96    case JS_Canceled:
97       term_msg = _("Admin Canceled");
98       break;
99    default:
100       term_msg = term_code;
101       sprintf(term_code, _("Inappropriate term code: %c\n"), jcr->JobStatus);
102       break;
103    }
104    bstrftime(sdt, sizeof(sdt), jcr->jr.StartTime);
105    bstrftime(edt, sizeof(edt), jcr->jr.EndTime);
106
107    Jmsg(jcr, msg_type, 0, _("Bacula " VERSION " (" LSMDATE "): %s\n"
108 "  JobId:                  %d\n"
109 "  Job:                    %s\n"
110 "  Start time:             %s\n"
111 "  End time:               %s\n"
112 "  Termination:            %s\n\n"),
113         edt,
114         jcr->jr.JobId,
115         jcr->jr.Job,
116         sdt,
117         edt,
118         term_msg);
119
120    Dmsg0(100, "Leave admin_cleanup()\n");
121 }