]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/admin.c
ebl Fix bug on RunBefore
[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) 2003-2006 Kern Sibbald
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
18    version 2 as amended with additional clauses defined in the
19    file LICENSE in the main source directory.
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 
24    the file LICENSE for additional details.
25
26  */
27
28 #include "bacula.h"
29 #include "dird.h"
30 #include "ua.h"
31
32
33 bool do_admin_init(JCR *jcr)
34 {
35    free_rstorage(jcr);
36    return true;
37 }
38
39 /*
40  *  Returns:  false on failure
41  *            true  on success
42  */
43 bool do_admin(JCR *jcr)
44 {
45
46    jcr->jr.JobId = jcr->JobId;
47
48    jcr->fname = (char *)get_pool_memory(PM_FNAME);
49
50    /* Print Job Start message */
51    Jmsg(jcr, M_INFO, 0, _("Start Admin JobId %d, Job=%s\n"),
52         jcr->JobId, jcr->Job);
53
54    set_jcr_job_status(jcr, JS_Running);
55    admin_cleanup(jcr, JS_Terminated);
56    return true;
57 }
58
59
60 /*
61  * Release resources allocated during backup.
62  */
63 void admin_cleanup(JCR *jcr, int TermCode)
64 {
65    char sdt[50], edt[50];
66    char term_code[100];
67    const char *term_msg;
68    int msg_type;
69    MEDIA_DBR mr;
70
71    Dmsg0(100, "Enter backup_cleanup()\n");
72    memset(&mr, 0, sizeof(mr));
73    set_jcr_job_status(jcr, TermCode);
74
75    update_job_end_record(jcr);        /* update database */
76
77    if (!db_get_job_record(jcr, jcr->db, &jcr->jr)) {
78       Jmsg(jcr, M_WARNING, 0, _("Error getting job record for stats: %s"),
79          db_strerror(jcr->db));
80       set_jcr_job_status(jcr, JS_ErrorTerminated);
81    }
82
83    msg_type = M_INFO;                 /* by default INFO message */
84    switch (jcr->JobStatus) {
85    case JS_Terminated:
86       term_msg = _("Admin OK");
87       break;
88    case JS_FatalError:
89    case JS_ErrorTerminated:
90       term_msg = _("*** Admin Error ***");
91       msg_type = M_ERROR;          /* Generate error message */
92       break;
93    case JS_Canceled:
94       term_msg = _("Admin Canceled");
95       break;
96    default:
97       term_msg = term_code;
98       sprintf(term_code, _("Inappropriate term code: %c\n"), jcr->JobStatus);
99       break;
100    }
101    bstrftime(sdt, sizeof(sdt), jcr->jr.StartTime);
102    bstrftime(edt, sizeof(edt), jcr->jr.EndTime);
103
104    Jmsg(jcr, msg_type, 0, _("Bacula " VERSION " (" LSMDATE "): %s\n"
105 "  JobId:                  %d\n"
106 "  Job:                    %s\n"
107 "  Start time:             %s\n"
108 "  End time:               %s\n"
109 "  Termination:            %s\n\n"),
110         edt,
111         jcr->jr.JobId,
112         jcr->jr.Job,
113         sdt,
114         edt,
115         term_msg);
116
117    Dmsg0(100, "Leave admin_cleanup()\n");
118 }