restore 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/bin/bash
  2. source ../settings/scripts/_common.sh
  3. source /usr/share/yunohost/helpers
  4. # reinstall couchdb
  5. ynh_script_progression --message="Reinstalling couchdb..." --weight=40
  6. flohmarkt_ynh_up_inst_couchdb
  7. # add couchdb configuration
  8. if ! [[ -e /opt/couchdb/etc/local.d/05-flohmarkt.ini ]]; then
  9. ynh_script_progression --message="Adding a configuration file..." --weight=2
  10. flohmarkt_ynh_stop_couchdb
  11. ynh_restore_file --origin_path="/opt/couchdb/etc/local.d/05-flohmarkt.ini"
  12. chown root:couchdb /opt/couchdb/etc/local.d/05-flohmarkt.ini
  13. chmod 640 /opt/couchdb/etc/local.d/05-flohmarkt.ini
  14. ynh_script_progression --message="Starting couchdb..." --weight=4
  15. flohmarkt_ynh_start_couchdb
  16. else
  17. ynh_script_progression --message="CouchDB configuration file already exists." --weight=1
  18. fi
  19. # if exists rename existing couchdb
  20. ynh_script_progression --message="Check if old database exists..." --weight=1
  21. if flohmarkt_ynh_exists_couchdb_db; then
  22. flohmarkt_ynh_backup_old_couchdb
  23. fi
  24. # restore couchdb from json
  25. ynh_script_progression --message="Importing couchdb from json backup..." --weight=8
  26. flohmarkt_ynh_restore_couchdb
  27. # RESTORE THE APP MAIN DIR
  28. ynh_script_progression --message="Restoring the app main directory..." --weight=10
  29. ynh_restore_file --origin_path="$flohmarkt_install"
  30. # RESTORE THE DATA DIRECTORY
  31. ynh_script_progression --message="Restoring the data directory..." --weight=1
  32. ynh_restore_file --origin_path="$flohmarkt_data_dir" --not_mandatory
  33. mkdir -p $data_dir
  34. # restore logfiles
  35. # independent of the question whether one wants the logfiles in a backup (as you can
  36. # see I decided I wanted them for the time being) it is important to create the log
  37. # directory and file so that the systemd.service can redirect STDOUT to the file.
  38. # If the logfile(or maybe just -directory?) is missing the service will not start
  39. # on a fresh install, because directory and/or file do not exist.
  40. ynh_script_progression --message="Restoring log directory and logfiles..." --weight=1
  41. ynh_restore_file --origin_path="$flohmarkt_log_dir" --not_mandatory
  42. mkdir -p -m755 "$flohmarkt_log_dir"
  43. touch "$flohmarkt_logfile"
  44. # logfile contains possibly the secret setup URL
  45. chmod 640 "$flohmarkt_logfile"
  46. # RESTORE FAIL2BAN CONFIGURATION
  47. ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=2
  48. ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf"
  49. ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf"
  50. ynh_systemd_action --action=restart --service_name=fail2ban
  51. # RESTORE THE NGINX CONFIGURATION
  52. ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1
  53. ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
  54. # RESTORE THE LOGROTATE CONFIGURATION
  55. ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1
  56. ynh_restore_file --origin_path="/etc/logrotate.d/$app"
  57. # restore flohmarkt systemd service and integrate service into yunohost
  58. ynh_script_progression --message="Restoring flohmarkt.service and integrating service into YunoHost..." --weight=1
  59. ynh_restore_file --origin_path="/etc/systemd/system/$flohmarkt_filename.service"
  60. ynh_systemd_action --action=enable --service_name=$flohmarkt_filename
  61. yunohost service add $flohmarkt_filename --description="A decentral federated small advertisement platform" --log="$flohmarkt_logfile"
  62. flohmarkt_ynh_start_service
  63. # RELOAD NGINX
  64. ynh_script_progression --message="Reloading NGINX web server..." --weight=1
  65. ynh_systemd_action --service_name=nginx --action=reload
  66. # create symlinks
  67. ynh_script_progression --message="Creating symlinks..." --weight=1
  68. flohmarkt_ynh_create_symlinks
  69. # restore cronjob file for urlwatch
  70. ynh_script_progression --message="Restoring cronjob for urlwatch..." --weight=1
  71. ynh_restore_file --origin_path="/etc/cron.hourly/$flohmarkt_filename"
  72. ynh_script_progression --message="Restoration completed for $app" --last