Valentin Lab
6 years ago
1 changed files with 99 additions and 0 deletions
@ -0,0 +1,99 @@ |
|||||
|
#!/bin/bash |
||||
|
|
||||
|
## Load action gets a first argument a DIRECTORY holding the necessary files. |
||||
|
## |
||||
|
## |
||||
|
|
||||
|
if [ -z "$SERVICE_DATASTORE" ]; then |
||||
|
echo "This script is meant to be run through 'compose' to work properly." >&2 |
||||
|
exit 1 |
||||
|
fi |
||||
|
|
||||
|
depends curl |
||||
|
|
||||
|
usage="$exname [-h|--help] [--force|-f] DBNAME DEST_FILENAME" |
||||
|
|
||||
|
dbname= |
||||
|
output= |
||||
|
while [ "$1" ]; do |
||||
|
case "$1" in |
||||
|
"--help"|"-h") |
||||
|
print_usage |
||||
|
exit 0 |
||||
|
;; |
||||
|
"--force"|"-f") |
||||
|
force=yes |
||||
|
;; |
||||
|
--*|-*) |
||||
|
err "Unexpected optional argument '$1'" |
||||
|
print_usage |
||||
|
exit 1 |
||||
|
;; |
||||
|
*) |
||||
|
[ -z "$dbname" ] && { dbname=$1 ; shift ; continue ; } |
||||
|
[ -z "$output" ] && { output=$1 ; shift ; continue ; } |
||||
|
err "Unexpected positional argument '$1'" |
||||
|
print_usage |
||||
|
exit 1 |
||||
|
;; |
||||
|
esac |
||||
|
shift |
||||
|
done |
||||
|
|
||||
|
if [ -z "$dbname" ]; then |
||||
|
err "You must provide a database name as first argument." |
||||
|
print_usage |
||||
|
exit 1 |
||||
|
fi |
||||
|
|
||||
|
if [ -z "$output" ]; then |
||||
|
err "You must provide a destination filename name as second argument." |
||||
|
print_usage |
||||
|
exit 1 |
||||
|
fi |
||||
|
|
||||
|
|
||||
|
if [ -e "$output" -a -z "$force" ]; then |
||||
|
err "File '$output' exists already. Force overwrite with -f or --force." |
||||
|
print_usage |
||||
|
exit 1 |
||||
|
fi |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
set -e |
||||
|
|
||||
|
## Ensure odoo is launched |
||||
|
service_def=$(get_compose_service_def "$SERVICE_NAME") |
||||
|
|
||||
|
ADMIN_PASSWORD=$(echo "$service_def" | shyaml get-value options.admin-password) || { |
||||
|
err "Could not find 'admin-password' in $SERVICE_NAME service definition." |
||||
|
exit 1 |
||||
|
} |
||||
|
|
||||
|
|
||||
|
containers="$(get_running_containers_for_service "$SERVICE_NAME")" |
||||
|
|
||||
|
if [ -z "$containers" ]; then |
||||
|
err "No containers running for service $DARKYELLOW$SERVICE_NAME$NORMAL." |
||||
|
die "Please ensure that $DARKYELLOW$SERVICE_NAME$NORMAL is running before using '$exname'." |
||||
|
fi |
||||
|
|
||||
|
## XXXvlab: taking first container is probably not a good idea |
||||
|
container="$(echo "$containers" | head -n 1)" |
||||
|
|
||||
|
## XXXvlab: taking first ip is probably not a good idea |
||||
|
container_ip="$(get_docker_ips "$container" | head -n 1 | cut -f 2 -d ":")" |
||||
|
|
||||
|
curl -X POST \ |
||||
|
-F "master_pwd=${ADMIN_PASSWORD}" \ |
||||
|
-F "name=${dbname}" \ |
||||
|
-F "backup_format=zip" \ |
||||
|
-o "$output" \ |
||||
|
http://${container_ip}:8069/web/database/backup >/dev/null 2>&1 || { |
||||
|
die "Querying odoo through curl was unsuccessfull." |
||||
|
} |
||||
|
|
||||
|
|
||||
|
info "Saved '$dbname' odoo database and filestore to '$output'." |
Write
Preview
Loading…
Cancel
Save
Reference in new issue