68 lines
1.5 KiB

  1. #!/bin/bash
  2. ## Load action gets a first argument a DIRECTORY holding the necessary files.
  3. ##
  4. ##
  5. if [ -z "$SERVICE_DATASTORE" ]; then
  6. echo "This script is meant to be run through 'compose' to work properly." >&2
  7. exit 1
  8. fi
  9. usage="$exname [-h|--help] DBNAME DEST"
  10. dbname=
  11. postgis=
  12. while [ "$1" ]; do
  13. case "$1" in
  14. "--help"|"-h")
  15. print_usage
  16. exit 0
  17. ;;
  18. *)
  19. [ -z "$dbname" ] && { dbname=$1 ; shift ; continue ; }
  20. [ -z "$DEST" ] && { DEST=$1 ; shift ; continue ; }
  21. err "Unexpected argument '$1'."
  22. exit 1
  23. ;;
  24. esac
  25. shift
  26. done
  27. if [ -z "$dbname" ]; then
  28. err "You must provide a source database name as first argument."
  29. print_usage
  30. exit 1
  31. fi
  32. if [ -z "$DEST" ]; then
  33. err "You must provide a dest file as second argument."
  34. print_usage
  35. exit 1
  36. fi
  37. realpath=$(realpath "$DEST") || exit 1
  38. dirname="$(dirname "$realpath")" || exit 1
  39. basename=$(basename "$realpath") || exit 1
  40. host_path="$(get_host_path "$dirname")" || {
  41. die "Failed to find host path for local directory: $dirname"
  42. }
  43. if [[ "$dbname" == *"@"* ]]; then
  44. IFS="@" read user dbname < <(echo "$dbname")
  45. fi
  46. . "$CHARM_PATH"/lib/common
  47. set -e
  48. if ! db_has_database "$dbname"; then
  49. err "Can't find database '$dbname'."
  50. exit 1
  51. fi
  52. db_docker_opts+=("-v" "$host_path:/tmp/work")
  53. PGM cp "$dbname" "/tmp/work/$basename" || {
  54. die "pgm command failed !"
  55. }
  56. info "Saved database '$dbname' into '$DEST'."