<commit_before>#!/usr/bin/env bash
set -eu

DATADIR="<%= @pg_datadir %>"
SYNCDIR="${DATADIR}.sync"
DATADIR_DELETE="${DATADIR}.todelete"

if [ -z ${DATADIR} ]; then
  echo "DATADIR variable is empty"
  exit 1
fi

if [ "$(id -u)" -ne "0" ]; then
  echo "Please run with sudo"
  exit 1
fi

sudo -u <%= @pg_user %> rm -rf ${SYNCDIR} ${DATADIR_DELETE}
sudo -u <%= @pg_user %> pg_basebackup -vP \
  -h <%= @master_host %> -U <%= @username %> \
  -D ${SYNCDIR}

service postgresql stop

# Files that don't exist in the basebackup and must be retained from the
# slave's original data directory.
sudo -u <%= @pg_user %> mv -t ${SYNCDIR}/ \
  ${DATADIR}/pg_xlog \
  ${DATADIR}/recovery.tmp \
  ${DATADIR}/postmaster.opts

# These exist on Precise/9.1 but not Trusty/9.3
sudo -u <%= @pg_user %> mv -t ${SYNCDIR}/ \
  ${DATADIR}/server.crt \
  ${DATADIR}/server.key \
  || true
<commit_msg>Prevent pg_resync_slave errors on Trusty<commit_after>#!/usr/bin/env bash
set -eu

DATADIR="<%= @pg_datadir %>"
SYNCDIR="${DATADIR}.sync"
DATADIR_DELETE="${DATADIR}.todelete"
FILES_TO_KEEP="
  ${DATADIR}/pg_xlog
  ${DATADIR}/recovery.tmp
  ${DATADIR}/postmaster.opts
  ${DATADIR}/server.crt
  ${DATADIR}/server.key
"

if [ -z ${DATADIR} ]; then
  echo "DATADIR variable is empty"
  exit 1
fi

if [ "$(id -u)" -ne "0" ]; then
  echo "Please run with sudo"
  exit 1
fi

sudo -u <%= @pg_user %> rm -rf ${SYNCDIR} ${DATADIR_DELETE}
sudo -u <%= @pg_user %> pg_basebackup -vP \
  -h <%= @master_host %> -U <%= @username %> \
  -D ${SYNCDIR}

service postgresql stop

# Files that don't exist in the basebackup and must be retained from the
# slave's original data directory.
for FILE in $FILES_TO_KEEP; do
  [ -f $FILE ] && sudo -u postgres mv -t ${SYNCDIR}/ $FILE
done

{'fraction_non_alphanumeric': 0.17613310384394723, 'fraction_numerical': 0.005737234652897304, 'mean_word_length': 3.5654450261780104, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '679398', 'n_tokens_mistral': 740, 'n_tokens_neox': 700, 'n_words': 194}