Changeset 2900 for box/trunk/bin
- Timestamp:
- 29/03/2011 00:41:25 (14 months ago)
- Location:
- box/trunk/bin/bbackupd
- Files:
-
- 2 edited
-
BackupDaemon.cpp (modified) (4 diffs)
-
BackupDaemon.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
box/trunk/bin/bbackupd/BackupDaemon.cpp
r2884 r2900 83 83 84 84 extern Win32BackupService* gpDaemonService; 85 86 # ifdef ENABLE_VSS 87 # include <comdef.h> 88 # include <Vss.h> 89 # include <VsWriter.h> 90 # include <VsBackup.h> 91 92 // http://www.flounder.com/cstring.htm 93 std::string GetMsgForHresult(HRESULT hr) 94 { 95 std::ostringstream buf; 96 97 if(hr == VSS_S_ASYNC_CANCELLED) 98 { 99 buf << "VSS async operation cancelled"; 100 } 101 else if(hr == VSS_S_ASYNC_FINISHED) 102 { 103 buf << "VSS async operation finished"; 104 } 105 else if(hr == VSS_S_ASYNC_PENDING) 106 { 107 buf << "VSS async operation pending"; 108 } 109 else 110 { 111 buf << _com_error(hr).ErrorMessage(); 112 } 113 114 buf << " (" << BOX_FORMAT_HEX32(hr) << ")"; 115 return buf.str(); 116 } 117 118 std::string WideStringToString(WCHAR *buf) 119 { 120 char* pStr = ConvertFromWideString(buf, CP_UTF8); 121 std::string result(pStr); 122 free(pStr); 123 return result; 124 } 125 126 std::string GuidToString(GUID guid) 127 { 128 wchar_t buf[64]; 129 StringFromGUID2(guid, buf, sizeof(buf)); 130 return WideStringToString(buf); 131 } 132 # endif 85 133 #endif 86 134 … … 126 174 mServiceName("bbackupd") 127 175 #endif 176 #ifdef ENABLE_VSS 177 , mpVssBackupComponents(NULL) 178 #endif 128 179 { 129 180 // Only ever one instance of a daemon … … 882 933 // Delete any unused directories? 883 934 DeleteUnusedRootDirEntries(clientContext); 935 936 #ifdef ENABLE_VSS 937 CreateVssBackupComponents(); 938 #endif 884 939 885 940 // Go through the records, syncing them … … 953 1008 // -------------------------------------------------------------------------------------------- 954 1009 } 1010 1011 #ifdef ENABLE_VSS 1012 void BackupDaemon::CreateVssBackupComponents() 1013 { 1014 HRESULT result = CoInitialize(NULL); 1015 if(result != S_OK) 1016 { 1017 BOX_ERROR("Failed to initialize COM for VSS: " << 1018 GetMsgForHresult(result)); 1019 return; 1020 } 1021 1022 result = ::CreateVssBackupComponents(&mpVssBackupComponents); 1023 if(result != S_OK) 1024 { 1025 BOX_ERROR("Failed to create VSS backup components: " << 1026 GetMsgForHresult(result)); 1027 return; 1028 } 1029 1030 result = mpVssBackupComponents->InitializeForBackup(NULL); 1031 if(result != S_OK) 1032 { 1033 std::string message = GetMsgForHresult(result); 1034 1035 if (result == VSS_E_UNEXPECTED) 1036 { 1037 message = "Check the Application Log for details, and ensure " 1038 "that the Volume Shadow Copy, COM+ System Application, " 1039 "and Distributed Transaction Coordinator services " 1040 "are running"; 1041 } 1042 1043 BOX_ERROR("Failed to initialize VSS for backup: " << message); 1044 goto CreateVssBackupComponents_cleanup_mpVssBackupComponents; 1045 } 1046 1047 result = mpVssBackupComponents->SetContext(VSS_CTX_BACKUP); 1048 if(result == E_NOTIMPL) 1049 { 1050 BOX_INFO("Failed to set VSS context to VSS_CTX_BACKUP: " 1051 "not implemented, probably Windows XP, ignored."); 1052 } 1053 else if(result != S_OK) 1054 { 1055 BOX_ERROR("Failed to set VSS context to VSS_CTX_BACKUP: " << 1056 GetMsgForHresult(result)); 1057 goto CreateVssBackupComponents_cleanup_mpVssBackupComponents; 1058 } 1059 1060 result = mpVssBackupComponents->SetBackupState( 1061 false, /* no components for now */ 1062 true, /* might as well ask for a bootable backup */ 1063 VSS_BT_FULL, 1064 false /* what is Partial File Support? */); 1065 if(result != S_OK) 1066 { 1067 BOX_ERROR("Failed to set VSS backup state: " << 1068 GetMsgForHresult(result)); 1069 goto CreateVssBackupComponents_cleanup_mpVssBackupComponents; 1070 } 1071 1072 IVssAsync *pAsync; 1073 result = mpVssBackupComponents->GatherWriterMetadata(&pAsync); 1074 if(result != S_OK) 1075 { 1076 BOX_ERROR("Failed to set VSS backup state: " << 1077 GetMsgForHresult(result)); 1078 goto CreateVssBackupComponents_cleanup_mpVssBackupComponents; 1079 } 1080 1081 BOX_INFO("VSS: waiting for GatherWriterMetadata() to complete"); 1082 1083 do 1084 { 1085 result = pAsync->Wait(1000); 1086 if(result != S_OK) 1087 { 1088 BOX_ERROR("VSS: Failed to wait for GatherWriterMetadata() " 1089 "to complete: " << GetMsgForHresult(result)); 1090 goto CreateVssBackupComponents_cleanup_pAsync; 1091 } 1092 1093 HRESULT result2; 1094 result = pAsync->QueryStatus(&result2, NULL); 1095 if(result != S_OK) 1096 { 1097 BOX_ERROR("VSS: Failed to query GatherWriterMetadata() " 1098 "status: " << GetMsgForHresult(result)); 1099 goto CreateVssBackupComponents_cleanup_pAsync; 1100 } 1101 1102 result = result2; 1103 BOX_INFO("VSS: GatherWriterMetadata() status: " << 1104 GetMsgForHresult(result)); 1105 } 1106 while(result == VSS_S_ASYNC_PENDING); 1107 1108 pAsync->Release(); 1109 pAsync = NULL; 1110 1111 if(result != VSS_S_ASYNC_FINISHED) 1112 { 1113 BOX_ERROR("VSS: GatherWriterMetadata() failed: " << 1114 GetMsgForHresult(result)); 1115 goto CreateVssBackupComponents_cleanup_mpVssBackupComponents; 1116 } 1117 1118 UINT writerCount; 1119 result = mpVssBackupComponents->GetWriterMetadataCount(&writerCount); 1120 if(result != S_OK) 1121 { 1122 BOX_ERROR("Failed to get VSS writer count: " << 1123 GetMsgForHresult(result)); 1124 goto CreateVssBackupComponents_cleanup_mpVssBackupComponents; 1125 } 1126 1127 for(UINT iWriter = 0; iWriter < writerCount; iWriter++) 1128 { 1129 BOX_INFO("VSS: Getting metadata from writer " << iWriter); 1130 VSS_ID writerInstance; 1131 IVssExamineWriterMetadata* pMetadata; 1132 result = mpVssBackupComponents->GetWriterMetadata(iWriter, 1133 &writerInstance, &pMetadata); 1134 if(result != S_OK) 1135 { 1136 BOX_ERROR("Failed to get VSS metadata from writer " << iWriter << 1137 ": " << GetMsgForHresult(result)); 1138 goto CreateVssBackupComponents_cleanup_mpVssBackupComponents; 1139 } 1140 1141 UINT includeFiles, excludeFiles, numComponents; 1142 result = pMetadata->GetFileCounts(&includeFiles, &excludeFiles, 1143 &numComponents); 1144 if(result != S_OK) 1145 { 1146 BOX_ERROR("Failed to get VSS metadata file counts from " 1147 "writer " << iWriter << ": " << 1148 GetMsgForHresult(result)); 1149 pMetadata->Release(); 1150 goto CreateVssBackupComponents_cleanup_mpVssBackupComponents; 1151 } 1152 1153 for(UINT iComponent = 0; iComponent < numComponents; iComponent++) 1154 { 1155 IVssWMComponent* pComponent; 1156 result = pMetadata->GetComponent(iComponent, &pComponent); 1157 if(result != S_OK) 1158 { 1159 BOX_ERROR("Failed to get VSS metadata component " << 1160 iComponent << " from writer " << iWriter << ": " << 1161 GetMsgForHresult(result)); 1162 continue; 1163 } 1164 1165 PVSSCOMPONENTINFO pComponentInfo; 1166 result = pComponent->GetComponentInfo(&pComponentInfo); 1167 if(result != S_OK) 1168 { 1169 BOX_ERROR("Failed to get VSS metadata component " << 1170 iComponent << " info from writer " << iWriter << ": " << 1171 GetMsgForHresult(result)); 1172 pComponent->Release(); 1173 continue; 1174 } 1175 1176 pComponent->FreeComponentInfo(pComponentInfo); 1177 pComponent->Release(); 1178 } 1179 1180 pMetadata->Release(); 1181 } 1182 1183 IVssEnumObject *pEnum; 1184 result = mpVssBackupComponents->Query(GUID_NULL, VSS_OBJECT_NONE, 1185 VSS_OBJECT_SNAPSHOT, &pEnum); 1186 if(result != S_OK) 1187 { 1188 BOX_ERROR("Failed to query VSS snapshot list: " << 1189 GetMsgForHresult(result)); 1190 goto CreateVssBackupComponents_cleanup_mpVssBackupComponents; 1191 } 1192 1193 while(result == S_OK) 1194 { 1195 VSS_OBJECT_PROP rgelt; 1196 ULONG count; 1197 result = pEnum->Next(1, &rgelt, &count); 1198 1199 if(result != S_OK && result != S_FALSE) 1200 { 1201 BOX_ERROR("Failed to enumerate VSS snapshot: " << 1202 GetMsgForHresult(result)); 1203 } 1204 else if(count != 1) 1205 { 1206 BOX_ERROR("Failed to enumerate VSS snapshot: " << 1207 "Next() returned " << count << " objects instead of 1"); 1208 } 1209 else if(rgelt.Type != VSS_OBJECT_SNAPSHOT) 1210 { 1211 BOX_ERROR("Failed to enumerate VSS snapshot: " << 1212 "Next() returned a type " << rgelt.Type << " object " 1213 "instead of VSS_OBJECT_SNAPSHOT"); 1214 } 1215 else 1216 { 1217 VSS_SNAPSHOT_PROP *pSnap = &rgelt.Obj.Snap; 1218 BOX_TRACE("VSS: Snapshot ID: " << 1219 GuidToString(pSnap->m_SnapshotId)); 1220 BOX_TRACE("VSS: Snapshot set ID: " << 1221 GuidToString(pSnap->m_SnapshotSetId)); 1222 BOX_TRACE("VSS: Number of volumes: " << 1223 pSnap->m_lSnapshotsCount); 1224 BOX_TRACE("VSS: Snapshot device object: " << 1225 WideStringToString(pSnap->m_pwszSnapshotDeviceObject)); 1226 BOX_TRACE("VSS: Original volume name: " << 1227 WideStringToString(pSnap->m_pwszOriginalVolumeName)); 1228 BOX_TRACE("VSS: Originating machine: " << 1229 WideStringToString(pSnap->m_pwszOriginatingMachine)); 1230 BOX_TRACE("VSS: Service machine: " << 1231 WideStringToString(pSnap->m_pwszServiceMachine)); 1232 BOX_TRACE("VSS: Exposed name: " << 1233 WideStringToString(pSnap->m_pwszExposedName)); 1234 BOX_TRACE("VSS: Exposed path: " << 1235 WideStringToString(pSnap->m_pwszExposedPath)); 1236 BOX_TRACE("VSS: Provider ID: " << 1237 GuidToString(pSnap->m_ProviderId)); 1238 BOX_TRACE("VSS: Snapshot attributes: " << 1239 BOX_FORMAT_HEX32(pSnap->m_lSnapshotAttributes)); 1240 BOX_TRACE("VSS: Snapshot creation time: " << 1241 BOX_FORMAT_HEX32(pSnap->m_tsCreationTimestamp)); 1242 1243 std::string status; 1244 switch(pSnap->m_eStatus) 1245 { 1246 case VSS_SS_UNKNOWN: status = "Unknown (error)"; break; 1247 case VSS_SS_PREPARING: status = "Preparing"; break; 1248 case VSS_SS_PROCESSING_PREPARE: status = "Preparing (processing)"; break; 1249 case VSS_SS_PREPARED: status = "Prepared"; break; 1250 case VSS_SS_PROCESSING_PRECOMMIT: status = "Precommitting"; break; 1251 case VSS_SS_PRECOMMITTED: status = "Precommitted"; break; 1252 case VSS_SS_PROCESSING_COMMIT: status = "Commiting"; break; 1253 case VSS_SS_COMMITTED: status = "Committed"; break; 1254 case VSS_SS_PROCESSING_POSTCOMMIT: status = "Postcommitting"; break; 1255 case VSS_SS_PROCESSING_PREFINALCOMMIT: status = "Pre final committing"; break; 1256 case VSS_SS_PREFINALCOMMITTED: status = "Pre final committed"; break; 1257 case VSS_SS_PROCESSING_POSTFINALCOMMIT: status = "Post final committing"; break; 1258 case VSS_SS_CREATED: status = "Created"; break; 1259 case VSS_SS_ABORTED: status = "Aborted"; break; 1260 case VSS_SS_DELETED: status = "Deleted"; break; 1261 case VSS_SS_POSTCOMMITTED: status = "Postcommitted"; break; 1262 default: 1263 std::ostringstream buf; 1264 buf << "Unknown code: " << pSnap->m_eStatus; 1265 status = buf.str(); 1266 } 1267 1268 BOX_TRACE("VSS: Snapshot status: " << status); 1269 1270 CoTaskMemFree(pSnap->m_pwszSnapshotDeviceObject); 1271 CoTaskMemFree(pSnap->m_pwszOriginalVolumeName); 1272 CoTaskMemFree(pSnap->m_pwszOriginatingMachine); 1273 CoTaskMemFree(pSnap->m_pwszServiceMachine); 1274 CoTaskMemFree(pSnap->m_pwszExposedName); 1275 CoTaskMemFree(pSnap->m_pwszExposedPath); 1276 } 1277 } 1278 1279 pEnum->Release(); 1280 1281 CreateVssBackupComponents_cleanup_pAsync: 1282 pAsync->Release(); 1283 1284 CreateVssBackupComponents_cleanup_mpVssBackupComponents: 1285 mpVssBackupComponents->Release(); 1286 mpVssBackupComponents = NULL; 1287 return; 1288 } 1289 #endif 955 1290 956 1291 void BackupDaemon::OnBackupStart() -
box/trunk/bin/bbackupd/BackupDaemon.h
r2804 r2900 30 30 #include "WinNamedPipeListener.h" 31 31 #include "WinNamedPipeStream.h" 32 #endif 33 34 #ifdef ENABLE_VSS 35 class IVssBackupComponents; 32 36 #endif 33 37 … … 523 527 std::string mServiceName; 524 528 #endif 529 530 #ifdef ENABLE_VSS 531 IVssBackupComponents* mpVssBackupComponents; 532 void CreateVssBackupComponents(); 533 #endif 525 534 }; 526 535
Note: See TracChangeset
for help on using the changeset viewer.
