restore 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. ynh_replace_string --match_string="# $language.UTF-8 UTF-8" --replace_string="$language.UTF-8 UTF-8" --target_file=/etc/locale.gen
  46. locale-gen
  47. ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
  48. ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
  49. ynh_restore_file --origin_path="/etc/apt/preferences.d/zabbix_repo"
  50. change_timeoutAgent
  51. systemctl enable zabbix-agent --quiet
  52. systemctl enable zabbix-server --quiet
  53. yunohost service add snmpd --description="Management of SNMP Daemon"
  54. yunohost service add zabbix-server --description="Management Zabbix server daemon : collect, agregate, compute and notify" --log="/var/log/$app/${app}_server.log"
  55. 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"
  56. #=================================================
  57. # RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
  58. #=================================================
  59. ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1
  60. # Start a systemd service
  61. ynh_systemd_action --service_name="$app-server" --action="restart" --log_path="/var/log/$app/${app}_server.log"
  62. ynh_systemd_action --service_name="$app-agent" --action="restart" --log_path="/var/log/$app/${app}_agent.log"
  63. ynh_systemd_action --service_name="php$phpversion-fpm" --action=reload
  64. ynh_systemd_action --service_name=nginx --action=reload
  65. #=================================================
  66. # END OF SCRIPT
  67. #=================================================
  68. ynh_script_progression --message="Restoration completed for $app"