mirror of
https://github.com/YunoHost-Apps/flohmarkt_ynh.git
synced 2024-09-03 18:36:30 +02:00
rename couchdb before restore if exists
https://codeberg.org/flohmarkt/flohmarkt_ynh/issues/62
This commit is contained in:
parent
b87ce1299e
commit
38f8e48f93
2 changed files with 46 additions and 2 deletions
|
@ -168,7 +168,7 @@ flohmarkt_ynh_couchdb_user_permissions() {
|
|||
ynh_local_curl -n -m PUT -u admin -p "$password_couchdb_admin" \
|
||||
-H "Accept: application/json" -H "Content-Type: application/json" \
|
||||
-d "{\"members\":{\"names\": [\"${app}\"],\"roles\": [\"editor\"]}}" \
|
||||
--line_match='ok' \
|
||||
--line_match='"ok":true' \
|
||||
"http://127.0.0.1:5984/${app}/_security"
|
||||
}
|
||||
|
||||
|
@ -183,8 +183,42 @@ flohmarkt_ynh_exists_couchdb_db() {
|
|||
}
|
||||
|
||||
flohmarkt_ynh_delete_couchdb_db() {
|
||||
local legacy_args='n'
|
||||
local -A args_array=( [n]=name= )
|
||||
ynh_handle_getopts_args "$@"
|
||||
local name=${name:-${app}}
|
||||
|
||||
ynh_local_curl -n -m DELETE -u admin -p "$password_couchdb_admin" \
|
||||
--line_match='"ok":true' "http://127.0.0.1:5984/${app}"
|
||||
--line_match='"ok":true' "http://127.0.0.1:5984/${name}"
|
||||
}
|
||||
|
||||
# replicate couchdb to a new database
|
||||
flohmarkt_ynh_copy_couchdb() {
|
||||
local legacy_args='on'
|
||||
local -A args_array=( [o]=old_name= [n]=new_name= )
|
||||
local new_name
|
||||
local old_name
|
||||
ynh_handle_getopts_args "$@"
|
||||
old_name=${old_name:-${app}}
|
||||
|
||||
ynh_local_curl -n -m POST -u admin -p "$password_couchdb_admin" \
|
||||
-H "Accept: application/json" -H "Content-Type: application/json" \
|
||||
-d '{ "create_target":true,"source" : "' -d"${old_name}" -d'",' \
|
||||
-d '"target":"' -d "${new_name}" -d'"}' --seperator=none \
|
||||
--line_match='"ok":true' "http://127.0.0.1:5984/_replicate"
|
||||
}
|
||||
|
||||
# copy couchdb to new name and delete source
|
||||
flohmarkt_ynh_rename_couchdb() {
|
||||
local legacy_args='on'
|
||||
local -A args_array=( [o]=old_name= [n]=new_name= )
|
||||
local new_name
|
||||
local old_name
|
||||
ynh_handle_getopts_args "$@"
|
||||
old_name=${old_name:-${app}}
|
||||
|
||||
flohmarkt_ynh_copy_couchdb -o "$old_name" -n "$new_name"
|
||||
flohmarkt_ynh_delete_couchdb_db "$old_name"
|
||||
}
|
||||
|
||||
# check whether old couchdb user or database exist before creating the new ones
|
||||
|
|
|
@ -23,6 +23,16 @@ else
|
|||
ynh_script_progression --message="CouchDB configuration file already exists." --weight=1
|
||||
fi
|
||||
|
||||
# check if couchdb already exists and if so rename it to make room for the restore
|
||||
if flohmarkt_ynh_exists_couchdb_db; then
|
||||
flohmarkt_couchdb_rename_to="${app}_$(date '+%Y-%m-%d_%H-%M-%S_%N')"
|
||||
if flohmarkt_ynh_rename_couchdb "${app}" "${flohmarkt_couchdb_rename_to}"; then
|
||||
ynh_print_warn --message="renamed existing database ${app} to ${flohmarkt_couchdb_rename_to}"
|
||||
else
|
||||
ynh_die --message="could not rename existing couchdb database and cannot overwrite it"
|
||||
fi
|
||||
fi
|
||||
|
||||
# restore couchdb from json
|
||||
ynh_script_progression --message="Importing couchdb from json backup..." --weight=8
|
||||
flohmarkt_ynh_restore_couchdb
|
||||
|
|
Loading…
Add table
Reference in a new issue