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