Skip to content

Commit

Permalink
Converted script to plain sh
Browse files Browse the repository at this point in the history
  • Loading branch information
rimi-itk committed Nov 21, 2024
1 parent 4c054ea commit 450cced
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions data-export/export.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/usr/bin/env bash
set -o errexit -o errtrace -o noclobber -o nounset -o pipefail
IFS=$'\n\t'
#!/usr/bin/env sh

script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
script_dir=$(cd "$(dirname "$0")" && pwd)

function usage() {
usage() {
if [ -n "${1:-}" ]; then
>&2 cat <<EOF
$1
Expand All @@ -13,40 +11,36 @@ EOF
fi

>&2 cat <<EOF
Usage: ${BASH_SOURCE[0]} site-uri
Usage: $0 site-uri
EOF
exit 1
}

if (( $# < 1 )); then
usage "Too few arguments"
fi

site_uri="$1"

if [ -z "$site_uri" ]; then
usage "Invalid site-uri"
usage "Missing site-uri"
fi

# cd "$project_dir"

filenames=("$script_dir"/export_*.sql)
filenames="$script_dir/export_*.sql"

for filename in "${filenames[@]}"; do
for filename in $filenames; do
echo "Running $filename"

# JSON

# https://tldp.org/LDP/abs/html/string-manipulation.html
output_filename=${filename/%.sql/.json}
output_filename="$filename.json"
# https://github.com/drush-ops/drush/issues/3071#issuecomment-347929777
vendor/bin/drush --uri="$site_uri" php:eval "return \Drupal::database()->query(file_get_contents('$filename'))->fetchAll()" --format=json >| "$output_filename" || true
ls -lh "$output_filename"

# CSV

output_filename=${filename/%.sql/.csv}
output_filename="$filename.csv"
# https://stackoverflow.com/a/22421445/2502647
vendor/bin/drush --uri="$site_uri" sql:cli < "$filename" | awk 'BEGIN { FS="\t"; OFS="," } {
rebuilt=0
Expand Down

0 comments on commit 450cced

Please sign in to comment.