-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Scripts to Import/ Export Datasets (#11)
Co-authored-by: Logan L <[email protected]>
- Loading branch information
Showing
5 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../elasticsearch/export_index.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../elasticsearch/import_index.sh |