public async Task <ViewResultBase> Edit(NullableIdInput <Guid> input) { var database = new SystemDataBase(); if (!input.Id.IsNullOrEmptyGuid()) { database = await _dataBaseLogic.GetByIdAsync(input.Id); } return(View(database)); }
/// <summary> /// 数据库还原 /// </summary> /// <param name="doubleWay"></param> /// <returns></returns> public async Task <OperateStatus> SystemDataBaseRestore(SystemDataBaseBackUpDoubleWay doubleWay) { OperateStatus operateStatus = new OperateStatus(); SystemDataBaseBackUp baseBackUp = await GetByIdAsync(doubleWay.Id); SystemDataBase systemDataBase = await _systemDataBaseRepository.GetByIdAsync(baseBackUp.DataBaseId); //开始进行数据库备份操作 DbBackUpAndRestore.Uid = systemDataBase.UserId; DbBackUpAndRestore.Database = systemDataBase.CatalogName; DbBackUpAndRestore.Pwd = systemDataBase.Password; DbBackUpAndRestore.Server = systemDataBase.DataSource; DbBackUpAndRestore.BackUpOrRestorePath = baseBackUp.Path; //程序根目录地址 try { //查询所有备份表信息 IList <SystemDataBaseBackUp> dataBaseBackUps = (await GetAllEnumerableAsync()).ToList(); if (DbBackUpAndRestore.Operate(false)) { //删除备份表 await DeleteAllAsync(); //更换备份表还原时间 var ups = dataBaseBackUps.Where(s => s.BackUpId == baseBackUp.BackUpId).FirstOrDefault(); if (ups != null) { ups.RestoreTime = DateTime.Now; } //批量插入备份表信息 operateStatus = await InsertMultipleAsync(dataBaseBackUps); } else { operateStatus.Message = Chs.Error; } } catch (Exception ex) { operateStatus.Message = ex.Message; } return(operateStatus); }
/// <summary> /// 数据库备份 /// </summary> /// <param name="doubleWay"></param> /// <returns></returns> public async Task <OperateStatus> SystemDataBaseBackUp(SystemDataBaseBackUpDoubleWay doubleWay) { OperateStatus operateStatus = new OperateStatus(); SystemDataBase systemDataBase = await _systemDataBaseRepository.GetByIdAsync(doubleWay.DataBaseId); string bakPath = "\\DataUsers\\DataBaseBackUps\\" + systemDataBase.CatalogName + DateTime.Now.ToString("yyyyMMddhhssmm") + ".bak"; //开始进行数据库备份操作 DbBackUpAndRestore.Uid = systemDataBase.UserId; DbBackUpAndRestore.Database = systemDataBase.CatalogName; DbBackUpAndRestore.Pwd = systemDataBase.Password; DbBackUpAndRestore.Server = systemDataBase.DataSource; DbBackUpAndRestore.BackUpOrRestorePath = doubleWay.BackUpOrRestorePath + bakPath; //程序根目录地址 try { if (DbBackUpAndRestore.Operate()) { //添加备份记录 SystemDataBaseBackUp backUp = new SystemDataBaseBackUp() { BackUpId = CombUtil.NewComb(), BackUpTime = DateTime.Now, DataBaseId = doubleWay.DataBaseId, From = (byte)EnumFrom.手动, Name = systemDataBase.CatalogName + DateTime.Now.ToString("yyyyMMddhhssmm") + ".bak", Path = DbBackUpAndRestore.BackUpOrRestorePath, Size = FileUtil.GetFileSize(DbBackUpAndRestore.BackUpOrRestorePath) }; operateStatus = await InsertAsync(backUp); } else { operateStatus.Message = Chs.Error; } } catch (Exception ex) { operateStatus.Message = ex.Message; } return(operateStatus); }
public async Task <JsonResult> SaveDataBase(SystemDataBase dataBase) { return(Json(await _dataBaseLogic.SaveDataBase(dataBase))); }