mirror of
https://github.com/YunoHost-Apps/noalyss_ynh.git
synced 2024-09-03 19:46:20 +02:00
Fix various bugs in scripts; Revert path to _common.sh for backup & restore scripts
This commit is contained in:
parent
2ca427a1f5
commit
43d9cafec7
4 changed files with 13 additions and 12 deletions
|
@ -83,11 +83,11 @@ ynh_psql_list_user_dbs() {
|
||||||
|
|
||||||
if ynh_psql_user_exists --user=$db_user; then # Check that the db_user exists
|
if ynh_psql_user_exists --user=$db_user; then # Check that the db_user exists
|
||||||
local sql="COPY (SELECT datname FROM pg_database JOIN pg_authid ON pg_database.datdba = pg_authid.oid WHERE rolname = '${db_user}') TO STDOUT"
|
local sql="COPY (SELECT datname FROM pg_database JOIN pg_authid ON pg_database.datdba = pg_authid.oid WHERE rolname = '${db_user}') TO STDOUT"
|
||||||
local dbs_list=ynh_psql_execute_as_root --sql="$sql" # Fetch database(s) associated to role $db_user
|
local dbs_list=$(ynh_psql_execute_as_root --sql="$sql") # Fetch database(s) associated to role $db_user as a string using space as delimiter (ex: "db1 db2 db3 db4")
|
||||||
return dbs_list
|
echo "$dbs_list"
|
||||||
else
|
else
|
||||||
ynh_print_err --message="User \'$db_user\' does not exist"
|
ynh_print_err --message="User \'$db_user\' does not exist"
|
||||||
return ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,10 +105,11 @@ ynh_psql_remove_all_user_dbs() {
|
||||||
# Manage arguments with getopts
|
# Manage arguments with getopts
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
|
|
||||||
local dbs_to_drop = ynh_psql_list_user_dbs $db_user
|
local dbs_to_drop=$(ynh_psql_list_user_dbs $db_user)
|
||||||
if [ -n "$dbs_to_drop" ]; then # Check that the list of database(s) is not empty
|
if [ -n "$dbs_to_drop" ]; then # Check that the list of database(s) is not empty
|
||||||
|
|
||||||
local db_name
|
local db_name
|
||||||
for $db_name in $dbs_to_drop # Iterate through the list of database(s) to remove
|
for db_name in $dbs_to_drop # Iterate through the list of database(s) to remove
|
||||||
do
|
do
|
||||||
if ynh_psql_database_exists --database=$db_name; then # Check if the database exists
|
if ynh_psql_database_exists --database=$db_name; then # Check if the database exists
|
||||||
ynh_psql_drop_db $db_name # Remove the database
|
ynh_psql_drop_db $db_name # Remove the database
|
||||||
|
@ -138,11 +139,11 @@ ynh_psql_dump_all_user_dbs() {
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
app="${app:-}"
|
app="${app:-}"
|
||||||
|
|
||||||
local dbs_to_dump = ynh_psql_list_user_dbs $db_user
|
local dbs_to_dump=$(ynh_psql_list_user_dbs $db_user)
|
||||||
if [ -n "$dbs_to_dump" ]; then # Check that the list of database(s) is not empty
|
if [ -n "$dbs_to_dump" ]; then # Check that the list of database(s) is not empty
|
||||||
|
|
||||||
local db_name
|
local db_name
|
||||||
for $db_name in $dbs_to_dump # Iterate through the list of database(s) to dump
|
for db_name in $dbs_to_dump # Iterate through the list of database(s) to dump
|
||||||
do
|
do
|
||||||
if ynh_psql_database_exists --database=$db_name; then # Check if the database exists
|
if ynh_psql_database_exists --database=$db_name; then # Check if the database exists
|
||||||
ynh_psql_dump_db $db_name > "$app-$db_name-dump.sql" # Dump the database to a filename format of app-db_name-dump.sql, or of db_name-dump.sql if app parameter was not supplied
|
ynh_psql_dump_db $db_name > "$app-$db_name-dump.sql" # Dump the database to a filename format of app-db_name-dump.sql, or of db_name-dump.sql if app parameter was not supplied
|
||||||
|
@ -187,7 +188,7 @@ ynh_psql_restore_all_app_dbs_dumps(){
|
||||||
local db_name
|
local db_name
|
||||||
db_name="${filename#${app}-}" # Remove "$app-" prefix from filename string to parse db_name. Will do nothing if there is no match.
|
db_name="${filename#${app}-}" # Remove "$app-" prefix from filename string to parse db_name. Will do nothing if there is no match.
|
||||||
db_name="${db_name%-dump.sql}" # Remove "-dump.sql" suffix from filename string to parse db_name. Will do nothing if there is no match.
|
db_name="${db_name%-dump.sql}" # Remove "-dump.sql" suffix from filename string to parse db_name. Will do nothing if there is no match.
|
||||||
db_name=ynh_sanitize_dbid --db_name="$db_name"
|
db_name=$(ynh_sanitize_dbid --db_name="$db_name")
|
||||||
|
|
||||||
if [[ "${filename#${app}-}" = "$filename" || -z "$db_name" ]] ; then # Check whether app_ID is included in filename OR $db_name is empty
|
if [[ "${filename#${app}-}" = "$filename" || -z "$db_name" ]] ; then # Check whether app_ID is included in filename OR $db_name is empty
|
||||||
ynh_print_warn --message="File ignored: $filename. Filename not matching expected format (appID-db_name-dump.sql)"
|
ynh_print_warn --message="File ignored: $filename. Filename not matching expected format (appID-db_name-dump.sql)"
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
# IMPORT GENERIC HELPERS
|
# IMPORT GENERIC HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
source _common.sh
|
source ../settings/scripts/_common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -55,7 +55,7 @@ ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_print_info --message="Backing up the PostgreSQL database..."
|
ynh_print_info --message="Backing up the PostgreSQL database..."
|
||||||
|
|
||||||
ynh_psql_dump_all_user_dbs --user=$db_user --app=$app
|
ynh_psql_dump_all_user_dbs --db_user=$db_user --app=$app
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
|
|
|
@ -26,7 +26,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||||
ynh_script_progression --message="Removing all associated PostgreSQL database(s) and role"
|
ynh_script_progression --message="Removing all associated PostgreSQL database(s) and role"
|
||||||
|
|
||||||
# Remove all existing databases associated with the app's dedicated user a database if it exists
|
# Remove all existing databases associated with the app's dedicated user a database if it exists
|
||||||
ynh_psql_remove_all_user_dbs --user=$db_user;
|
ynh_psql_remove_all_user_dbs --db_user=$db_user;
|
||||||
|
|
||||||
# Remove dedicated PostgreSQL role
|
# Remove dedicated PostgreSQL role
|
||||||
if ynh_psql_user_exists --user=$db_user; then
|
if ynh_psql_user_exists --user=$db_user; then
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
# IMPORT GENERIC HELPERS
|
# IMPORT GENERIC HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
source _common.sh
|
source ../settings/scripts/_common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
Loading…
Reference in a new issue