]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/admin.c
c056bcee9797fdd8f875a490be204001db359396
[bacula/bacula] / bacula / src / dird / admin.c
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2015 Kern Sibbald
5    Copyright (C) 2003-2014 Free Software Foundation Europe e.V.
6
7    The original author of Bacula is Kern Sibbald, with contributions
8    from many others, a complete list can be found in the file AUTHORS.
9
10    You may use this file and others of this release according to the
11    license defined in the LICENSE file, which includes the Affero General
12    Public License, v3.0 ("AGPLv3") and some additional permissions and
13    terms pursuant to its AGPLv3 Section 7.
14
15    This notice must be preserved when any source code is 
16    conveyed and/or propagated.
17
18    Bacula(R) is a registered trademark of Kern Sibbald.
19 */
20 /*
21  *
22  *   Bacula Director -- admin.c -- responsible for doing admin jobs
23  *
24  *     Kern Sibbald, May MMIII
25  *
26  *  Basic tasks done here:
27  *     Display the job report.
28  *
29  */
30
31 #include "bacula.h"
32 #include "dird.h"
33 #include "ua.h"
34
35
36 bool do_admin_init(JCR *jcr)
37 {
38    free_rstorage(jcr);
39    if (!allow_duplicate_job(jcr)) {
40       return false;
41    }
42    return true;
43 }
44
45 /*
46  *  Returns:  false on failure
47  *            true  on success
48  */
49 bool do_admin(JCR *jcr)
50 {
51
52    jcr->jr.JobId = jcr->JobId;
53
54    jcr->fname = (char *)get_pool_memory(PM_FNAME);
55
56    /* Print Job Start message */
57    Jmsg(jcr, M_INFO, 0, _("Start Admin JobId %d, Job=%s\n"),
58         jcr->JobId, jcr->Job);
59
60    jcr->setJobStatus(JS_Running);
61    admin_cleanup(jcr, JS_Terminated);
62    return true;
63 }
64
65
66 /*
67  * Release resources allocated during backup.
68  */
69 void admin_cleanup(JCR *jcr, int TermCode)
70 {
71    char sdt[50], edt[50], schedt[50];
72    char term_code[100];
73    const char *term_msg;
74    int msg_type;
75    MEDIA_DBR mr;
76
77    Dmsg0(100, "Enter backup_cleanup()\n");
78
79    update_job_end(jcr, TermCode);
80
81    if (!db_get_job_record(jcr, jcr->db, &jcr->jr)) {
82       Jmsg(jcr, M_WARNING, 0, _("Error getting Job record for Job report: ERR=%s"),
83          db_strerror(jcr->db));
84       jcr->setJobStatus(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    bstrftimes(schedt, sizeof(schedt), jcr->jr.SchedTime);
106    bstrftimes(sdt, sizeof(sdt), jcr->jr.StartTime);
107    bstrftimes(edt, sizeof(edt), jcr->jr.EndTime);
108
109
110    Jmsg(jcr, msg_type, 0, _("Bacula " VERSION " (" LSMDATE "): %s\n"
111 "  JobId:                  %d\n"
112 "  Job:                    %s\n"
113 "  Scheduled time:         %s\n"
114 "  Start time:             %s\n"
115 "  End time:               %s\n"
116 "  Termination:            %s\n\n"),
117         edt,
118         jcr->jr.JobId,
119         jcr->jr.Job,
120         schedt,
121         sdt,
122         edt,
123         term_msg);
124
125    Dmsg0(100, "Leave admin_cleanup()\n");
126 }