def do_restore(conn, sleep_interval, source_table, destination_table, write_capacity):
  logging.info("Starting restore for " + source_table + " to " + destination_table + "..")

  # create table using schema
  # restore source_table from dump directory if it exists else try current working directory
  if os.path.exists("%s/%s" % (DUMP_PATH, source_table)):
    dump_data_path = DUMP_PATH
  else:
    logging.info("Cannot find \"./%s/%s\", Now trying current working directory.." % (DUMP_PATH, source_table))
    if os.path.exists("%s/%s" % (CURRENT_WORKING_DIR, source_table)):
      dump_data_path = CURRENT_WORKING_DIR
    else:
      logging.info("Cannot find \"%s/%s\" directory containing dump files!" % (CURRENT_WORKING_DIR, source_table))
      sys.exit(1)
  table_data = json.load(open(dump_data_path + "/" + source_table + "/" + SCHEMA_FILE))
  table = table_data["Table"]
  table_attribute_definitions = table["AttributeDefinitions"]
  table_table_name = destination_table
  table_key_schema = table["KeySchema"]
  original_read_capacity = table["ProvisionedThroughput"]["ReadCapacityUnits"]
  original_write_capacity = table["ProvisionedThroughput"]["WriteCapacityUnits"]
  table_local_secondary_indexes = table.get("LocalSecondaryIndexes")
  table_global_secondary_indexes = table.get("GlobalSecondaryIndexes")

  if not args.dataOnly:
    # override table write capacity if specified, else use RESTORE_WRITE_CAPACITY if original write capacity is lower
    if write_capacity == None:
      if original_write_capacity < RESTORE_WRITE_CAPACITY:
        write_capacity = RESTORE_WRITE_CAPACITY
      else:
        write_capacity = original_write_capacity

    # override GSI write capacities if specified, else use RESTORE_WRITE_CAPACITY if original write capacity is lower
    original_gsi_write_capacities = []
    if table_global_secondary_indexes is not None:
      for gsi in table_global_secondary_indexes:
        original_gsi_write_capacities.append(gsi["ProvisionedThroughput"]["WriteCapacityUnits"])

        if gsi["ProvisionedThroughput"]["WriteCapacityUnits"] < int(write_capacity):
          gsi["ProvisionedThroughput"]["WriteCapacityUnits"] = int(write_capacity)

    # temp provisioned throughput for restore
    table_provisioned_throughput = {"ReadCapacityUnits": int(original_read_capacity), "WriteCapacityUnits": int(write_capacity)}

    logging.info("Creating " + destination_table + " table with temp write capacity of " + str(write_capacity))

    while True:
      try:
        conn.create_table(table_attribute_definitions, table_table_name, table_key_schema, table_provisioned_throughput, table_local_secondary_indexes, table_global_secondary_indexes)
        break
      except boto.exception.JSONResponseError, e:
        if e.body["__type"] == "com.amazonaws.dynamodb.v20120810#LimitExceededException":
          logging.info("Limit exceeded, retrying creation of " + destination_table + "..")
          time.sleep(sleep_interval)
        elif e.body["__type"] == "com.amazon.coral.availability#ThrottlingException":
          logging.info("Control plane limit exceeded, retrying creation of " + destination_table + "..")
          time.sleep(sleep_interval)
        else:
          logging.exception(e)
          sys.exit(1)

    # wait for table creation completion
    wait_for_active_table(conn, destination_table, "created")

  # read data files
  logging.info("Restoring data for " + destination_table + " table..")
  data_file_list = os.listdir(dump_data_path + "/" + source_table + "/" + DATA_DIR + "/")
  data_file_list.sort()

  for data_file in data_file_list:
    logging.info("Processing " + data_file + " of " + destination_table)
    items = []
    item_data = json.load(open(dump_data_path + "/" + source_table + "/" + DATA_DIR + "/" + data_file))
    items.extend(item_data["Items"])

    # batch write data
    put_requests = []
    while len(items) > 0:
      put_requests.append({"PutRequest": {"Item": items.pop(0)}})

      # flush every MAX_BATCH_WRITE
      if len(put_requests) == MAX_BATCH_WRITE:
        logging.debug("Writing next " + str(MAX_BATCH_WRITE) + " items to " + destination_table + "..")
        batch_write(conn, sleep_interval, destination_table, put_requests)
        del put_requests[:]

    # flush remainder
    if len(put_requests) > 0:
      batch_write(conn, sleep_interval, destination_table, put_requests)

  if not args.dataOnly and not args.skipThroughputUpdate:
    # revert to original table write capacity if it has been modified
    if write_capacity != original_write_capacity:
      update_provisioned_throughput(conn, destination_table, original_read_capacity, original_write_capacity, False)

    # loop through each GSI to check if it has changed and update if necessary
    if table_global_secondary_indexes is not None:
      gsi_data = []
      for gsi in table_global_secondary_indexes:
        original_gsi_write_capacity = original_gsi_write_capacities.pop(0)
        if original_gsi_write_capacity != gsi["ProvisionedThroughput"]["WriteCapacityUnits"]:
          gsi_data.append({"Update": { "IndexName" : gsi["IndexName"], "ProvisionedThroughput": { "ReadCapacityUnits": int(gsi["ProvisionedThroughput"]["ReadCapacityUnits"]), "WriteCapacityUnits": int(original_gsi_write_capacity),},},})

      logging.info("Updating " + destination_table + " global secondary indexes write capacities as necessary..")
      while True:
        try:
          conn.update_table(destination_table, global_secondary_index_updates=gsi_data)
          break
        except boto.exception.JSONResponseError, e:
          if e.body["__type"] == "com.amazonaws.dynamodb.v20120810#LimitExceededException":
            logging.info("Limit exceeded, retrying updating throughput of GlobalSecondaryIndexes in " + destination_table + "..")
            time.sleep(sleep_interval)
          elif e.body["__type"] == "com.amazon.coral.availability#ThrottlingException":
            logging.info("Control plane limit exceeded, retrying updating throughput of GlobalSecondaryIndexes in " + destination_table + "..")
            time.sleep(sleep_interval)

  logging.info("Restore for " + source_table + " to " + destination_table + " table completed. Time taken: " + str(datetime.datetime.now().replace(microsecond=0) - start_time))

# parse args
dataset/ETHPy150Open bchew/dynamodump/dynamodump.py/do_restore/original