restore 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC START
  4. #=================================================
  5. # MANAGE SCRIPT FAILURE
  6. #=================================================
  7. # Exit on command errors and treat access to unset variables as an error
  8. set -eu
  9. #=================================================
  10. # IMPORT GENERIC HELPERS
  11. #=================================================
  12. if [ ! -e _common.sh ]; then
  13. # Get the _common.sh file if it's not in the current directory
  14. cp ../settings/scripts/_common.sh ./_common.sh
  15. chmod a+rx _common.sh
  16. fi
  17. source _common.sh
  18. source /usr/share/yunohost/helpers
  19. #=================================================
  20. # LOAD SETTINGS
  21. #=================================================
  22. app=$YNH_APP_INSTANCE_NAME
  23. domain=$(ynh_app_setting_get $app domain)
  24. path_url=$(ynh_app_setting_get $app path)
  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. # SPECIFIC RESTORATION
  67. #=================================================
  68. # REINSTALL DEPENDENCIES
  69. #=================================================
  70. # Define and install dependencies
  71. ynh_install_app_dependencies deb1 deb2
  72. #=================================================
  73. # ADVERTISE SERVICE IN ADMIN PANEL
  74. #=================================================
  75. yunohost service add $app --log "/var/log/$app/APP.log"
  76. #=================================================
  77. # RESTORE SYSTEMD
  78. #=================================================
  79. ynh_restore_file "/etc/systemd/system/$app.service"
  80. systemctl enable $app.service
  81. #=================================================
  82. # RESTORE THE CRON FILE
  83. #=================================================
  84. ynh_restore_file "/etc/cron.d/$app"
  85. #=================================================
  86. # BACKUP THE LOGROTATE CONFIGURATION
  87. #=================================================
  88. ynh_restore_file "/etc/logrotate.d/$app"
  89. #=================================================
  90. # GENERIC FINALIZATION
  91. #=================================================
  92. # RELOAD NGINX AND PHP-FPM
  93. #=================================================
  94. systemctl reload php5-fpm
  95. systemctl reload nginx