]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/admin.c
Simplify the code path in migration and copy jobs
[bacula/bacula] / bacula / src / dird / admin.c
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2003-2007 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version three of the GNU Affero General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU Affero General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of Kern Sibbald.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*
29  *
30  *   Bacula Director -- admin.c -- responsible for doing admin jobs
31  *
32  *     Kern Sibbald, May MMIII
33  *
34  *  Basic tasks done here:
35  *     Display the job report.
36  *
37  *   Version $Id$
38  */
39
40 #include "bacula.h"
41 #include "dird.h"
42 #include "ua.h"
43
44
45 bool do_admin_init(JCR *jcr)
46 {
47    free_rstorage(jcr);
48    if (!allow_duplicate_job(jcr)) {
49       return false;
50    }
51    return true;
52 }
53
54 /*
55  *  Returns:  false on failure
56  *            true  on success
57  */
58 bool do_admin(JCR *jcr)
59 {
60
61    jcr->jr.JobId = jcr->JobId;
62
63    jcr->fname = (char *)get_pool_memory(PM_FNAME);
64
65    /* Print Job Start message */
66    Jmsg(jcr, M_INFO, 0, _("Start Admin JobId %d, Job=%s\n"),
67         jcr->JobId, jcr->Job);
68
69    jcr->setJobStatus(JS_Running);
70    admin_cleanup(jcr, JS_Terminated);
71    return true;
72 }
73
74
75 /*
76  * Release resources allocated during backup.
77  */
78 void admin_cleanup(JCR *jcr, int TermCode)
79 {
80    char sdt[50], edt[50];
81    char term_code[100];
82    const char *term_msg;
83    int msg_type;
84    MEDIA_DBR mr;
85
86    Dmsg0(100, "Enter backup_cleanup()\n");
87    memset(&mr, 0, sizeof(mr));
88
89    update_job_end(jcr, TermCode);
90
91    if (!db_get_job_record(jcr, jcr->db, &jcr->jr)) {
92       Jmsg(jcr, M_WARNING, 0, _("Error getting Job record for Job report: ERR=%s"),
93          db_strerror(jcr->db));
94       jcr->setJobStatus(JS_ErrorTerminated);
95    }
96
97    msg_type = M_INFO;                 /* by default INFO message */
98    switch (jcr->JobStatus) {
99    case JS_Terminated:
100       term_msg = _("Admin OK");
101       break;
102    case JS_FatalError:
103    case JS_ErrorTerminated:
104       term_msg = _("*** Admin Error ***");
105       msg_type = M_ERROR;          /* Generate error message */
106       break;
107    case JS_Canceled:
108       term_msg = _("Admin Canceled");
109       break;
110    default:
111       term_msg = term_code;
112       sprintf(term_code, _("Inappropriate term code: %c\n"), jcr->JobStatus);
113       break;
114    }
115    bstrftime(sdt, sizeof(sdt), jcr->jr.StartTime);
116    bstrftime(edt, sizeof(edt), jcr->jr.EndTime);
117
118    Jmsg(jcr, msg_type, 0, _("Bacula " VERSION " (" LSMDATE "): %s\n"
119 "  JobId:                  %d\n"
120 "  Job:                    %s\n"
121 "  Start time:             %s\n"
122 "  End time:               %s\n"
123 "  Termination:            %s\n\n"),
124         edt,
125         jcr->jr.JobId,
126         jcr->jr.Job,
127         sdt,
128         edt,
129         term_msg);
130
131    Dmsg0(100, "Leave admin_cleanup()\n");
132 }