<commit_before>#!/bin/bash
set -e

# Call this script like: backup_postgres.sh docker_ocpg_1 /path/to/file.backup
# Where "docker_ocpg_1" is the container name.

# Create a new directory with the same name as the container argument.
mkdir -p backups/$1
cd backups/$1

# Restore a pg_dump custom format file into a postgres container.
#
# Steps:
# - Copy backup file from host into container.
# - Give ownership of backup file to container postgres user.
# - Restore the backup into postgres.
# - Remove the backup file.
docker cp $2 $1:/tmp/pg_restore.backup
docker exec $1 bash -c 'chown -R postgres /tmp/pg_restore.backup; \
    chmod 700 /tmp/pg_restore.backup; \
    export PGPASSWORD="$<PASSWORD>"; \
    gosu postgres pg_restore -U "$POSTGRES_USER" -d "$OC_DATABASE" -Ocw \
    --role="$OC_USER" -j 4 -F c /tmp/pg_restore.backup; \
    rm /tmp/pg_restore.backup'<commit_msg>add configuration restore and optional restart for postgres<commit_after>#!/bin/bash
set -e

# Call this script like: restore_postgres.sh docker_ocpg_1 /path/to/folder/ x
# Where "docker_ocpg_1" is the container name.
# Where /path/to/folder contains the configs to drop into $PGDATA, and backup file.
# - The configs may include postgresql.conf, pg_hba.conf, pg_ident.conf.
# - The backup file should be named openclinica.backup.
# Where "x" prevents restart; if ommited the container will be restarted.

# Restore a pg_dump custom format file into a postgres container.
#
# Steps:
# - Copy backup directory from host into container.
# - Copy backup files into $PGDATA.
# - Give ownership of backup file to container postgres user.
# - Restore the backup into postgres.
# - Remove the backup directory.
# - Restart the container if there are only 2 positional parameters given.
docker cp $2 $1:/tmp/pg_restore
docker exec $1 bash -c 'chown -R postgres /tmp/pg_restore; \
    chmod -R 700 /tmp/pg_restore; \
    export PGPASSWORD="$<PASSWORD>"; \
    gosu postgres pg_restore -U "$POSTGRES_USER" -d "$OC_DATABASE" -Ocw \
    --role="$OC_USER" -j 4 -F c /tmp/pg_restore/openclinica.backup; \
    cp /tmp/pg_restore/*.conf $PGDATA; \
    chown postgres $PGDATA/*.conf; \
    chmod 700 $PGDATA/*.conf; \
    rm -rf /tmp/pg_restore'
if [ $# -eq 2 ]; then
    docker restart $1
fi

{'fraction_non_alphanumeric': 0.10904255319148937, 'fraction_numerical': 0.01152482269503546, 'mean_word_length': 3.4341846758349703, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2247383', 'n_tokens_mistral': 784, 'n_tokens_neox': 746, 'n_words': 268}