Browse Source

new: add ``vps odoo {restart,dump,restore,set-cyclos-url}`` commands

Signed-off-by: Valentin Lab <valentin.lab@kalysto.org>
rc1
Valentin Lab 3 years ago
parent
commit
1cbff5305e
  1. 33
      README.org
  2. 160
      bin/vps

33
README.org

@ -316,6 +316,22 @@ docker-ip
*** odoo *** odoo
**** Backups **** Backups
***** Backuping odoo account (filestore and database) ***** Backuping odoo account (filestore and database)
****** Via =vps= command
A few examples:
#+begin_src sh
## dump default database of default service to file db.zip
vps odoo dump db.zip
## dump default database of 'odoo2' service
vps odoo dump /tmp/db.zip -s odoo2
## dump 'odoodev' database of default 'odoo' service
vps odoo dump /tmp/db.zip -d odoodev
#+end_src
****** Via charm only actions
Be sure that your odoo instance should be already up. Be sure that your odoo instance should be already up.
@ -336,6 +352,23 @@ don't want to allow to go mess around with sending mails or fetching mails.
docker-cutoff 25 993 465 docker-cutoff 25 993 465
#+END_SRC #+END_SRC
****** Via =vps= command
#+begin_src sh
## restore default database of default service from file db.zip
vps odoo restore db.zip
## restore default database of 'odoo2' service
vps odoo restore /tmp/db.zip -s odoo2
## restore 'odoodev' database of default 'odoo' service
vps odoo restore /tmp/db.zip -d odoodev
#+end_src
****** Via standard charm action
Be sure that your odoo instance is already up.
These are the normal loading instructions: These are the normal loading instructions:
#+BEGIN_SRC sh #+BEGIN_SRC sh

160
bin/vps

@ -841,4 +841,164 @@ cmdline.spec::cmd:recover-target:run() {
} }
cmdline.spec.gnu odoo
cmdline.spec::cmd:odoo:run() {
:
}
cmdline.spec.gnu restart
cmdline.spec:odoo:cmd:restart:run() {
: :optval: --service,-s "The service (defaults to 'odoo')"
local out odoo_service
odoo_service="${opt_service:-odoo}"
if ! out=$(docker restart "myc_${odoo_service}_1" 2>&1); then
if [[ "$out" == *"no matching entries in passwd file" ]]; then
warn "Catched docker bug. Restarting once more."
if ! out=$(docker restart "myc_${odoo_service}_1"); then
err "Can't restart container myc_${odoo_service}_1 (restarted twice)."
echo " output:" >&2
echo "$out" | prefix " ${GRAY}|${NORMAL} " >&2
exit 1
fi
else
err "Couldn't restart container myc_${odoo_service}_1 (and no restart bug detected)."
exit 1
fi
fi
info "Container myc_${odoo_service}_1 was ${DARKGREEN}successfully${NORMAL} restarted."
}
cmdline.spec.gnu restore
cmdline.spec:odoo:cmd:restore:run() {
: :posarg: ZIP_DUMP_LOCATION 'Source odoo dump file to restore
(can be a local file or an url)'
: :optval: --service,-s "The service (defaults to 'odoo')"
: :optval: --database,-d 'Target database (default if not specified)'
local out
odoo_service="${opt_service:-odoo}"
if [[ "$ZIP_DUMP_LOCATION" == "http://"* ]]; then
settmpdir ZIP_TMP_LOCATION
tmp_location="$ZIP_TMP_LOCATION/dump.zip"
curl -k -s -L "$ZIP_DUMP_LOCATION" > "$tmp_location" || {
err "Couldn't get '$ZIP_DUMP_LOCATION'."
exit 1
}
if [[ "$(dd if="$tmp_location" count=2 bs=1 2>/dev/null)" != "PK" ]]; then
err "Download doesn't seem to be a zip file."
dd if="$tmp_location" count=1 bs=256 | hd | prefix " ${GRAY}|${NORMAL} " >&2
exit 1
fi
info "Successfully downloaded '$ZIP_DUMP_LOCATION'"
echo " in '$tmp_location'." >&2
ZIP_DUMP_LOCATION="$tmp_location"
fi
[ -e "$ZIP_DUMP_LOCATION" ] || {
err "No file '$ZIP_DUMP_LOCATION' found." >&2
exit 1
}
#cmdline.spec:odoo:cmd:restart:run --service "$odoo_service" || exit 1
msg_dbname=default
[ -n "$opt_database" ] && msg_dbname="'$opt_database'"
compose --no-hooks drop "$odoo_service" $opt_database || {
err "Error dropping $msg_dbname database of service ${DARKYELLOW}$odoo_service${NORMAL}."
exit 1
}
compose --no-hooks load "$odoo_service" $opt_database < "$ZIP_DUMP_LOCATION" || {
err "Error restoring service ${DARKYELLOW}$odoo_service${NORMAL} to $msg_dbname database."
exit 1
}
info "Successfully restored ${DARKYELLOW}$odoo_service${NORMAL} to $msg_dbname database."
## Restart odoo, ensure there is no bugs lingering on it.
cmdline.spec:odoo:cmd:restart:run --service "$odoo_service" || exit 1
}
cmdline.spec.gnu dump
cmdline.spec:odoo:cmd:dump:run() {
: :posarg: DUMP_ZIPFILE 'Target path to store odoo dump zip file.'
: :optval: --database,-d 'Target database (default if not specified)'
: :optval: --service,-s "The service (defaults to 'odoo')"
odoo_service="${opt_service:-odoo}"
msg_dbname=default
[ -n "$opt_database" ] && msg_dbname="'$opt_database'"
compose --no-hooks save "$odoo_service" $opt_database > "$DUMP_ZIPFILE" || {
err "Error dumping ${DARKYELLOW}$odoo_service${NORMAL}'s $msg_dbname database to '$DUMP_ZIPFILE'."
exit 1
}
info "Successfully dumped ${DARKYELLOW}$odoo_service${NORMAL}'s $msg_dbname database to '$DUMP_ZIPFILE'."
}
cmdline.spec.gnu drop
cmdline.spec:odoo:cmd:drop:run() {
: :optval: --database,-d 'Target database (default if not specified)'
: :optval: --service,-s "The service (defaults to 'odoo')"
odoo_service="${opt_service:-odoo}"
msg_dbname=default
[ -n "$opt_database" ] && msg_dbname="'$opt_database'"
compose --no-hooks drop "$odoo_service" $opt_database || {
err "Error dropping ${DARKYELLOW}$odoo_service${NORMAL}'s $msg_dbname database."
exit 1
}
info "Successfully dropped ${DARKYELLOW}$odoo_service${NORMAL}'s $msg_dbname database."
}
cmdline.spec.gnu set-cyclos-url
cmdline.spec:odoo:cmd:set-cyclos-url:run() {
: :optval: --database,-d "Target database ('odoo' if not specified)"
: :optval: --service,-s "The cyclos service name (defaults to 'cyclos')"
local URL
dbname=${opt_database:-odoo}
cyclos_service="${opt_service:-cyclos}"
URL=$(
set -o pipefail
cat /var/lib/compose/relations/myc/${cyclos_service}-frontend/web-proxy/data |
shyaml get-value url
) || {
err "Failed querying ${cyclos_service} to frontend relation to get url."
exit 1
}
echo "UPDATE res_company SET cyclos_server_url = '$URL' WHERE id=1;" |
docker exec -i myc_postgres_1 psql -U postgres "$dbname" || {
err "Failed to set cyclos url value in '$dbname' database."
exit 1
}
}
cmdline::parse "$@" cmdline::parse "$@"
Loading…
Cancel
Save