fork 0k-charms
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.2 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. if [[ "$dbname" == *"@"* ]]; then
  38. IFS="@" read user dbname < <(echo "$dbname")
  39. fi
  40. . "$CHARM_PATH"/lib/common
  41. set -e
  42. if ! db_has_database "$dbname"; then
  43. err "Can't find database '$dbname'."
  44. exit 1
  45. fi
  46. PGM cp "$dbname" "$DEST" || {
  47. die "pgm command failed !"
  48. }
  49. info "Saved database '$dbname' into '$DEST'."