2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2018 Kern Sibbald
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.
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.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
20 * Written by James Harper, July 2010
23 #include "exchange-fd.h"
25 store_node_t::store_node_t(char *name, node_t *parent_node) : node_t(name, NODE_TYPE_STORE, parent_node)
33 store_node_t::~store_node_t()
35 safe_delete(dbi_node);
36 safe_delete(file_node);
40 store_node_t::startBackupFile(exchange_fd_context_t *context, struct save_pkt *sp)
44 _DebugMessage(100, "startBackupNode_STORE state = %d\n", state);
49 stream_ptr = dbi->wszDatabaseStreams;
53 dbi_node = new dbi_node_t((char *)"DatabaseBackupInfo", this);
55 context->current_node = dbi_node;
58 tmp = new char[wcslen(stream_ptr) + 1];
59 wcstombs(tmp, stream_ptr, wcslen(stream_ptr) + 1);
60 file_node = new file_node_t(tmp, this);
61 file_node->hccx = hccx;
62 file_node->filename = stream_ptr;
63 context->current_node = file_node;
66 if (context->job_level == 'F')
68 time_t now = time(NULL);
69 sp->fname = full_path;
71 sp->statp.st_mode = 0700 | S_IFDIR;
72 sp->statp.st_ctime = now;
73 sp->statp.st_mtime = now;
74 sp->statp.st_atime = now;
75 sp->statp.st_size = 0;
80 bfuncs->setBaculaValue(context->bpContext, bVarFileSeen, (void *)full_path);
90 store_node_t::endBackupFile(exchange_fd_context_t *context)
92 _DebugMessage(100, "endBackupNode_STORE state = %d\n", state);
98 // should never happen
105 safe_delete(file_node);
106 stream_ptr += wcslen(stream_ptr) + 1;
107 if (*stream_ptr == 0)
113 context->current_node = parent;
120 store_node_t::createFile(exchange_fd_context_t *context, struct restore_pkt *rp)
122 _DebugMessage(0, "createFile_STORE state = %d\n", state);
124 if (strcmp(context->path_bits[level - 1], parent->name) != 0)
126 _DebugMessage(0, "Different storage group - switching back to parent\n", state);
127 context->current_node = parent;
135 if (strcmp("DatabaseBackupInfo", context->path_bits[level + 1]) != 0)
137 _JobMessage(M_FATAL, "DatabaseBackupInfo file must exist and must be first in directory\n");
141 dbi_node = new dbi_node_t(bstrdup(context->path_bits[level + 1]), this);
142 context->current_node = dbi_node;
145 if (strcmp(context->path_bits[level - 1], parent->name) != 0)
147 _JobMessage(M_ERROR, "Unexpected Storage Group Change\n");
152 if (*stream_ptr != 0)
154 // verify that stream_ptr == context->path_bits[level + 1];
155 _DebugMessage(150, "stream_ptr = %S\n", stream_ptr);
156 _DebugMessage(150, "out_stream_ptr = %S\n", out_stream_ptr);
157 file_node = new file_node_t(bstrdup(context->path_bits[level + 1]), this);
158 file_node->hccx = hccx;
159 file_node->filename = out_stream_ptr;
160 context->current_node = file_node;
165 _JobMessage(M_ERROR, "Extra file found '%s'\n", full_path);
170 if (rp->type != FT_DIREND)
172 _JobMessage(M_ERROR, "Unexpected file '%s'\n", full_path);
176 rp->create_status = CF_CREATED;
179 if (strcmp(context->path_bits[level], name) != 0)
181 _DebugMessage(0, "End of Store when in error state - switching back to parent\n", state);
182 context->current_node = parent;
185 rp->create_status = CF_CREATED;
192 store_node_t::endRestoreFile(exchange_fd_context_t *context)
196 _DebugMessage(0, "endRestoreFile_STORE state = %d\n", state);
203 _DebugMessage(0, "Calling HrESERestoreAddDatabase\n");
204 result = HrESERestoreAddDatabase(hccx, dbi_node->restore_display_name, dbi_node->restore_guid, dbi_node->restore_input_streams, &dbi_node->restore_output_streams);
207 _JobMessage(M_FATAL, "HrESERestoreAddDatabase failed with error 0x%08x - %s\n", result, ESEErrorMessage(result));
211 stream_ptr = dbi_node->restore_input_streams;
212 out_stream_ptr = dbi_node->restore_output_streams;
215 if (*stream_ptr != 0)
217 safe_delete(file_node);
219 stream_ptr += wcslen(stream_ptr) + 1;
220 out_stream_ptr += wcslen(out_stream_ptr) + 1;
221 if (*stream_ptr == 0)
231 context->current_node = parent;