2 Bacula® - The Network Backup Solution
4 Copyright (C) 2008-2010 Free Software Foundation Europe e.V.
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, which is
11 listed in the file LICENSE.
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.
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
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.
29 * Written by James Harper, October 2008
32 #include "exchange-fd.h"
34 service_node_t::service_node_t(char *name, node_t *parent_node) : node_t(name, NODE_TYPE_SERVICE, parent_node)
40 first_storage_group_node = NULL;
43 service_node_t::~service_node_t()
48 service_node_t::startBackupFile(exchange_fd_context_t *context, struct save_pkt *sp)
53 _DebugMessage(100, "startBackupNode_SERVICE state = %d\n", state);
57 if (strcmp(PLUGIN_PATH_PREFIX_SERVICE, name) != 0)
59 _JobMessage(M_FATAL, "Invalid restore path specified, must start with /" PLUGIN_PATH_PREFIX_BASE "/" PLUGIN_PATH_PREFIX_SERVICE "/\n");
62 // convert name to a wide string
64 _DebugMessage(100, "Calling HrESEBackupPrepare\n");
65 wcstombs(aname, context->computer_name, 256);
66 _JobMessage(M_INFO, "Preparing Exchange Backup for %s\n", aname);
67 result = HrESEBackupPrepare(context->computer_name, PLUGIN_PATH_PREFIX_SERVICE_W, &ibi_count, &ibi, &hccx);
70 _JobMessage(M_FATAL, "HrESEBackupPrepare failed with error 0x%08x - %s\n", result, ESEErrorMessage(result));
76 if (context->path_bits[level + 1] == NULL)
78 _DebugMessage(100, "No specific storage group specified - backing them all up\n");
79 char *tmp = new char[wcslen(ibi[current_ibi].wszInstanceName) + 1];
80 wcstombs(tmp, ibi[current_ibi].wszInstanceName, wcslen(ibi[current_ibi].wszInstanceName) + 1);
81 first_storage_group_node = new storage_group_node_t(tmp, this);
83 _DebugMessage(100, "storage group name = %s\n", first_storage_group_node->name);
84 first_storage_group_node->ibi = &ibi[current_ibi];
85 first_storage_group_node->hccx = hccx;
86 context->current_node = first_storage_group_node;
91 for (current_ibi = 0; current_ibi < ibi_count; current_ibi++)
93 tmp = new char[wcslen(ibi[current_ibi].wszInstanceName) + 1];
94 wcstombs(tmp, ibi[current_ibi].wszInstanceName, wcslen(ibi[current_ibi].wszInstanceName) + 1);
95 if (stricmp(tmp, context->path_bits[level + 1]) == 0)
98 first_storage_group_node = new storage_group_node_t(tmp, this);
100 if (current_ibi == ibi_count)
102 _JobMessage(M_FATAL, "Invalid Storage Group '%s'\n", context->path_bits[level + 1]);
105 _DebugMessage(100, "storage group name = %s\n", first_storage_group_node->name);
106 first_storage_group_node->ibi = &ibi[current_ibi];
107 first_storage_group_node->hccx = hccx;
108 context->current_node = first_storage_group_node;
112 time_t now = time(NULL);
113 sp->fname = full_path;
114 sp->link = full_path;
115 sp->statp.st_mode = 0700 | S_IFDIR;
116 sp->statp.st_ctime = now;
117 sp->statp.st_mtime = now;
118 sp->statp.st_atime = now;
119 sp->statp.st_size = 0;
120 sp->statp.st_nlink = 1;
121 //sp->statp.st_blocks = 0;
122 sp->type = FT_DIREND;
125 _DebugMessage(100, "ending startBackupNode_SERVICE state = %d\n", state);
130 service_node_t::endBackupFile(exchange_fd_context_t *context)
135 _DebugMessage(100, "endBackupNode_SERVICE state = %d\n", state);
139 // should never happen
142 // free node->storage_group_node
143 if (context->path_bits[level + 1] == NULL)
146 if (current_ibi == ibi_count)
154 _DebugMessage(100, "calling HrESEBackupEnd\n");
155 result = HrESEBackupEnd(hccx);
158 _JobMessage(M_FATAL, "HrESEBackupEnd failed with error 0x%08x - %s\n", result, ESEErrorMessage(result));
162 context->current_node = parent;
170 service_node_t::createFile(exchange_fd_context_t *context, struct restore_pkt *rp)
172 storage_group_node_t *curr_sg, *prev_sg;
174 _DebugMessage(0, "createFile_SERVICE state = %d\n", state);
175 if (strcmp(name, "Microsoft Information Store") != 0)
177 _JobMessage(M_FATAL, "Invalid restore path specified, must start with '/" PLUGIN_PATH_PREFIX_BASE "/" PLUGIN_PATH_PREFIX_SERVICE "/'\n", state);
185 if (context->path_bits[level + 1] == NULL)
190 for (prev_sg = NULL, curr_sg = first_storage_group_node; curr_sg != NULL; prev_sg = curr_sg, curr_sg = curr_sg->next)
192 if (strcmp(curr_sg->name, context->path_bits[level + 1]) == 0)
199 curr_sg = new storage_group_node_t(bstrdup(context->path_bits[level + 1]), this);
201 first_storage_group_node = curr_sg;
203 prev_sg->next = curr_sg;
205 context->current_node = curr_sg;
208 rp->create_status = CF_CREATED;
216 service_node_t::endRestoreFile(exchange_fd_context_t *context)
218 _DebugMessage(0, "endRestoreFile_SERVICE state = %d\n", state);
224 context->current_node = parent;