<commit_before>#!/bin/bash

set -euo pipefail

#
# Replicate backdrop mongo db from a source host to a target host.
# Useful to import data from the preview environment to the development
# one.
#

if [ "$(hostname)" == "development-1" ]; then
    echo "This script should be run on the host machine, not your virtual machine!"
    exit 1
fi

if [ "$(basename $(pwd))" != 'tools' ]; then
    echo "This script should be run from the backdrop/tools directory!"
    exit
fi


if [ $# -lt 1 ]; then
    echo "The script requires at least one argument."
    echo
    echo "Replicate backdrop data from a source host to a target host."
    echo
    echo "Usage:"
    echo "  $(basename $0) <user@source_host> [<target_host>]"
    echo
    echo "Example:"
    echo "  $(basename $0) youruser@postgresql dev.machine"
    echo "    This will run restore on the host machine against the specified target host"
    echo "  $(basename $0) youruser@postgresql"
    echo "    This will run restore from within the development VM"
    echo

    exit 2
fi


set +u
SOURCE_HOST=$1
DESTINATION_HOST=$2
set -u

DATE=$(date +'%Y%m%d-%H%M%S')
FILENAME="stagecraft-$DATE.tar.gz"

set -x

ssh -t $SOURCE_HOST "sudo su postgres -c \"cd && pg_dumpall --database=stagecraft --clean --oids | gzip > /tmp/${FILENAME}\""
scp $SOURCE_HOST:/tmp/$FILENAME .
ssh $SOURCE_HOST "sudo su postgres -c \"rm /tmp/${FILENAME}\""

if [ -z "$DESTINATION_HOST" ]
then
    pushd ../../pp-puppet
    vagrant ssh development-1 -c "cd /var/apps/stagecraft/tools && sudo service collectd stop && sudo su postgres -c \"gunzip -c ${FILENAME} | psql\" -- -t && sudo service collectd start"
    popd
else
    echo "Remote restore has not been implemented yet."
fi

#rm $FILENAME
<commit_msg>squash-me reset password<commit_after>#!/bin/bash

set -euo pipefail

#
# Replicate backdrop mongo db from a source host to a target host.
# Useful to import data from the preview environment to the development
# one.
#

if [ "$(hostname)" == "development-1" ]; then
    echo "This script should be run on the host machine, not your virtual machine!"
    exit 1
fi

if [ "$(basename $(pwd))" != 'tools' ]; then
    echo "This script should be run from the backdrop/tools directory!"
    exit
fi


if [ $# -lt 1 ]; then
    echo "The script requires at least one argument."
    echo
    echo "Replicate backdrop data from a source host to a target host."
    echo
    echo "Usage:"
    echo "  $(basename $0) <user@source_host> [<target_host>]"
    echo
    echo "Example:"
    echo "  $(basename $0) youruser@postgresql dev.machine"
    echo "    This will run restore on the host machine against the specified target host"
    echo "  $(basename $0) youruser@postgresql"
    echo "    This will run restore from within the development VM"
    echo

    exit 2
fi


set +u
SOURCE_HOST=$1
DESTINATION_HOST=$2
set -u

DATE=$(date +'%Y%m%d-%H%M%S')
FILENAME="stagecraft-$DATE.tar.gz"

set -x

ssh -t $SOURCE_HOST "sudo su postgres -c \"cd && pg_dumpall --database=stagecraft --clean --oids | gzip > /tmp/${FILENAME}\""
scp $SOURCE_HOST:/tmp/$FILENAME .
ssh $SOURCE_HOST "sudo su postgres -c \"rm /tmp/${FILENAME}\""

if [ -z "$DESTINATION_HOST" ]
then
    pushd ../../pp-puppet
    vagrant ssh development-1 -c "cd /var/apps/stagecraft/tools && sudo service collectd stop && sudo su postgres -c \"gunzip -c ${FILENAME} | psql\" -- -t && sudo service collectd start"
    vagrant ssh development-1 -c "sudo su postgres -c \"psql -c \\\"ALTER ROLE stagecraft WITH PASSWORD '<PASSWORD>8'\\\"\" -- -t"
    popd
else
    echo "Remote restore has not been implemented yet."
fi

#rm $FILENAME

{'fraction_non_alphanumeric': 0.12755383765875208, 'fraction_numerical': 0.006073992269464384, 'mean_word_length': 3.150057273768614, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 10, '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': '882236', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1179, 'n_words': 451}