From 9aae43b4b0f3ad95e16b78bebf0bd06588e6fed2 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Mon, 4 Mar 2024 17:06:13 +0100 Subject: [PATCH] fix: [odoo-tecnativa] support restoring large database file --- odoo-tecnativa/actions/load | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/odoo-tecnativa/actions/load b/odoo-tecnativa/actions/load index ccad9cd..e25e38b 100755 --- a/odoo-tecnativa/actions/load +++ b/odoo-tecnativa/actions/load @@ -160,26 +160,41 @@ check_input() { } } +## Beware that we are not on the host, so we need to create the +## fifo in a place we can share with the curl container. +export TMPDIR=/var/cache/compose +settmpdir RESTORE_TMPDIR +mkfifo "$RESTORE_TMPDIR/fifo" + +## Using fifo because if using ``@-`` curl will load all the database +## in memory before sending it, which is NOT desirable as the size of +## the database can be greater than available memory. Using fifo, we +## force the data to be streamed. cmd=( docker run -i --rm --network "$container_network" + -v "$RESTORE_TMPDIR/fifo:/tmp/restore/fifo" "$DEFAULT_CURL_IMAGE" - -sS - -X POST - -F "master_pwd=${ADMIN_PASSWORD}" - -F "backup_file=@-" + -sS + -X POST + -F "master_pwd=${ADMIN_PASSWORD}" -F "name=${dbname}" - "${curl_opts[@]}" + -F "backup_file=@/tmp/restore/fifo" http://${container_ip}:8069/web/database/restore -) + ) ## XXXvlab: contains password, left only for advanced debug -#debug "${cmd[@]}" +#echo "COMMAND: ${cmd[@]}" >&2 -out=$(set -o pipefail; check_input | "${cmd[@]}") || { +"${cmd[@]}" > "$RESTORE_TMPDIR/out" & +pid=$! +check_input > "$RESTORE_TMPDIR/fifo" +wait "$pid" || { die "Posting to odoo restore API through curl was unsuccessfull." } +out=$(cat "$RESTORE_TMPDIR/out") + if [[ "$out" == *""* ]]; then errmsg=$(echo "$out" | grep "alert-danger") errmsg=${errmsg#*>}