<commit_before>#!/bin/bash

DUMP_ROOT_FOLDER="./.dump"
DB_WAIT_TIME=10

LOCAL_DB_PORT=3000
LOCAL_DB_HOST=127.0.0.1
LOCAL_DB_NAME=meteor

function db-copy_help {
  cat << EOF
Copy remote database

boo db-copy server_type [-d|--dump] [-v|--verbose] [--no-drop|-D] [--no-hook|-H]

Options:
-d  - use previously created dump
-v  - verbose mode (print all logs)
--no-hook  - prevent post restore hook execution
--no-drop  - prevent database drop before restore
EOF
}


function db-copy {
  local server_name=$1
  source_deploy_conf ${server_name}

  local local_db_path=$(pwd)/.meteor/local/db

  local output_stream=/dev/null
  local drop_flag="--drop"
  local use_dump=0
  local run_post_hook=1

  # parse script arguments
  while [[ $(($#-1)) -gt 0 ]]; do
    local key="$2"

    case ${key} in
      --no-drop|-D)
      drop_flag=""
      echo "Prevent database drop: YES"
      ;;
      --no-hook|-H)
      run_post_hook=0
      echo "Prevent post dump hook: YES"
      ;;
      -d|--dump)
      use_dump=1
      echo "Use local dump: YES"
      ;;
      -v|--verbose)
      output_stream="/dev/stdout"
      ;;
      *)
      echo_error "Unknown option ${key}"
      exit 1
      ;;
    esac

    shift # past argument or value
  done

  printf "Selected database of '${COLOR_SUCCESS}${SERVER_DESCRIPTION}${COLOR_DEFAULT}'\n"

  # remove old database instead of `meteor reset`
  echo "Removing local database..."
  rm -rf .meteor/local/db
  mkdir -p .meteor/local/db ${DUMP_ROOT_FOLDER}

  if [[ ${use_dump} != 1 ]]; then
    # refresh dump
    rm -rf "${DUMP_ROOT_FOLDER}/${MONGO_DB}"
    echo "Making remote database dump. Please, wait..."
    mongodump -u "${MONGO_USER}" -h "${MONGO_HOST}" -d "${MONGO_DB}" -p "${MONGO_PASSWORD}" \
      -o "${DUMP_ROOT_FOLDER}" &> ${output_stream}
  fi

  local dump_folder="${DUMP_ROOT_FOLDER}/${MONGO_DB}"

  # check if dump exists
  if [[ ! -d ${dump_folder} ]]; then
    echo_error "Dump '${dump_folder}' doesn't exists!"
    exit 1
  fi

  # find out if current release supports MongoDB's WiredTiger storage engine
  local storage_engine_option="--storageEngine=mmapv1"
  if grep -q "METEOR@1.4" ./.meteor/release; then
    echo_success "Using WiredTiger storage engine"
    storage_engine_option=""
  fi

  echo "Starting local database ..."
  mongod --dbpath="${local_db_path}" --port="${LOCAL_DB_PORT}" ${storage_engine_option} \
    --nojournal > ${output_stream} &
<commit_msg>Force wiredTiger for MongoDB 3.0.x<commit_after>#!/bin/bash

DUMP_ROOT_FOLDER="./.dump"
DB_WAIT_TIME=10

LOCAL_DB_PORT=3000
LOCAL_DB_HOST=127.0.0.1
LOCAL_DB_NAME=meteor

function db-copy_help {
  cat << EOF
Copy remote database

boo db-copy server_type [-d|--dump] [-v|--verbose] [--no-drop|-D] [--no-hook|-H]

Options:
-d  - use previously created dump
-v  - verbose mode (print all logs)
--no-hook  - prevent post restore hook execution
--no-drop  - prevent database drop before restore
EOF
}


function db-copy {
  local server_name=$1
  source_deploy_conf ${server_name}

  local local_db_path=$(pwd)/.meteor/local/db

  local output_stream=/dev/null
  local drop_flag="--drop"
  local use_dump=0
  local run_post_hook=1

  # parse script arguments
  while [[ $(($#-1)) -gt 0 ]]; do
    local key="$2"

    case ${key} in
      --no-drop|-D)
      drop_flag=""
      echo "Prevent database drop: YES"
      ;;
      --no-hook|-H)
      run_post_hook=0
      echo "Prevent post dump hook: YES"
      ;;
      -d|--dump)
      use_dump=1
      echo "Use local dump: YES"
      ;;
      -v|--verbose)
      output_stream="/dev/stdout"
      ;;
      *)
      echo_error "Unknown option ${key}"
      exit 1
      ;;
    esac

    shift # past argument or value
  done

  printf "Selected database of '${COLOR_SUCCESS}${SERVER_DESCRIPTION}${COLOR_DEFAULT}'\n"

  # remove old database instead of `meteor reset`
  echo "Removing local database..."
  rm -rf .meteor/local/db
  mkdir -p .meteor/local/db ${DUMP_ROOT_FOLDER}

  if [[ ${use_dump} != 1 ]]; then
    # refresh dump
    rm -rf "${DUMP_ROOT_FOLDER}/${MONGO_DB}"
    echo "Making remote database dump. Please, wait..."
    mongodump -u "${MONGO_USER}" -h "${MONGO_HOST}" -d "${MONGO_DB}" -p "${MONGO_PASSWORD}" \
      -o "${DUMP_ROOT_FOLDER}" &> ${output_stream}
  fi

  local dump_folder="${DUMP_ROOT_FOLDER}/${MONGO_DB}"

  # check if dump exists
  if [[ ! -d ${dump_folder} ]]; then
    echo_error "Dump '${dump_folder}' doesn't exists!"
    exit 1
  fi

  # find out if current release supports MongoDB's WiredTiger storage engine
  local storage_engine_option="mmapv1"
  if grep -q "METEOR@1.4" ./.meteor/release; then
    echo_success "Using WiredTiger storage engine"
    storage_engine_option="wiredTiger"
  fi

  echo "Starting local database ..."
  mongod --dbpath="${local_db_path}" --port="${LOCAL_DB_PORT}" --storageEngine=${storage_engine_option} \
    --nojournal > ${output_stream} &

{'fraction_non_alphanumeric': 0.14575230296827021, 'fraction_numerical': 0.01105424769703173, 'mean_word_length': 2.9950940310711367, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3896098', 'n_tokens_mistral': 1837, 'n_tokens_neox': 1713, 'n_words': 436}