1313 fi
1414
1515 >&2 cat << EOF
16- Usage: ${BASH_SOURCE[0]} project-dir site-uri
16+ Usage: ${BASH_SOURCE[0]} site-uri
1717
1818EOF
1919 exit 1
2020}
2121
22- if (( $# < 2 )) ; then
22+ if (( $# < 1 )) ; then
2323 usage " Too few arguments"
2424fi
2525
26- project_dir=" $1 "
27- uri=" $2 "
26+ site_uri=" $1 "
2827
29- if [ -z " $project_dir " ]; then
30- usage " Invalid project directory"
31- fi
32-
33- if [ ! -d " $project_dir " ] ; then
34- (>&2 echo ' Project directory "' " $project_dir " ' " does not exist' )
35- exit 1
36- fi
37-
38- if [ -z " $uri " ]; then
28+ if [ -z " $site_uri " ]; then
3929 usage " Invalid site-uri"
4030fi
4131
42- cd " $project_dir "
32+ # cd "$project_dir"
4333
4434filenames=(" $script_dir " /export_* .sql)
4535
4636for filename in " ${filenames[@]} " ; do
47- echo " $filename "
37+ echo " Running $filename "
4838
4939 # JSON
5040
5141 # https://tldp.org/LDP/abs/html/string-manipulation.html
5242 output_filename=${filename/% .sql/ .json}
5343 # https://github.com/drush-ops/drush/issues/3071#issuecomment-347929777
54- vendor/bin/drush --uri=" $uri " php:eval " return \Drupal::database()->query(file_get_contents('$filename '))->fetchAll()" --format=json > | " $output_filename " || true
55- echo " $output_filename "
44+ vendor/bin/drush --uri=" $site_uri " php:eval " return \Drupal::database()->query(file_get_contents('$filename '))->fetchAll()" --format=json > | " $output_filename " || true
45+ ls -lh " $output_filename "
5646
5747 # CSV
5848
5949 output_filename=${filename/% .sql/ .csv}
6050 # https://stackoverflow.com/a/22421445/2502647
61- vendor/bin/drush --uri=" $uri " sql:cli < " $filename " | awk ' BEGIN { FS="\t"; OFS="," } {
51+ vendor/bin/drush --uri=" $site_uri " sql:cli < " $filename " | awk ' BEGIN { FS="\t"; OFS="," } {
6252 rebuilt=0
6353 for(i=1; i<=NF; ++i) {
6454 if ($i ~ /,/ && $i !~ /^".*"$/) {
@@ -70,5 +60,6 @@ for filename in "${filenames[@]}"; do
7060 if (!rebuilt) { $1=$1 }
7161 print
7262}' > | " $output_filename " || true
73- echo " $output_filename "
63+ ls -lh " $output_filename "
64+
7465done
0 commit comments