]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/admin.c
746f629b4fa52834215f9702ea18cc057f2b3d8a
[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    jcr->jr.StartTime = jcr->start_time;
52    if (!db_update_job_start_record(jcr, jcr->db, &jcr->jr)) {
53       Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
54       goto bail_out;
55    }
56
57    jcr->fname = (char *)get_pool_memory(PM_FNAME);
58
59    /* Print Job Start message */
60    Jmsg(jcr, M_INFO, 0, _("Start Admin JobId %d, Job=%s\n"),
61         jcr->JobId, jcr->Job);
62
63    set_jcr_job_status(jcr, JS_Running);
64    admin_cleanup(jcr, JS_Terminated);
65    return 0;
66     
67 bail_out:
68    admin_cleanup(jcr, JS_ErrorTerminated);
69    return 0;
70 }
71
72 /*
73  * Release resources allocated during backup.
74  */
75 static void admin_cleanup(JCR *jcr, int TermCode)
76 {
77    char sdt[50], edt[50];
78    char term_code[100];
79    const char *term_msg;
80    int msg_type;
81    MEDIA_DBR mr;
82
83    Dmsg0(100, "Enter backup_cleanup()\n");
84    memset(&mr, 0, sizeof(mr));
85    set_jcr_job_status(jcr, TermCode);
86
87    update_job_end_record(jcr);        /* update database */
88    
89    if (!db_get_job_record(jcr, jcr->db, &jcr->jr)) {
90       Jmsg(jcr, M_WARNING, 0, _("Error getting job record for stats: %s"), 
91          db_strerror(jcr->db));
92       set_jcr_job_status(jcr, 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 }