From 6e55e9cac03ae3d155edea37f9e7c674121db20b Mon Sep 17 00:00:00 2001 From: jarod5001 <68397534+jarod5001@users.noreply.github.com> Date: Tue, 7 Jun 2022 10:23:05 +0100 Subject: [PATCH] Backup config file before upgrade and restore it --- scripts/upgrade | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index e2c64ee..57ec1b1 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -47,6 +47,17 @@ ynh_clean_setup () { # Exit if an error occurs during the execution of the script ynh_abort_if_errors +#================================================= +# BACKUP CONFIGURATION FILE +#================================================= +ynh_script_progression --message="Backing up configuration file..." + + # Create a temporary directory + tmpdir="$(ynh_smart_mktemp min_size=3)" + + # Backup the config file in the temp dir + cp -a "$final_path/configuration.php" "$tmpdir/configuration.php" + #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -116,11 +127,15 @@ ynh_add_fpm_config #================================================= # SPECIFIC UPGRADE #================================================= -# UPDATE A CONFIG FILE +# RESTORE A CONFIG FILE #================================================= -ynh_script_progression --message="Updating a configuration file..." +ynh_script_progression --message="Restoring configuration file..." -ynh_add_config --template="../conf/configuration.php" --destination="$final_path/configuration.php" +#ynh_add_config --template="../conf/configuration.php" --destination="$final_path/configuration.php" + + # Restore config file + mv -f "$tmpdir/configuration.php" "$final_path/configuration.php" + ynh_secure_remove --file="$tmpdir" chmod 400 "$final_path/configuration.php" chown $app:$app "$final_path/configuration.php"