internal void RestoreData(DateTime?fromDay, DateTime?toDay, RestoreStatus theRuningStatusInSession) { //备份源数据库 TransferService.StartLittleProcess(theRuningStatusInSession, string.Format("{0}{1}", Utility._Process_BackUpDb, _DbName)); string targetName = string.Format("{0}{1}{2}.bak", DiskOperations.DbBackUp_ForRestoreDirectory, _DbName, Utility.GetTimeStamp()); SqlCommandRunner.BackUpDb(_DbName, targetName); //删减数据库备份 TransferService.StartLittleProcess(theRuningStatusInSession, string.Format("{0}", Utility._Process_DelNonuseDbBackUp)); theRuningStatusInSession.AddInformationLine(DiskOperations.DelFilesFromDirectory(DiskOperations.DbBackUp_ForRestoreDirectory, _DbName, targetName, _DefaultBackUpDbCount)); //拷贝下载的数据库用于数据还原 string copyDbName = _DbName + _ForRestoreCopyDbSuffix; string downLoadDbBackUpFullName = string.Format("{0}{1}{2}.bak", DiskOperations.DataTemp_ForRestoreDirectory, _DbName, _OrginCopyDbSuffix); TransferService.StartLittleProcess(theRuningStatusInSession, string.Format("{0}{1}", Utility._Process_CopyDb, copyDbName)); SqlCommandRunner.RestoreDbFromFile(copyDbName, DiskOperations.TempDirectory, downLoadDbBackUpFullName); //每一个表的数据还原 foreach (TableTransfer tt in _TablesToTransfer) { tt.RestoreData(fromDay, toDay, theRuningStatusInSession); } //删除无用的数据库拷贝 TransferService.StartLittleProcess(theRuningStatusInSession, string.Format("{0}{1}", Utility._Process_DelNonUseDb, copyDbName)); SqlCommandRunner.DeleteDb(copyDbName); }
internal void BackUpData(DateTime?fromDay, DateTime?toDay, RunningStatus theRuningStatusInSession) { //备份源数据库 TransferService.StartLittleProcess(theRuningStatusInSession, string.Format("{0}{1}", Utility._Process_BackUpDb, _DbName)); string targetName = string.Format("{0}{1}{2}.bak", DiskOperations.DbBackUp_ForBackUpDirectory, _DbName, Utility.GetTimeStamp()); SqlCommandRunner.BackUpDb(_DbName, targetName); //删减数据库备份 TransferService.StartLittleProcess(theRuningStatusInSession, string.Format("{0}", Utility._Process_DelNonuseDbBackUp)); theRuningStatusInSession.AddInformationLine(DiskOperations.DelFilesFromDirectory(DiskOperations.DbBackUp_ForBackUpDirectory, _DbName, targetName, _DefaultBackUpDbCount)); //拷贝数据库用于数据筛选 string copyDbName = _DbName + _OrginCopyDbSuffix; TransferService.StartLittleProcess(theRuningStatusInSession, string.Format("{0}{1}", Utility._Process_CopyDb, copyDbName)); SqlCommandRunner.RestoreDbFromFile(copyDbName, DiskOperations.TempDirectory, targetName); //删除无用的表 TransferService.StartLittleProcess(theRuningStatusInSession, Utility._Process_DelNonUseTable); theRuningStatusInSession.AddInformationLine(DropNonUseTable(copyDbName)); //有用表数据筛选 foreach (TableTransfer tt in _TablesToTransfer) { tt.BackUpData(fromDay, toDay, theRuningStatusInSession); } //将筛选完毕的数据库备份到指定地点用于打包压缩 TransferService.StartLittleProcess(theRuningStatusInSession, string.Format("{0}{1}", Utility._Process_BackUpFiltedTable, copyDbName)); BackUpFilteredDb(copyDbName); //删除无用的数据库拷贝 TransferService.StartLittleProcess(theRuningStatusInSession, string.Format("{0}{1}", Utility._Process_DelNonUseDb, copyDbName)); SqlCommandRunner.DeleteDb(copyDbName); }
internal void TryRestoreErrorClean() { SqlCommandRunner.DeleteDb(_DbName + _ForRestoreCopyDbSuffix); }
internal void TryBackUpErrorClean() { SqlCommandRunner.DeleteDb(_DbName + _OrginCopyDbSuffix); }