void BackupExecuter::_RestoreDataDirectory(shared_ptr<Backup> pBackup, XNode *pBackupNode) { XNode *pBackupInfoNode = pBackupNode->GetChild(_T("BackupInformation")); // Create the path to the zip file. String sBackupFile = pBackup->GetBackupFile(); String sPath = sBackupFile.Mid(0, sBackupFile.ReverseFind(_T("\\"))); String sDirContainingDataFiles; String sDataFileFormat = pBackupInfoNode->GetChildAttr(_T("DataFiles"), _T("Format"))->value; String sExtractedFilesDirectory; if (sDataFileFormat.CompareNoCase(_T("7Z")) == 0) { // Create the path to the directory that will contain the extracted files. // This directory is temporary and will be removed when we're done. sExtractedFilesDirectory = Utilities::GetUniqueTempDirectory(); // Extract the files to this directory. Compression oComp; oComp.Uncompress(sBackupFile, sExtractedFilesDirectory); // The data files in the zip file are stored in // a directory called DataBackup. sDirContainingDataFiles = sExtractedFilesDirectory + "\\DataBackup"; } else { // Fetch the path to the data files. String sFolderName = pBackupInfoNode->GetChildAttr(_T("DataFiles"), _T("FolderName"))->value; sDirContainingDataFiles = sPath + "\\" + sFolderName; } // Delete all directories from the data directory // so that we're sure that we're doing a clean restore String sDataDirectory = IniFileSettings::Instance()->GetDataDirectory(); std::set<String> vecExcludes; FileUtilities::DeleteFilesInDirectory(sDataDirectory); FileUtilities::DeleteDirectoriesInDirectory(sDataDirectory, vecExcludes); String errorMessage; FileUtilities::CopyDirectory(sDirContainingDataFiles, sDataDirectory, errorMessage); if (sDataFileFormat.CompareNoCase(_T("7z")) == 0) { // The temporary directory we created while // unzipping should be deleted now. FileUtilities::DeleteDirectory(sExtractedFilesDirectory); } }
shared_ptr<Backup> BackupManager::LoadBackup(const String &sZipFile) const { LOG_DEBUG("BackupManager::LoadBackup"); shared_ptr<Backup> pResult = shared_ptr<Backup>(new Backup); // First uncompress our specification file. String sTempDir = IniFileSettings::Instance()->GetTempDirectory(); String sXMLFile = sTempDir + "\\hMailServerBackup.xml"; FileUtilities::DeleteFile(sXMLFile); Compression oComp; oComp.Uncompress(sZipFile, sTempDir, "hMailServerBackup.xml"); // Load the XML document String sXMLBuffer = FileUtilities::ReadCompleteTextFile(sXMLFile); XDoc oXMLDocument; oXMLDocument.Load(sXMLBuffer); XNode *pBackupNode = oXMLDocument.GetChild(_T("Backup")); if (!pBackupNode) { LOG_DEBUG("BackupManager::~LoadBackup - E1"); return pResult; } int iMode = _ttoi(pBackupNode->GetChildAttr(_T("BackupInformation"), _T("Mode"))->value); pResult->SetBackupFile(sZipFile); pResult->SetContains(iMode); // Delete the XML file we temporarly created FileUtilities::DeleteFile(sXMLFile); LOG_DEBUG("BackupManager::~LoadBackup - E2"); return pResult; }