restore 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. ynh_clean_setup () {
  13. #### Remove this function if there's nothing to clean before calling the remove script.
  14. true
  15. }
  16. # Exit if an error occurs during the execution of the script
  17. ynh_abort_if_errors
  18. #=================================================
  19. # LOAD SETTINGS
  20. #=================================================
  21. app=$YNH_APP_INSTANCE_NAME
  22. domain=$(ynh_app_setting_get $app domain)
  23. path_url=$(ynh_app_setting_get $app path)
  24. app=$YNH_APP_INSTANCE_NAME
  25. final_path=$(ynh_app_setting_get $app final_path)
  26. db_name=$(ynh_app_setting_get $app db_name)
  27. #=================================================
  28. # CHECK IF THE APP CAN BE RESTORED
  29. #=================================================
  30. ynh_webpath_available $domain $path_url \
  31. || ynh_die "Path not available: ${domain}${path_url}"
  32. test ! -d $final_path \
  33. || ynh_die "There is already a directory: $final_path "
  34. #=================================================
  35. # STANDARD RESTORATION STEPS
  36. #=================================================
  37. # RESTORE THE NGINX CONFIGURATION
  38. #=================================================
  39. ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
  40. #=================================================
  41. # RESTORE THE APP MAIN DIR
  42. #=================================================
  43. ynh_restore_file "$final_path"
  44. #=================================================
  45. # RESTORE THE MYSQL DATABASE
  46. #=================================================
  47. db_pwd=$(ynh_app_setting_get $app mysqlpwd)
  48. ynh_mysql_setup_db $db_name $db_name $db_pwd
  49. ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
  50. #=================================================
  51. # RECREATE THE DEDICATED USER
  52. #=================================================
  53. # Create the dedicated user (if not existing)
  54. ynh_system_user_create $app
  55. #=================================================
  56. # RESTORE USER RIGHTS
  57. #=================================================
  58. # Restore permissions on app files
  59. chown -R root: $final_path
  60. #=================================================
  61. # RESTORE THE PHP-FPM CONFIGURATION
  62. #=================================================
  63. ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf"
  64. ynh_restore_file "/etc/php5/fpm/conf.d/20-$app.ini"
  65. #=================================================
  66. # GENERIC FINALIZATION
  67. #=================================================
  68. # RELOAD NGINX AND PHP-FPM
  69. #=================================================
  70. systemctl reload php5-fpm
  71. systemctl reload nginx