Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Scripts to Import/ Export Datasets #11

Merged
merged 4 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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