/// <summary> /// グループ情報取得 /// </summary> /// <returns></returns> public backupServerGroup GetBackupServerGroup(int monitorServerID) { backupServerGroup _backupServerGroup = null; try { string sql = @"select * from backupServerGroup where monitorServerID = @monitorServerID and deleteFlg = 0"; SqlParameter para = new SqlParameter("@monitorServerID", monitorServerID); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, CommandType.Text, sql, para)) { if (reader.Read()) { _backupServerGroup = new backupServerGroup(); _backupServerGroup.id = int.Parse(reader["id"].ToString()); _backupServerGroup.backupServerGroupName = reader["backupServerGroupName"].ToString(); _backupServerGroup.monitorServerID = int.Parse(reader["monitorServerID"].ToString()); _backupServerGroup.deleteFlg = short.Parse(reader["deleteFlg"].ToString()); } } } catch (Exception ex) { logger.Error(ex.Message); } return(_backupServerGroup); }
/// <summary> /// ファイルの比較 /// </summary> /// <param name="startSrcPath"></param> /// <param name="startBakPath"></param> private void FileCopyListen(string startSrcPath, string startBakPath) { MonitorServerFolderManager monitorServerFolderManager = new MonitorServerFolderManager(); MonitorFileListenManager monitorFileListenManager = new MonitorFileListenManager(); FileTypeSetManager fileTypeSetManager = new FileTypeSetManager(); BackupServerGroupManager backupServerGroupManager = new BackupServerGroupManager(); BackupServerGroupDetailManager backupServerGroupDetailManager = new BackupServerGroupDetailManager(); BackupServerManager backupServerManager = new BackupServerManager(); // 転送情報の抽出 try { backupServerGroup backupServerGroup = backupServerGroupManager.GetBackupServerGroup(Int32.Parse(paraMonitorID)); List <backupServerGroupDetail> backupServerGroupDetailList = backupServerGroupDetailManager.GetBackupServerGroupDetailList(backupServerGroup.id); // 監視対象の抽出 List <monitorServerFolder> monitorPathlist = monitorServerFolderManager.GetByMonitorObject(Int32.Parse(paraMonitorID), "99", 1, 0); // if (monitorPathlist.Count > 0) { int monitorPathNum = monitorPathlist.Count; for (int i = 0; i < monitorPathNum; i++) { try { if (String.IsNullOrEmpty(monitorPathlist[i].monitorFileName)) { // FileSetInfo fileSetInfo = fileTypeSetManager.CheckFileTypeSet(paraMonitorRootDirectory, Int32.Parse(paraMonitorID), 0); if (fileSetInfo.DirectoryPathList.Count() > 0) { if (fileSetInfo.DirectoryPathList.Contains(paraMonitorRootDirectory)) { // ファイル除外リスト List <string> fileExtensionList = fileSetInfo.DirectoryFileExtensionList[paraMonitorRootDirectory] as List <string>; // ローカルコピー CopyListenExclusionFile(startSrcPath.TrimEnd('\\'), startBakPath.TrimEnd('\\'), fileExtensionList, paraCopyListenTime, MTNum, RNum, WNum); // Thread.Sleep(10000); // 転送コピー for (int j = 0; j < backupServerGroupDetailList.Count; j++) { backupServer backupServer = backupServerManager.GetBackupServerInfo(backupServerGroupDetailList[j].backupServerID); string TransferCopyPath = @"\\" + backupServer.backupServerIP + @"\" + backupServer.startFile.TrimStart('\\'); CopyListenExclusionFile(startBakPath.TrimEnd('\\'), TransferCopyPath.TrimEnd('\\'), fileExtensionList, paraTransferTime, MTNum, RNum, WNum); } } else { // ローカルコピー CopyListen(startSrcPath.TrimEnd('\\'), startBakPath.TrimEnd('\\'), paraCopyListenTime, MTNum, RNum, WNum); // Thread.Sleep(10000); // 転送コピー for (int j = 0; j < backupServerGroupDetailList.Count; j++) { backupServer backupServer = backupServerManager.GetBackupServerInfo(backupServerGroupDetailList[j].backupServerID); string TransferCopyPath = @"\\" + backupServer.backupServerIP + @"\" + backupServer.startFile.TrimStart('\\'); CopyListen(startBakPath.TrimEnd('\\'), TransferCopyPath.TrimEnd('\\'), paraTransferTime, MTNum, RNum, WNum); } } } else { // ローカルコピー CopyListen(startSrcPath.TrimEnd('\\'), startBakPath.TrimEnd('\\'), paraCopyListenTime, MTNum, RNum, WNum); // Thread.Sleep(10000); // 転送コピー for (int j = 0; j < backupServerGroupDetailList.Count; j++) { backupServer backupServer = backupServerManager.GetBackupServerInfo(backupServerGroupDetailList[j].backupServerID); string TransferCopyPath = @"\\" + backupServer.backupServerIP + @"\" + backupServer.startFile.TrimStart('\\'); CopyListen(startBakPath.TrimEnd('\\'), TransferCopyPath.TrimEnd('\\'), paraTransferTime, MTNum, RNum, WNum); } } break; } else { // コピー元 string objectPath = Path.Combine(monitorPathlist[i].monitorFilePath + "\\", monitorPathlist[i].monitorFileName); string copySrcPath = PathFileConvert(paraMonitorRootDirectory, startSrcPath, objectPath); // コピー先 string copyTargetPath = PathFileConvert(paraMonitorRootDirectory, startBakPath, objectPath); // FileSetInfo fileSetInfo = fileTypeSetManager.CheckFileTypeSet(objectPath, Int32.Parse(paraMonitorID), 0); if (fileSetInfo.DirectoryPathList.Count() > 0) { // フォルダー除外リスト List <string> folderExtensionList = fileSetInfo.DirectoryPathList; // 監視元の除外フォルダーリスト List <string> folderPathConvertExtensionList = new List <string>(); // コピー先の除外フォルダーリスト List <string> folderPathConvertExtensionForLocalList = new List <string>(); if (folderExtensionList.Count > 0) { foreach (string folderExtensionPath in folderExtensionList) { if (!folderExtensionPath.Equals(objectPath)) { if (!String.IsNullOrEmpty(RelativePathFileConvert(folderExtensionPath))) { folderPathConvertExtensionList.Add(RelativePathFileConvert(folderExtensionPath)); folderPathConvertExtensionForLocalList.Add(RelativePathFileConvert(folderExtensionPath)); } } } } // if (fileSetInfo.DirectoryPathList.Contains(objectPath)) { // ファイル除外リスト List <string> fileExtensionList = fileSetInfo.DirectoryFileExtensionList[objectPath] as List <string>; // ローカルコピー CopyListenExclusionFolderFile(copySrcPath.TrimEnd('\\'), copyTargetPath.TrimEnd('\\'), folderPathConvertExtensionList, fileExtensionList, paraCopyListenTime, MTNum, RNum, WNum); // Thread.Sleep(10000); // 転送コピー for (int j = 0; j < backupServerGroupDetailList.Count; j++) { backupServer backupServer = backupServerManager.GetBackupServerInfo(backupServerGroupDetailList[j].backupServerID); string TransferCopyPath = @"\\" + backupServer.backupServerIP + @"\" + backupServer.startFile.TrimStart('\\'); // 転送先 string TransferTargetPath = PathFileConvert(startBakPath, TransferCopyPath, copyTargetPath); CopyListenExclusionFolderFile(startBakPath.TrimEnd('\\'), TransferCopyPath.TrimEnd('\\'), folderPathConvertExtensionForLocalList, fileExtensionList, paraTransferTime, MTNum, RNum, WNum); } // // 特別処理 foreach (string dirPathKey in fileSetInfo.DirectoryPathList) { if (!objectPath.Equals(dirPathKey)) { // コピー元 string copyExtensionSrcPath = PathFileConvert(paraMonitorRootDirectory, startSrcPath, dirPathKey); // コピー先 string copyExtensionTargetPath = PathFileConvert(paraMonitorRootDirectory, startBakPath, dirPathKey); // List <string> fileSubExtensionList = fileSetInfo.DirectoryFileExtensionList[dirPathKey] as List <string>; // ローカルコピー CopyListenExclusionFile(copyExtensionSrcPath.TrimEnd('\\'), copyExtensionTargetPath.TrimEnd('\\'), fileSubExtensionList, paraCopyListenTime, MTNum, RNum, WNum); // Thread.Sleep(10000); // 転送コピー for (int j = 0; j < backupServerGroupDetailList.Count; j++) { backupServer backupServer = backupServerManager.GetBackupServerInfo(backupServerGroupDetailList[j].backupServerID); string TransferCopyPath = @"\\" + backupServer.backupServerIP + @"\" + backupServer.startFile.TrimStart('\\'); // 転送先 string TransferTargetPath = PathFileConvert(startBakPath, TransferCopyPath, copyExtensionTargetPath); CopyListenExclusionFile(startBakPath.TrimEnd('\\'), TransferCopyPath.TrimEnd('\\'), fileSubExtensionList, paraTransferTime, MTNum, RNum, WNum); } } } } else { // 特別処理 foreach (string dirPathKey in fileSetInfo.DirectoryPathList) { // コピー元 string copyExtensionSrcPath = PathFileConvert(paraMonitorRootDirectory, startSrcPath, dirPathKey); // コピー先 string copyExtensionTargetPath = PathFileConvert(paraMonitorRootDirectory, startBakPath, dirPathKey); // List <string> fileExtensionList = fileSetInfo.DirectoryFileExtensionList[dirPathKey] as List <string>; // ローカルコピー CopyListenExclusionFile(copyExtensionSrcPath.TrimEnd('\\'), copyExtensionTargetPath.TrimEnd('\\'), fileExtensionList, paraCopyListenTime, MTNum, RNum, WNum); // Thread.Sleep(10000); // 転送コピー for (int j = 0; j < backupServerGroupDetailList.Count; j++) { backupServer backupServer = backupServerManager.GetBackupServerInfo(backupServerGroupDetailList[j].backupServerID); string TransferCopyPath = @"\\" + backupServer.backupServerIP + @"\" + backupServer.startFile.TrimStart('\\'); // 転送先 string TransferTargetPath = PathFileConvert(startBakPath, TransferCopyPath, copyExtensionTargetPath); CopyListenExclusionFile(startBakPath.TrimEnd('\\'), TransferCopyPath.TrimEnd('\\'), fileExtensionList, paraTransferTime, MTNum, RNum, WNum); } } // // ローカルコピー // ファイル除外リスト List <string> fileExtensionNullList = new List <string>(); CopyListenExclusionFolderFile(copySrcPath.TrimEnd('\\'), copyTargetPath.TrimEnd('\\'), folderPathConvertExtensionList, fileExtensionNullList, paraCopyListenTime, MTNum, RNum, WNum); // Thread.Sleep(10000); // 転送コピー for (int j = 0; j < backupServerGroupDetailList.Count; j++) { backupServer backupServer = backupServerManager.GetBackupServerInfo(backupServerGroupDetailList[j].backupServerID); string TransferCopyPath = @"\\" + backupServer.backupServerIP + @"\" + backupServer.startFile.TrimStart('\\'); // 転送先 string TransferTargetPath = PathFileConvert(startBakPath, TransferCopyPath, copyTargetPath); CopyListenExclusionFolderFile(startBakPath.TrimEnd('\\'), TransferCopyPath.TrimEnd('\\'), folderPathConvertExtensionForLocalList, fileExtensionNullList, paraTransferTime, MTNum, RNum, WNum); } } } else { // ローカルコピー CopyListen(copySrcPath.TrimEnd('\\'), copyTargetPath.TrimEnd('\\'), paraCopyListenTime, MTNum, RNum, WNum); // Thread.Sleep(10000); // 転送コピー for (int j = 0; j < backupServerGroupDetailList.Count; j++) { backupServer backupServer = backupServerManager.GetBackupServerInfo(backupServerGroupDetailList[j].backupServerID); string TransferCopyPath = @"\\" + backupServer.backupServerIP + @"\" + backupServer.startFile.TrimStart('\\'); // 転送先 string TransferTargetPath = PathFileConvert(startBakPath, TransferCopyPath, copyTargetPath); CopyListen(startBakPath.TrimEnd('\\'), TransferCopyPath.TrimEnd('\\'), paraTransferTime, MTNum, RNum, WNum); } } } } catch (Exception e) { logger.Error(monitorPathlist[i].monitorFilePath + e.Message); continue; } } } } catch (Exception e) { logger.Error(e.Message); } }