restore 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC START
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. source ../settings/scripts/_common.sh
  8. source /usr/share/yunohost/helpers
  9. #=================================================
  10. # MANAGE SCRIPT FAILURE
  11. #=================================================
  12. # Exit if an error occurs during the execution of the script
  13. ynh_abort_if_errors
  14. #=================================================
  15. # LOAD SETTINGS
  16. #=================================================
  17. ynh_script_progression --message="Loading installation settings..." --time --weight=1
  18. app=$YNH_APP_INSTANCE_NAME
  19. domain=$(ynh_app_setting_get --app=$app --key=domain)
  20. path_url=$(ynh_app_setting_get --app=$app --key=path)
  21. final_path=$(ynh_app_setting_get --app=$app --key=final_path)
  22. db_name=$(ynh_app_setting_get --app=$app --key=db_name)
  23. db_user=$db_name
  24. phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
  25. #=================================================
  26. # CHECK IF THE APP CAN BE RESTORED
  27. #=================================================
  28. ynh_script_progression --message="Validating restoration parameters..." --time --weight=1
  29. test ! -d $final_path \
  30. || ynh_die --message="There is already a directory: $final_path "
  31. #=================================================
  32. # STANDARD RESTORATION STEPS
  33. #=================================================
  34. # RESTORE THE NGINX CONFIGURATION
  35. #=================================================
  36. ynh_script_progression --message="Restoring the NGINX configuration..." --time --weight=1
  37. ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
  38. #=================================================
  39. # RECREATE THE DEDICATED USER
  40. #=================================================
  41. ynh_script_progression --message="Recreating the dedicated system user..." --time --weight=1
  42. # Create the dedicated user (if not existing)
  43. ynh_system_user_create --username=$app --home_dir="$final_path"
  44. #=================================================
  45. # RESTORE THE APP MAIN DIR
  46. #=================================================
  47. ynh_script_progression --message="Restoring the app main directory..." --time --weight=1
  48. ynh_restore_file --origin_path="$final_path"
  49. chmod 750 "$final_path"
  50. chmod -R o-rwx "$final_path"
  51. chown -R $app:www-data "$final_path"
  52. #=================================================
  53. # RESTORE THE PHP-FPM CONFIGURATION
  54. #=================================================
  55. ynh_script_progression --message="Restoring the PHP-FPM configuration..." --time --weight=1
  56. ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
  57. #=================================================
  58. # RESTORE THE MYSQL DATABASE
  59. #=================================================
  60. ynh_script_progression --message="Restoring the MySQL database..." --time --weight=1
  61. db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
  62. ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
  63. ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
  64. #=================================================
  65. # GENERIC FINALIZATION
  66. #=================================================
  67. # RELOAD NGINX AND PHP-FPM
  68. #=================================================
  69. ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." --time --weight=1
  70. ynh_systemd_action --service_name=php$phpversion-fpm --action=reload
  71. ynh_systemd_action --service_name=nginx --action=reload
  72. #=================================================
  73. # END OF SCRIPT
  74. #=================================================
  75. ynh_script_progression --message="Restoration completed for $app" --time --last