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.

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