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.

97 lines
2.4 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. depends curl
  10. usage="$exname [-h|--help] [--force|-f] DBNAME DEST_FILENAME"
  11. dbname=
  12. output=
  13. while [ "$1" ]; do
  14. case "$1" in
  15. "--help"|"-h")
  16. print_usage
  17. exit 0
  18. ;;
  19. "--force"|"-f")
  20. force=yes
  21. ;;
  22. --*|-*)
  23. err "Unexpected optional argument '$1'"
  24. print_usage
  25. exit 1
  26. ;;
  27. *)
  28. [ -z "$dbname" ] && { dbname=$1 ; shift ; continue ; }
  29. [ -z "$output" ] && { output=$1 ; shift ; continue ; }
  30. err "Unexpected positional argument '$1'"
  31. print_usage
  32. exit 1
  33. ;;
  34. esac
  35. shift
  36. done
  37. if [ -z "$dbname" ]; then
  38. err "You must provide a database name as first argument."
  39. print_usage
  40. exit 1
  41. fi
  42. if [ -z "$output" ]; then
  43. err "You must provide a destination filename name as second argument."
  44. print_usage
  45. exit 1
  46. fi
  47. if [ -e "$output" -a -z "$force" ]; then
  48. err "File '$output' exists already. Force overwrite with -f or --force."
  49. print_usage
  50. exit 1
  51. fi
  52. set -e
  53. ## Ensure odoo is launched
  54. service_def=$(get_compose_service_def "$SERVICE_NAME")
  55. ADMIN_PASSWORD=$(echo "$service_def" | shyaml get-value options.admin-password) || {
  56. err "Could not find 'admin-password' in $SERVICE_NAME service definition."
  57. exit 1
  58. }
  59. containers="$(get_running_containers_for_service "$SERVICE_NAME")"
  60. if [ -z "$containers" ]; then
  61. err "No containers running for service $DARKYELLOW$SERVICE_NAME$NORMAL."
  62. die "Please ensure that $DARKYELLOW$SERVICE_NAME$NORMAL is running before using '$exname'."
  63. fi
  64. ## XXXvlab: taking first container is probably not a good idea
  65. container="$(echo "$containers" | head -n 1)"
  66. ## XXXvlab: taking first ip is probably not a good idea
  67. container_ip="$(get_docker_ips "$container" | head -n 1 | cut -f 2 -d ":")"
  68. curl -X POST \
  69. -F "master_pwd=${ADMIN_PASSWORD}" \
  70. -F "name=${dbname}" \
  71. -F "backup_format=zip" \
  72. -o "$output" \
  73. http://${container_ip}:8069/web/database/backup >/dev/null 2>&1 || {
  74. die "Querying odoo through curl was unsuccessfull."
  75. }
  76. info "Saved '$dbname' odoo database and filestore to '$output'."