2 Bacula® - The Network Backup Solution
4 Copyright (C) 2008-2008 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 two of the GNU 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 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 time_t now = time(NULL);
79 sp->fname = full_path;
81 sp->statp.st_mode = 0700 | S_IFDIR;
82 sp->statp.st_ctime = now;
83 sp->statp.st_mtime = now;
84 sp->statp.st_atime = now;
85 sp->statp.st_size = 0;
94 store_node_t::endBackupFile(exchange_fd_context_t *context)
96 _DebugMessage(100, "endBackupNode_STORE state = %d\n", state);
102 // should never happen
110 stream_ptr += wcslen(stream_ptr) + 1;
111 if (*stream_ptr == 0)
117 context->current_node = parent;
124 store_node_t::createFile(exchange_fd_context_t *context, struct restore_pkt *rp)
126 _DebugMessage(0, "createFile_STORE state = %d\n", state);
128 if (strcmp(context->path_bits[level - 1], parent->name) != 0)
130 _DebugMessage(0, "Different storage group - switching back to parent\n", state);
131 context->current_node = parent;
139 if (strcmp("DatabaseBackupInfo", context->path_bits[level + 1]) != 0)
141 _JobMessage(M_ERROR, "DatabaseBackupInfo file must exist and must be first in directory\n");
145 dbi_node = new dbi_node_t(bstrdup(context->path_bits[level + 1]), this);
146 context->current_node = dbi_node;
149 if (strcmp(context->path_bits[level - 1], parent->name) != 0)
151 _JobMessage(M_ERROR, "Unexpected Storage Group Change\n");
156 if (*stream_ptr != 0)
158 // verify that stream_ptr == context->path_bits[level + 1];
159 _DebugMessage(150, "stream_ptr = %S\n", stream_ptr);
160 _DebugMessage(150, "out_stream_ptr = %S\n", out_stream_ptr);
161 file_node = new file_node_t(bstrdup(context->path_bits[level + 1]), this);
162 file_node->hccx = hccx;
163 file_node->filename = out_stream_ptr;
164 context->current_node = file_node;
169 _JobMessage(M_ERROR, "Extra file found '%s'\n", full_path);
174 if (rp->type != FT_DIREND)
176 _JobMessage(M_ERROR, "Unexpected file '%s'\n", full_path);
180 rp->create_status = CF_CREATED;
183 if (strcmp(context->path_bits[level], name) != 0)
185 _DebugMessage(0, "End of Store when in error state - switching back to parent\n", state);
186 context->current_node = parent;
189 rp->create_status = CF_CREATED;
196 store_node_t::endRestoreFile(exchange_fd_context_t *context)
200 _DebugMessage(0, "endRestoreFile_STORE state = %d\n", state);
207 _DebugMessage(0, "Calling HrESERestoreAddDatabase\n");
208 result = HrESERestoreAddDatabase(hccx, dbi_node->restore_display_name, dbi_node->restore_guid, dbi_node->restore_input_streams, &dbi_node->restore_output_streams);
211 _JobMessage(M_ERROR, "HrESERestoreAddDatabase failed with error 0x%08x - %s\n", result, ESEErrorMessage(result));
215 stream_ptr = dbi_node->restore_input_streams;
216 out_stream_ptr = dbi_node->restore_output_streams;
219 if (*stream_ptr != 0)
223 stream_ptr += wcslen(stream_ptr) + 1;
224 out_stream_ptr += wcslen(out_stream_ptr) + 1;
225 if (*stream_ptr == 0)
235 context->current_node = parent;