From 7918f0aa57fcd1d2b1d3123817daebf05c3f236a Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Sun, 13 Mar 2022 21:44:18 +0100 Subject: [PATCH] setting up scripts --- scripts/backup | 15 +++------------ scripts/restore | 21 +++++++++------------ scripts/upgrade | 13 +++++++++++++ 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/scripts/backup b/scripts/backup index f99225d..3f88850 100755 --- a/scripts/backup +++ b/scripts/backup @@ -62,12 +62,6 @@ ynh_backup --src_path="$datadir" --is_big ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# BACKUP THE PHP-FPM CONFIGURATION -#================================================= - -ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" - #================================================= # BACKUP FAIL2BAN CONFIGURATION #================================================= @@ -98,14 +92,11 @@ ynh_backup --src_path="/etc/cron.d/$app" ynh_backup --src_path="/etc/$app/" #================================================= -# BACKUP THE MYSQL DATABASE +# BACKUP THE POSTGRESQL DATABASE #================================================= -ynh_print_info --message="Backing up the MySQL database..." +ynh_print_info --message="Backing up the PostgreSQL database..." -### (However, things like MySQL dumps *do* take some time to run, though the -### copy of the generated dump to the archive still happens later) - -ynh_mysql_dump_db --database="$db_name" > db.sql +ynh_psql_dump_db --database="$db_name" > db.sql #================================================= # END OF SCRIPT diff --git a/scripts/restore b/scripts/restore index 31b3158..192aa18 100755 --- a/scripts/restore +++ b/scripts/restore @@ -99,13 +99,6 @@ chmod 750 "$datadir" chmod -R o-rwx "$datadir" chown -R $app:www-data "$datadir" -#================================================= -# RESTORE THE PHP-FPM CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the PHP-FPM configuration..." --time --weight=1 - -ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" - #================================================= # RESTORE FAIL2BAN CONFIGURATION #================================================= @@ -126,13 +119,17 @@ ynh_script_progression --message="Reinstalling dependencies..." --time --weight= ynh_install_app_dependencies $pkg_dependencies #================================================= -# RESTORE THE MYSQL DATABASE +# RESTORE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Restoring the MySQL database..." --time --weight=1 +ynh_script_progression --message="Restoring the PostgreSQL database..." -db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) -ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd -ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql +ynh_psql_test_if_first_run +ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd +ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS unaccent;" --database=$db_name +ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name +ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS citext;" --database=$db_name +ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";" --database=$db_name +ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name" #================================================= # RESTORE VARIOUS FILES diff --git a/scripts/upgrade b/scripts/upgrade index 855b543..c0d6d41 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -101,6 +101,19 @@ if ! ynh_permission_exists --permission="api"; then ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --show_tile="false" --protected="true" fi +#Switch variables name +psql_db=$(ynh_app_setting_get --app=$app --key=psql_db) + +if [ -n "$psql_db" ] +then + db_name=$(ynh_app_setting_get --app=$app --key=psql_db) + db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) + ynh_app_setting_set --app=$app --key=db_name --value=$db_name + ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd + ynh_app_setting_delete --app=$app --key=psql_db + ynh_app_setting_delete --app=$app --key=psqlpwd +fi + #================================================= # CREATE DEDICATED USER #=================================================