restore 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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..." --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..." --weight=1
  29. test ! -d $final_path || ynh_die --message="There is already a directory: $final_path "
  30. #=================================================
  31. # STANDARD RESTORATION STEPS
  32. #=================================================
  33. # RESTORE THE NGINX CONFIGURATION
  34. #=================================================
  35. ynh_script_progression --message="Restoring the NGINX configuration..." --weight=1
  36. ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
  37. #=================================================
  38. # RECREATE THE DEDICATED USER
  39. #=================================================
  40. ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
  41. # Create the dedicated user (if not existing)
  42. ynh_system_user_create --username=$app --home_dir="$final_path"
  43. #=================================================
  44. # RESTORE THE APP MAIN DIR
  45. #=================================================
  46. ynh_script_progression --message="Restoring the app main directory..." --weight=3
  47. ynh_restore_file --origin_path="$final_path"
  48. chmod 750 "$final_path"
  49. chmod -R o-rwx "$final_path"
  50. chown -R $app:www-data "$final_path"
  51. #=================================================
  52. # RESTORE THE PHP-FPM CONFIGURATION
  53. #=================================================
  54. ynh_script_progression --message="Restoring the PHP-FPM configuration..." --weight=1
  55. ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
  56. #=================================================
  57. # REINSTALL DEPENDENCIES
  58. #=================================================
  59. ynh_script_progression --message="Reinstalling dependencies..." --weight=1
  60. # Define and install dependencies
  61. ynh_install_app_dependencies $pkg_dependencies
  62. #=================================================
  63. # RESTORE THE MYSQL DATABASE
  64. #=================================================
  65. ynh_script_progression --message="Restoring the MySQL database..." --weight=1
  66. db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
  67. ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
  68. ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
  69. #=================================================
  70. # GENERIC FINALIZATION
  71. #=================================================
  72. # RELOAD NGINX AND PHP-FPM
  73. #=================================================
  74. ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." --weight=1
  75. ynh_systemd_action --service_name=php$phpversion-fpm --action=reload
  76. ynh_systemd_action --service_name=nginx --action=reload
  77. #=================================================
  78. # END OF SCRIPT
  79. #=================================================
  80. ynh_script_progression --message="Restoration completed for $app" --last