restore 2.7 KB

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