Example #1
0
  /**
   * 重置(还原出厂设置)
   *
   * @param error
   * @return
   */
  public static int reset(ErrorInfo error) {
    error.clear();

    String backupFileName = backup(false, error);

    if (null == backupFileName) {
      return error.code;
    }

    if (0 != createOperation(DBOperationType.RESET, backupFileName, error)) {
      return error.code;
    }

    DealDetail.supervisorEvent(
        Supervisor.currSupervisor().id, SupervisorEvent.DB_RESET, "还原出厂初始数据", error);

    if (error.code < 0) {
      JPA.setRollbackOnly();

      return error.code;
    }

    if (0
        != MySQLTool.executeSqlFile(
            username, password, host, port, database, resetFileName, error)) {
      JPA.setRollbackOnly();

      return error.code;
    }

    error.code = 0;
    error.msg = "还原出厂设置成功";

    return error.code;
  }
Example #2
0
  /**
   * 还原数据库
   *
   * @param fileName
   * @param error
   * @return
   */
  public static int recover(String fileName, ErrorInfo error) {
    error.clear();

    if (StringUtils.isBlank(fileName)) {
      error.code = -1;
      error.msg = "恢复文件不能为空";

      return error.code;
    }

    String backupFileName = backup(false, error);

    if (null == backupFileName) {
      return error.code;
    }

    if (0 != createOperation(DBOperationType.RECOVER, backupFileName, error)) {
      return error.code;
    }

    DealDetail.supervisorEvent(
        Supervisor.currSupervisor().id, SupervisorEvent.DB_RECOVER, "还原运营数据", error);

    if (error.code < 0) {
      JPA.setRollbackOnly();

      return error.code;
    }

    String decryptFileName = Constants.SQL_PATH + UUID.randomUUID().toString() + ".sql";

    if (!FileEncrypt.decrypt(fileName, decryptFileName, Constants.ENCRYPTION_KEY)) {
      error.code = -1;
      error.msg = "还原数据库失败";

      return error.code;
    }

    if (0
        != MySQLTool.executeSqlFile(
            username, password, host, port, database, decryptFileName, error)) {
      JPA.setRollbackOnly();

      return error.code;
    }

    if (!new File(decryptFileName).delete()) {
      error.code = -1;
      error.msg = "还原数据库失败";

      return error.code;
    }

    error.code = 0;
    error.msg = "还原数据库成功";

    return error.code;
  }