From 4d924b6e3fd7b34ac7bb3712470b7b23d698eeb8 Mon Sep 17 00:00:00 2001 From: magikcypress Date: Thu, 9 Mar 2017 15:01:44 +0100 Subject: [PATCH] Correction Backup/restore --- scripts/backup | 14 +++++++------- scripts/restore | 40 +++++++++++++++++++++++----------------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/scripts/backup b/scripts/backup index 805f30c..0ca3670 100644 --- a/scripts/backup +++ b/scripts/backup @@ -11,17 +11,17 @@ source /usr/share/yunohost/helpers # Retrieve app settings domain=$(ynh_app_setting_get "$app" domain) -path=$(ynh_app_setting_get "$app" final_path) with_mysql=$(ynh_app_setting_get "$app" with_mysql) # Copy the app files -DESTDIR="/var/www/${app}" -ynh_backup "$DESTDIR" "sources" 1 +final_path="/var/www/${app}" +ynh_backup "$final_path" "sources" 1 -# Copy the conf files -ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "conf/nginx.conf" -ynh_backup "/etc/php5/fpm/pool.d/${app}.conf" "conf/php-fpm.conf" -ynh_backup "/etc/php5/fpm/conf.d/20-${app}.ini" "conf/php-fpm.ini" +# Copy the nginx conf files +ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf" +# Copy the php-fpm conf files +ynh_backup "/etc/php5/fpm/pool.d/${app}.conf" "php-fpm.conf" +ynh_backup "/etc/php5/fpm/conf.d/20-${app}.ini" "php-fpm.ini" # Backup db if [[ $with_mysql -eq 1 ]]; then diff --git a/scripts/restore b/scripts/restore index 93810d8..152605d 100644 --- a/scripts/restore +++ b/scripts/restore @@ -14,11 +14,15 @@ source /usr/share/yunohost/helpers domain=$(ynh_app_setting_get $app domain) path=$(ynh_app_setting_get $app path) is_public=$(ynh_app_setting_get $app is_public) -final_path=$(ynh_app_setting_get $app final_path) +with_mysql=$(ynh_app_setting_get "$app" with_mysql) -if [ -d $final_path ]; then - ynh_die "There is already a directory: $final_path" -fi +# Check domain/path availability +sudo yunohost app checkurl "${domain}${path}" -a "$app" \ + || ynh_die "Path not available: ${domain}${path}" + +# Restore sources & data +final_path="/var/www/${app}" +sudo cp -a ./sources "$final_path" # Check configuration files php-fpm nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf" @@ -34,23 +38,25 @@ phpfpm_ini="/etc/php5/fpm/conf.d/20-${app}.ini" "The PHP FPM INI configuration already exists at '${phpfpm_ini}'. You should safely delete it before restoring this app." -sudo cp -a ./sources $final_path - -db_pwd=$(ynh_app_setting_get $app mysqlpwd) -db_user=$app -ynh_mysql_create_db $db_user $db_user $db_pwd -sudo su -c "mysql -u $db_user -p$db_pwd $app < ./db.sql" -sudo rm -f "./db.sql" -sudo sed -i -e "s/'DB_USER', *'[^']*'/'DB_USER', '$app'/g" $final_path/config/connect.php -sudo sed -i -e "s/'DB_NAME', *'[^']*'/'DB_NAME', '$app'/g" $final_path/config/connect.php +# Restore db +if [[ $with_mysql -eq 1 ]]; then + db_pwd=$(ynh_app_setting_get $app mysqlpwd) + db_user=$app + ynh_mysql_create_db $db_user $db_user $db_pwd + sudo su -c "mysql -u $db_user -p$db_pwd $app < ./db.sql" + sudo rm -f "./db.sql" + sudo sed -i -e "s/'__DB_USER__', *'[^']*'/'__DB_USER__', '$app'/g" $final_path/config/connect.php + # sudo sed -i -e "s/'__DB_PWD__', *'[^']*'/'__DB_PWD__', '$app'/g" $final_path/config/connect.php +fi # Set permissions sudo chown -R www-data: $final_path -# Restore configuration files -sudo cp -a ./conf/nginx.conf "$nginx_conf" -sudo cp -a ./conf/php-fpm.conf "$phpfpm_conf" -sudo cp -a ./conf/php-fpm.ini "$phpfpm_ini" +# Restore nginx configuration files +sudo cp -a ./nginx.conf "$nginx_conf" +# Restore php-fpm configuration files +sudo cp -a ./php-fpm.conf "$phpfpm_conf" +sudo cp -a ./php-fpm.ini "$phpfpm_ini" # Reload services sudo service php5-fpm reload || true