1 /* 2 BAREOS® - Backup Archiving REcovery Open Sourced 3 4 Copyright (C) 2015-2015 Planets Communications B.V. 5 Copyright (C) 2015-2015 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", 42 (char *)"TYPE", 43 (char *)"DIRECT", 44 (char *)"LEVEL", 45 (char *)"UPDATE", 46 (char *)"EXCLUDE", 47 (char *)"INCLUDE", 48 (char *)"FILESYSTEM", 49 (char *)"PREFIX" 50 }; 51 52 /** 53 * Index values for above keyword. 54 */ 55 enum { 56 NDMP_ENV_KW_HIST = 0, 57 NDMP_ENV_KW_TYPE, 58 NDMP_ENV_KW_DIRECT, 59 NDMP_ENV_KW_LEVEL, 60 NDMP_ENV_KW_UPDATE, 61 NDMP_ENV_KW_EXCLUDE, 62 NDMP_ENV_KW_INCLUDE, 63 NDMP_ENV_KW_FILESYSTEM, 64 NDMP_ENV_KW_PREFIX 65 }; 66 67 /** 68 * Array used for storing fixed NDMP env values. 69 * Anything special should go into a so called meta-tag in the fileset options. 70 */ 71 static char *ndmp_env_values[] = { 72 (char *)"n", 73 (char *)"y" 74 }; 75 76 /** 77 * Index values for above values. 78 */ 79 enum { 80 NDMP_ENV_VALUE_NO = 0, 81 NDMP_ENV_VALUE_YES 82 }; 83 #endif /* NDMP_NEED_ENV_KEYWORDS */ 84 85 struct ndmp_backup_format_option { 86 char *format; 87 bool uses_file_history; 88 bool uses_level; 89 bool restore_prefix_relative; 90 bool needs_namelist; 91 }; 92 93 /** 94 * Internal structure to keep track of private data. 95 */ 96 struct ndmp_internal_state { 97 uint32_t LogLevel; 98 JobControlRecord *jcr; 99 UaContext *ua; 100 char *filesystem; 101 int32_t FileIndex; 102 char *virtual_filename; 103 bool save_filehist; 104 int64_t filehist_size; 105 void *fhdb_state; 106 }; 107 typedef struct ndmp_internal_state NIS; 108 109 /* 110 * Generic DMA functions. 111 */ 112 ndmp_backup_format_option *ndmp_lookup_backup_format_options(const char *backup_format); 113 114 bool NdmpValidateJob(JobControlRecord *jcr, struct ndm_job_param *job); 115 void NdmpParseMetaTag(struct ndm_env_table *env_tab, char *meta_tag); 116 int NativeToNdmpLoglevel(int NdmpLoglevel, int debuglevel, NIS *nis); 117 bool NdmpBuildClientJob(JobControlRecord *jcr, ClientResource *client, StorageResource *store, int operation, 118 struct ndm_job_param *job); 119 bool NdmpBuildStorageJob(JobControlRecord *jcr, StorageResource *store, bool init_tape, bool init_robot, 120 int operation, struct ndm_job_param *job); 121 bool NdmpBuildClientAndStorageJob(JobControlRecord *jcr, StorageResource *store, ClientResource *client, 122 bool init_tape, bool init_robot, int operation, struct ndm_job_param *job); 123 124 void NdmpLoghandler(struct ndmlog *log, char *tag, int level, char *msg); 125 void NdmpDoQuery(UaContext *ua, JobControlRecord *jcr, 126 ndm_job_param *ndmp_job, int NdmpLoglevel, ndmca_query_callbacks* query_cbs); 127 128 /* 129 * NDMP FHDB specific helpers. 130 */ 131 void NdmpStoreAttributeRecord(JobControlRecord *jcr, char *fname, char *linked_fname, 132 char *attributes, int8_t FileType, uint64_t Node, uint64_t fhinfo); 133 void NdmpConvertFstat(ndmp9_file_stat *fstat, int32_t FileIndex, 134 int8_t *FileType, PoolMem &attribs); 135 136 /* 137 * FHDB using LMDB. 138 */ 139 void NdmpFhdbLmdbRegister(struct ndmlog *ixlog); 140 void NdmpFhdbLmdbUnregister(struct ndmlog *ixlog); 141 void NdmpFhdbLmdbProcessDb(struct ndmlog *ixlog); 142 143 /* 144 * FHDB using in memory tree. 145 */ 146 void NdmpFhdbMemRegister(struct ndmlog *ixlog); 147 void NdmpFhdbMemUnregister(struct ndmlog *ixlog); 148 void NdmpFhdbMemProcessDb(struct ndmlog *ixlog); 149 150 /* 151 * NDMP Media Info in DB storage and retrieval 152 */ 153 bool StoreNdmmediaInfoInDatabase(ndmmedia *media, JobControlRecord *jcr); 154 bool GetNdmmediaInfoFromDatabase(ndm_media_table *media_tab, JobControlRecord *jcr); 155 extern "C" int BndmpFhdbAddFile(struct ndmlog *ixlog, int tagc, char *raw_name, ndmp9_file_stat *fstat); 156 157 } /* namespace directordaemon */ 158 #endif /* BAREOS_DIRD_NDMP_DMA_PRIV_H_ */ 159