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, October 2008
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()
38 if (file_node != NULL)
43 store_node_t::startBackupFile(exchange_fd_context_t *context, struct save_pkt *sp)
47 _DebugMessage(100, "startBackupNode_STORE state = %d\n", state);
52 stream_ptr = dbi->wszDatabaseStreams;
56 dbi_node = new dbi_node_t("DatabaseBackupInfo", this);
58 context->current_node = dbi_node;
61 tmp = new char[wcslen(stream_ptr) + 1];
62 wcstombs(tmp, stream_ptr, wcslen(stream_ptr) + 1);
63 file_node = new file_node_t(tmp, this);
64 file_node->hccx = hccx;
65 file_node->filename = stream_ptr;
66 context->current_node = file_node;
69 if (context->job_level == 'F')
71 time_t now = time(NULL);
72 sp->fname = full_path;
74 sp->statp.st_mode = 0700 | S_IFDIR;
75 sp->statp.st_ctime = now;
76 sp->statp.st_mtime = now;
77 sp->statp.st_atime = now;
78 sp->statp.st_size = 0;
83 bfuncs->setBaculaValue(context->bpContext, bVarFileSeen, (void *)full_path);
93 store_node_t::endBackupFile(exchange_fd_context_t *context)
95 _DebugMessage(100, "endBackupNode_STORE state = %d\n", state);
101 // should never happen
109 stream_ptr += wcslen(stream_ptr) + 1;
110 if (*stream_ptr == 0)
116 context->current_node = parent;
123 store_node_t::createFile(exchange_fd_context_t *context, struct restore_pkt *rp)
125 _DebugMessage(100, "createFile_STORE state = %d\n", state);
127 if (strcmp(context->path_bits[level - 1], parent->name) != 0)
129 _DebugMessage(100, "Different storage group - switching back to parent\n", state);
130 context->current_node = parent;
138 if (strcmp("DatabaseBackupInfo", context->path_bits[level + 1]) != 0)
140 _JobMessage(M_FATAL, "DatabaseBackupInfo file must exist and must be first in directory\n");
144 dbi_node = new dbi_node_t(bstrdup(context->path_bits[level + 1]), this);
145 context->current_node = dbi_node;
148 if (strcmp(context->path_bits[level - 1], parent->name) != 0)
150 _JobMessage(M_ERROR, "Unexpected Storage Group Change\n");
155 if (*stream_ptr != 0)
157 // verify that stream_ptr == context->path_bits[level + 1];
158 _DebugMessage(150, "stream_ptr = %S\n", stream_ptr);
159 _DebugMessage(150, "out_stream_ptr = %S\n", out_stream_ptr);
160 file_node = new file_node_t(bstrdup(context->path_bits[level + 1]), this);
161 file_node->hccx = hccx;
162 file_node->filename = out_stream_ptr;
163 context->current_node = file_node;
168 _JobMessage(M_ERROR, "Extra file found '%s'\n", full_path);
173 if (rp->type != FT_DIREND)
175 _JobMessage(M_ERROR, "Unexpected file '%s'\n", full_path);
179 rp->create_status = CF_CREATED;
182 if (strcmp(context->path_bits[level], name) != 0)
184 _DebugMessage(100, "End of Store when in error state - switching back to parent\n", state);
185 context->current_node = parent;
188 rp->create_status = CF_CREATED;
195 store_node_t::endRestoreFile(exchange_fd_context_t *context)
199 _DebugMessage(100, "endRestoreFile_STORE state = %d\n", state);
206 _DebugMessage(100, "Calling HrESERestoreAddDatabase\n");
207 result = HrESERestoreAddDatabase(hccx, dbi_node->restore_display_name, dbi_node->restore_guid, dbi_node->restore_input_streams, &dbi_node->restore_output_streams);
210 _JobMessage(M_FATAL, "HrESERestoreAddDatabase failed with error 0x%08x - %s\n", result, ESEErrorMessage(result));
214 stream_ptr = dbi_node->restore_input_streams;
215 out_stream_ptr = dbi_node->restore_output_streams;
218 if (*stream_ptr != 0)
222 stream_ptr += wcslen(stream_ptr) + 1;
223 out_stream_ptr += wcslen(out_stream_ptr) + 1;
224 if (*stream_ptr == 0)
234 context->current_node = parent;