1 /*
2    BAREOS® - Backup Archiving REcovery Open Sourced
3 
4    Copyright (C) 2015-2015 Planets Communications B.V.
5    Copyright (C) 2015-2019 Bareos GmbH & Co. KG
6 
7    This program is Free Software; you can redistribute it and/or
8    modify it under the terms of version three of the GNU Affero General Public
9    License as published by the Free Software Foundation and included
10    in the file LICENSE.
11 
12    This program is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15    Affero General Public License for more details.
16 
17    You should have received a copy of the GNU Affero General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20    02110-1301, USA.
21 */
22 /*
23  * Marco van Wieringen, May 2015
24  */
25 /**
26  * @file
27  * NDMP internal routines used by the different NDMP components.
28  */
29 
30 #ifndef BAREOS_DIRD_NDMP_DMA_PRIV_H_
31 #define BAREOS_DIRD_NDMP_DMA_PRIV_H_ 1
32 
33 namespace directordaemon {
34 
35 #ifdef NDMP_NEED_ENV_KEYWORDS
36 /**
37  * Array used for storing fixed NDMP env keywords.
38  * Anything special should go into a so called meta-tag in the fileset options.
39  */
40 static char* ndmp_env_keywords[]
41     = {(char*)"HIST",    (char*)"TYPE",       (char*)"DIRECT",
42        (char*)"LEVEL",   (char*)"UPDATE",     (char*)"EXCLUDE",
43        (char*)"INCLUDE", (char*)"FILESYSTEM", (char*)"PREFIX"};
44 
45 /**
46  * Index values for above keyword.
47  */
48 enum
49 {
50   NDMP_ENV_KW_HIST = 0,
51   NDMP_ENV_KW_TYPE,
52   NDMP_ENV_KW_DIRECT,
53   NDMP_ENV_KW_LEVEL,
54   NDMP_ENV_KW_UPDATE,
55   NDMP_ENV_KW_EXCLUDE,
56   NDMP_ENV_KW_INCLUDE,
57   NDMP_ENV_KW_FILESYSTEM,
58   NDMP_ENV_KW_PREFIX
59 };
60 
61 /**
62  * Array used for storing fixed NDMP env values.
63  * Anything special should go into a so called meta-tag in the fileset options.
64  */
65 static char* ndmp_env_values[] = {(char*)"n", (char*)"y"};
66 
67 /**
68  * Index values for above values.
69  */
70 enum
71 {
72   NDMP_ENV_VALUE_NO = 0,
73   NDMP_ENV_VALUE_YES
74 };
75 #endif /* NDMP_NEED_ENV_KEYWORDS */
76 
77 struct ndmp_backup_format_option {
78   char* format;
79   bool uses_file_history;
80   bool uses_level;
81   bool restore_prefix_relative;
82   bool needs_namelist;
83 };
84 
85 /**
86  * Internal structure to keep track of private data.
87  */
88 struct ndmp_internal_state {
89   uint32_t LogLevel;
90   JobControlRecord* jcr;
91   UaContext* ua;
92   char* filesystem;
93   int32_t FileIndex;
94   char* virtual_filename;
95   bool save_filehist;
96   int64_t filehist_size;
97   void* fhdb_state;
98 };
99 typedef struct ndmp_internal_state NIS;
100 
101 /*
102  * Generic DMA functions.
103  */
104 ndmp_backup_format_option* ndmp_lookup_backup_format_options(
105     const char* backup_format);
106 
107 bool NdmpValidateJob(JobControlRecord* jcr, struct ndm_job_param* job);
108 void NdmpParseMetaTag(struct ndm_env_table* env_tab, char* meta_tag);
109 int NativeToNdmpLoglevel(int NdmpLoglevel, int debuglevel, NIS* nis);
110 bool NdmpBuildClientJob(JobControlRecord* jcr,
111                         ClientResource* client,
112                         StorageResource* store,
113                         int operation,
114                         struct ndm_job_param* job);
115 bool NdmpBuildStorageJob(JobControlRecord* jcr,
116                          StorageResource* store,
117                          bool init_tape,
118                          bool init_robot,
119                          int operation,
120                          struct ndm_job_param* job);
121 bool NdmpBuildClientAndStorageJob(JobControlRecord* jcr,
122                                   StorageResource* store,
123                                   ClientResource* client,
124                                   bool init_tape,
125                                   bool init_robot,
126                                   int operation,
127                                   struct ndm_job_param* job);
128 
129 void NdmpLoghandler(struct ndmlog* log, char* tag, int level, char* msg);
130 void NdmpDoQuery(UaContext* ua,
131                  JobControlRecord* jcr,
132                  ndm_job_param* ndmp_job,
133                  int NdmpLoglevel,
134                  ndmca_query_callbacks* query_cbs);
135 
136 /*
137  * NDMP FHDB specific helpers.
138  */
139 void NdmpStoreAttributeRecord(JobControlRecord* jcr,
140                               char* fname,
141                               char* linked_fname,
142                               char* attributes,
143                               int8_t FileType,
144                               uint64_t Node,
145                               uint64_t fhinfo);
146 void NdmpConvertFstat(ndmp9_file_stat* fstat,
147                       int32_t FileIndex,
148                       int8_t* FileType,
149                       PoolMem& attribs);
150 
151 /*
152  * FHDB using LMDB.
153  */
154 void NdmpFhdbLmdbRegister(struct ndmlog* ixlog);
155 void NdmpFhdbLmdbUnregister(struct ndmlog* ixlog);
156 void NdmpFhdbLmdbProcessDb(struct ndmlog* ixlog);
157 
158 /*
159  * FHDB using in memory tree.
160  */
161 void NdmpFhdbMemRegister(struct ndmlog* ixlog);
162 void NdmpFhdbMemUnregister(struct ndmlog* ixlog);
163 void NdmpFhdbMemProcessDb(struct ndmlog* ixlog);
164 
165 /*
166  * NDMP Media Info in DB storage and retrieval
167  */
168 bool StoreNdmmediaInfoInDatabase(ndmmedia* media, JobControlRecord* jcr);
169 bool GetNdmmediaInfoFromDatabase(ndm_media_table* media_tab,
170                                  JobControlRecord* jcr);
171 extern "C" int BndmpFhdbAddFile(struct ndmlog* ixlog,
172                                 int tagc,
173                                 char* raw_name,
174                                 ndmp9_file_stat* fstat);
175 
176 } /* namespace directordaemon */
177 #endif /* BAREOS_DIRD_NDMP_DMA_PRIV_H_ */
178