restore 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/bash
  2. #=================================================
  3. # IMPORT GENERIC HELPERS
  4. #=================================================
  5. # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
  6. source ../settings/scripts/_common.sh
  7. source /usr/share/yunohost/helpers
  8. #=================================================
  9. # RESTORE THE APP MAIN DIR
  10. #=================================================
  11. ynh_script_progression "Restoring the app main directory..."
  12. ynh_restore "$install_dir"
  13. ### $install_dir will automatically be initialized with some decent
  14. ### permissions by default... however, you may need to recursively reapply
  15. ### ownership to all files such as after the ynh_setup_source step
  16. chown -R "$app:www-data" "$install_dir"
  17. #=================================================
  18. # RESTORE THE DATA DIRECTORY
  19. #=================================================
  20. ynh_script_progression "Restoring the data directory..."
  21. ynh_restore "$data_dir"
  22. ### (Same as for install dir)
  23. chown -R "$app:www-data" "$data_dir"
  24. #=================================================
  25. # RESTORE THE MYSQL DATABASE
  26. #=================================================
  27. ynh_script_progression "Restoring the MySQL database..."
  28. ynh_mysql_db_shell < ./db.sql
  29. #=================================================
  30. # RESTORE SYSTEM CONFIGURATION
  31. #=================================================
  32. ynh_script_progression "Restoring system configurations related to $app..."
  33. ### This should be a symetric version of what happens in the install script
  34. ynh_restore "/etc/php/$php_version/fpm/pool.d/$app.conf"
  35. ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"
  36. ynh_restore "/etc/systemd/system/$app.service"
  37. systemctl enable "$app.service" --quiet
  38. yunohost service add "$app" --description="A short description of the app" --log="/var/log/$app/$app.log"
  39. ynh_restore "/etc/logrotate.d/$app"
  40. ynh_restore "/etc/fail2ban/jail.d/$app.conf"
  41. ynh_restore "/etc/fail2ban/filter.d/$app.conf"
  42. ynh_systemctl --action=restart --service=fail2ban
  43. #=================================================
  44. # RESTORE VARIOUS FILES
  45. #=================================================
  46. ynh_restore "/etc/cron.d/$app"
  47. ynh_restore "/etc/$app/"
  48. ### For apps with huge logs, you might want to not backup logs every time:
  49. ### The mkdir call is just here in case the log directory was not backed up.
  50. ### mkdir -p "/var/log/$app"
  51. ### chown $app:www-data "/var/log/$app"
  52. ### ynh_restore "/var/log/$app/" || true
  53. ###
  54. ### For other apps, the simple way is better:
  55. ynh_restore "/var/log/$app/"
  56. #=================================================
  57. # RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
  58. #=================================================
  59. ynh_script_progression "Reloading NGINX web server and $app's service..."
  60. ### Typically you only have either $app or PHP-FPM but not both at the same time...
  61. ynh_systemctl --service="$app" --action="start"
  62. ynh_systemctl --service="php$php_version-fpm" --action=reload
  63. ynh_systemctl --service=nginx --action=reload
  64. #=================================================
  65. # END OF SCRIPT
  66. #=================================================
  67. ynh_script_progression "Restoration completed for $app"