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 store_node_t::store_node_t(char *name, node_t *parent_node) : node_t(name, NODE_TYPE_STORE, parent_node)
42 store_node_t::~store_node_t()
47 if (file_node != NULL)
52 store_node_t::startBackupFile(exchange_fd_context_t *context, struct save_pkt *sp)
56 _DebugMessage(100, "startBackupNode_STORE state = %d\n", state);
61 stream_ptr = dbi->wszDatabaseStreams;
65 dbi_node = new dbi_node_t("DatabaseBackupInfo", this);
67 context->current_node = dbi_node;
70 tmp = new char[wcslen(stream_ptr) + 1];
71 wcstombs(tmp, stream_ptr, wcslen(stream_ptr) + 1);
72 file_node = new file_node_t(tmp, this);
73 file_node->hccx = hccx;
74 file_node->filename = stream_ptr;
75 context->current_node = file_node;
78 if (context->job_level == 'F')
80 time_t now = time(NULL);
81 sp->fname = full_path;
83 sp->statp.st_mode = 0700 | S_IFDIR;
84 sp->statp.st_ctime = now;
85 sp->statp.st_mtime = now;
86 sp->statp.st_atime = now;
87 sp->statp.st_size = 0;
92 bfuncs->setBaculaValue(context->bpContext, bVarFileSeen, (void *)full_path);
102 store_node_t::endBackupFile(exchange_fd_context_t *context)
104 _DebugMessage(100, "endBackupNode_STORE state = %d\n", state);
110 // should never happen
118 stream_ptr += wcslen(stream_ptr) + 1;
119 if (*stream_ptr == 0)
125 context->current_node = parent;
132 store_node_t::createFile(exchange_fd_context_t *context, struct restore_pkt *rp)
134 _DebugMessage(0, "createFile_STORE state = %d\n", state);
136 if (strcmp(context->path_bits[level - 1], parent->name) != 0)
138 _DebugMessage(0, "Different storage group - switching back to parent\n", state);
139 context->current_node = parent;
147 if (strcmp("DatabaseBackupInfo", context->path_bits[level + 1]) != 0)
149 _JobMessage(M_FATAL, "DatabaseBackupInfo file must exist and must be first in directory\n");
153 dbi_node = new dbi_node_t(bstrdup(context->path_bits[level + 1]), this);
154 context->current_node = dbi_node;
157 if (strcmp(context->path_bits[level - 1], parent->name) != 0)
159 _JobMessage(M_ERROR, "Unexpected Storage Group Change\n");
164 if (*stream_ptr != 0)
166 // verify that stream_ptr == context->path_bits[level + 1];
167 _DebugMessage(150, "stream_ptr = %S\n", stream_ptr);
168 _DebugMessage(150, "out_stream_ptr = %S\n", out_stream_ptr);
169 file_node = new file_node_t(bstrdup(context->path_bits[level + 1]), this);
170 file_node->hccx = hccx;
171 file_node->filename = out_stream_ptr;
172 context->current_node = file_node;
177 _JobMessage(M_ERROR, "Extra file found '%s'\n", full_path);
182 if (rp->type != FT_DIREND)
184 _JobMessage(M_ERROR, "Unexpected file '%s'\n", full_path);
188 rp->create_status = CF_CREATED;
191 if (strcmp(context->path_bits[level], name) != 0)
193 _DebugMessage(0, "End of Store when in error state - switching back to parent\n", state);
194 context->current_node = parent;
197 rp->create_status = CF_CREATED;
204 store_node_t::endRestoreFile(exchange_fd_context_t *context)
208 _DebugMessage(0, "endRestoreFile_STORE state = %d\n", state);
215 _DebugMessage(0, "Calling HrESERestoreAddDatabase\n");
216 result = HrESERestoreAddDatabase(hccx, dbi_node->restore_display_name, dbi_node->restore_guid, dbi_node->restore_input_streams, &dbi_node->restore_output_streams);
219 _JobMessage(M_FATAL, "HrESERestoreAddDatabase failed with error 0x%08x - %s\n", result, ESEErrorMessage(result));
223 stream_ptr = dbi_node->restore_input_streams;
224 out_stream_ptr = dbi_node->restore_output_streams;
227 if (*stream_ptr != 0)
231 stream_ptr += wcslen(stream_ptr) + 1;
232 out_stream_ptr += wcslen(out_stream_ptr) + 1;
233 if (*stream_ptr == 0)
243 context->current_node = parent;