<commit_before>#!/usr/bin/env bash

# Generated by Chef

# ./usr/local/openvpn_as/scripts/sqlite3 <[TEXT_FILE] [DB_FILE]

# /usr/local/openvpn_as/etc
# certs.db
# config.db
# log.db
# userprop.db

OPENVPNAS_DIR=<%= node['openvpnas']['dir'] %>
RESTORE_BUCKET=<%= node['openvpnas']['backup']['bucket'] %>
RESTORE_DIR=/tmp/openvpnas_restore

echo 'starting restore'

# make a temporary restore directory
mkdir -p $RESTORE_DIR
cd $RESTORE_DIR

# download the latest backup
RESTORE_NAME=`aws s3 ls s3://mybucket`
aws s3 cp s3://$RESTORE_BUCKET/$RESTORE_NAME.tar.gz openvpnas-backup.tar.gz

# extract the backup to the temp dir

tar zxf openvpnas-backup.tar.gz .

# stop openvpnas
/etc/init.d/openvpnas stop

# iterate the database files
for DBNAME in *.db
do
  echo "restoring $DBNAME"
  $OPENVPNAS_DIR/scripts/sqlite3 <$DBNAME.dump $DBNAME
done

# start openvpnas
/etc/init.d/openvpnas start

# delete the temporary restore directory
rm -rf $RESTORE_DIR

# create a flag so we know not to restore over top
touch $OPENVPNAS_DIR/RESTORED<commit_msg>fix restore script<commit_after>#!/usr/bin/env bash

# Generated by Chef

# ./usr/local/openvpn_as/scripts/sqlite3 <[TEXT_FILE] [DB_FILE]

# /usr/local/openvpn_as/etc
# certs.db
# config.db
# log.db
# userprop.db

OPENVPNAS_DIR=<%= node['openvpnas']['dir'] %>
RESTORE_BUCKET=<%= node['openvpnas']['backup']['bucket'] %>
RESTORE_DIR=/tmp/openvpnas_restore

echo 'starting restore'

# make a temporary restore directory
mkdir -p $RESTORE_DIR
cd $RESTORE_DIR

# download the latest backup
RESTORE_NAME=$(/usr/local/bin/aws s3 ls s3://$RESTORE_BUCKET | grep -o 'openvpnas-backup[^\n]*' | tail -1)
aws s3 cp s3://$RESTORE_BUCKET/$RESTORE_NAME.tar.gz openvpnas-backup.tar.gz

# extract the backup to the temp dir

tar zxf openvpnas-backup.tar.gz .

# stop openvpnas
/etc/init.d/openvpnas stop

# iterate the database files
for DBNAME in *.db
do
  echo "restoring $DBNAME"
  $OPENVPNAS_DIR/scripts/sqlite3 $OPENVPNAS_DIR/etc/db/$DBNAME < $DBNAME.dump
done

# start openvpnas
/etc/init.d/openvpnas start

# delete the temporary restore directory
rm -rf $RESTORE_DIR

# create a flag so we know not to restore over top
touch $OPENVPNAS_DIR/RESTORED
{'fraction_non_alphanumeric': 0.12648945921173235, 'fraction_numerical': 0.005957836846929423, 'mean_word_length': 4.655440414507772, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3419318', 'n_tokens_mistral': 884, 'n_tokens_neox': 841, 'n_words': 204}