Skip to content

Commit

Permalink
Add Scripts to Import/ Export Datasets (#11)
Browse files Browse the repository at this point in the history
Co-authored-by: Logan L <[email protected]>
  • Loading branch information
Zalgo2462 and Logan L authored Jul 9, 2020
1 parent ada8c77 commit 3b3115d
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
11 changes: 10 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,13 @@ services:
volumes:
- ${BEAKER_CONFIG_DIR:-/etc/BeaKer/}certificates:/usr/share/kibana/config/certificates
depends_on:
- elasticsearch
- elasticsearch

es-dump:
image: taskrabbit/elasticsearch-dump:v6.28.0
restart: "no"
environment:
- NODE_TLS_REJECT_UNAUTHORIZED=0
depends_on:
- elasticsearch
entrypoint: ["/bin/true"]
37 changes: 37 additions & 0 deletions elasticsearch/export_index.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

# Grab input arguments
if [ "$#" -ne 2 ]; then
echo "Usage: ./export_index.sh index_to_save output/directory"
exit 1
fi

index_name="$1"
output_dir=`realpath "$2"`

# Change dir to script parent dir after calling realpath on the output directory
pushd "$(dirname "${BASH_SOURCE[0]}")/.." > /dev/null

# Use main function for local vars to hold sensitive info
main() {

mkdir -p "$output_dir/$index_name"


local username=""
IFS="" read -es -p "Elasticsearch Username: " username
echo ""
local password=""
IFS="" read -es -p "Elasticsearch Password: " password
echo ""

./beaker run -v "$output_dir/$index_name:/exports:rw" --entrypoint multielasticdump es-dump --input="https://$username:$password@elasticsearch:9200" --output="/exports" --includeType="data,mapping" --match="^$index_name\$"

tar -C "$output_dir" -czf "$output_dir/$index_name.tar.gz" "$index_name"
rm -rf "$output_dir/$index_name"
}

main

# Change back to original directory
popd > /dev/null
36 changes: 36 additions & 0 deletions elasticsearch/import_index.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash

# Grab input arguments
if [ "$#" -ne 1 ]; then
echo "Usage: ./import_index.sh path/to/archive.tar"
exit 1
fi

input_tar=`realpath "$1"`

# Change dir to script parent dir after calling realpath on the output directory
pushd "$(dirname "${BASH_SOURCE[0]}")/.." > /dev/null

# Use main function for local vars to hold sensitive info
main() {
local input_tar_dir=`dirname "$input_tar"`
local index_name=`tar --exclude='*/*' -tf "$input_tar"`

tar -xf "$input_tar" -C "$input_tar_dir"
local index_dir="$input_tar_dir/$index_name"

local username=""
IFS="" read -es -p "Elasticsearch Username: " username
echo ""
local password=""
IFS="" read -es -p "Elasticsearch Password: " password
echo ""
./beaker run -v "$index_dir:/$index_name" --entrypoint multielasticdump es-dump --direction=load --input="/$index_name" --output="https://$username:$password@elasticsearch:9200"

rm -rf "$index_dir"
}

main

# Change back to original directory
popd > /dev/null
1 change: 1 addition & 0 deletions installer/stage/BeaKer/elasticsearch/export_index.sh
1 change: 1 addition & 0 deletions installer/stage/BeaKer/elasticsearch/import_index.sh

0 comments on commit 3b3115d

Please sign in to comment.