restore 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 --message="Restoring the app main directory..."
  12. chmod -R o-rwx "/usr/share/zabbix"
  13. chown -R "$app:www-data" "/usr/share/zabbix"
  14. #=================================================
  15. # RESTORE THE MYSQL DATABASE
  16. #=================================================
  17. ynh_script_progression --message="Restoring the MySQL database..." --weight=1
  18. ynh_mysql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < ./db.sql
  19. export mysqlconn="mysql --user=$db_user --password=$db_pwd --database=$db_name"
  20. convert_ZabbixDB
  21. #=================================================
  22. # RESTORE VARIOUS FILES
  23. #=================================================
  24. ynh_script_progression --message="Restoring various files..."
  25. if [ -f "/etc/zabbix/web/zabbix.conf.php" ]; then
  26. ynh_secure_remove --file="/etc/zabbix/web/zabbix.conf.php"
  27. fi
  28. ynh_restore_file --origin_path="/etc/zabbix/web/zabbix.conf.php"
  29. chmod 400 "/etc/zabbix/web/zabbix.conf.php"
  30. chown "$app:www-data" "/etc/zabbix/web/zabbix.conf.php"
  31. ynh_restore_file --origin_path="/etc/apt/apt.conf.d/100update_force_init_zabbix_frontend_config"
  32. ynh_restore_file --origin_path="/etc/zabbix/zabbix_server.conf"
  33. ynh_restore_file --origin_path="/etc/zabbix/zabbix_agentd.conf"
  34. if [ ! -L /etc/zabbix/zabbix_agentd.d ]; then
  35. ln -s /etc/zabbix/zabbix_agentd.conf.d /etc/zabbix/zabbix_agentd.d
  36. fi
  37. # Restore sudo file
  38. ynh_restore_file --origin_path="/etc/sudoers.d/zabbix"
  39. # Restore zabbix-cli
  40. ynh_restore_file --origin_path="/usr/share/zabbix-cli"
  41. #=================================================
  42. # RESTORE SYSTEM CONFIGURATIONS
  43. #=================================================
  44. ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1
  45. # The CI will fail on these, even though the locales package is installed.
  46. if ! [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then
  47. locale-gen C.UTF-8
  48. update-locale C.UTF-8
  49. fi
  50. ynh_replace_string --match_string="# $language.UTF-8 UTF-8" --replace_string="$language.UTF-8 UTF-8" --target_file=/etc/locale.gen
  51. locale-gen
  52. ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
  53. ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
  54. ynh_restore_file --origin_path="/etc/apt/preferences.d/zabbix_repo"
  55. change_timeoutAgent
  56. systemctl enable zabbix-agent --quiet
  57. systemctl enable zabbix-server --quiet
  58. yunohost service add snmpd --description="Management of SNMP Daemon"
  59. yunohost service add zabbix-server --description="Management Zabbix server daemon : collect, agregate, compute and notify" --log="/var/log/$app/${app}_server.log"
  60. yunohost service add zabbix-agent --description="Management Zabbix agent daemon : send informations about this host to the server" --log="/var/log/$app/${app}_agent.log"
  61. #=================================================
  62. # RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
  63. #=================================================
  64. ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1
  65. # Start a systemd service
  66. ynh_systemd_action --service_name="$app-server" --action="restart" --log_path="/var/log/$app/${app}_server.log"
  67. ynh_systemd_action --service_name="$app-agent" --action="restart" --log_path="/var/log/$app/${app}_agent.log"
  68. ynh_systemd_action --service_name="php$phpversion-fpm" --action=reload
  69. ynh_systemd_action --service_name=nginx --action=reload
  70. #=================================================
  71. # END OF SCRIPT
  72. #=================================================
  73. ynh_script_progression --message="Restoration completed for $app"