restore 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/bin/bash
  2. source /usr/share/yunohost/helpers
  3. source ../settings/scripts/_common.sh
  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. # check if couchdb already exists and if so rename it to make room for the restore
  20. if flohmarkt_ynh_exists_couchdb_db; then
  21. flohmarkt_couchdb_rename_to="${app}_$(date '+%Y-%m-%d_%H-%M-%S_%N')"
  22. if flohmarkt_ynh_rename_couchdb "${app}" "${flohmarkt_couchdb_rename_to}"; then
  23. ynh_print_warn --message="renamed existing database ${app} to ${flohmarkt_couchdb_rename_to}"
  24. else
  25. ynh_die --message="could not rename existing couchdb database and cannot overwrite it"
  26. fi
  27. fi
  28. # restore couchdb from json
  29. ynh_script_progression --message="Importing couchdb from json backup..." --weight=8
  30. flohmarkt_ynh_restore_couchdb
  31. # RESTORE THE APP MAIN DIR
  32. ynh_script_progression --message="Restoring the app main directory..." --weight=10
  33. ynh_restore_file --origin_path="$flohmarkt_install"
  34. # RESTORE THE DATA DIRECTORY
  35. ynh_script_progression --message="Restoring the data directory..." --weight=1
  36. ynh_restore_file --origin_path="$flohmarkt_data_dir" --not_mandatory
  37. mkdir -p $data_dir
  38. # restore logfiles
  39. # independent of the question whether one wants the logfiles in a backup (as you can
  40. # see I decided I wanted them for the time being) it is important to create the log
  41. # directory and file so that the systemd.service can redirect STDOUT to the file.
  42. # If the logfile(or maybe just -directory?) is missing the service will not start
  43. # on a fresh install, because directory and/or file do not exist.
  44. ynh_script_progression --message="Restoring log directory and logfiles..." --weight=1
  45. ynh_restore_file --origin_path="$flohmarkt_log_dir" --not_mandatory
  46. mkdir -p -m755 "$flohmarkt_log_dir"
  47. touch "$flohmarkt_logfile"
  48. # logfile contains possibly the secret setup URL
  49. chmod 640 "$flohmarkt_logfile"
  50. # RESTORE FAIL2BAN CONFIGURATION
  51. ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=2
  52. ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf"
  53. ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf"
  54. ynh_systemd_action --action=restart --service_name=fail2ban
  55. # RESTORE THE NGINX CONFIGURATION
  56. ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1
  57. ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
  58. # RESTORE THE LOGROTATE CONFIGURATION
  59. ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1
  60. ynh_restore_file --origin_path="/etc/logrotate.d/$app"
  61. # restore flohmarkt systemd service and integrate service into yunohost
  62. ynh_script_progression --message="Restoring flohmarkt.service and integrating service into YunoHost..." --weight=1
  63. ynh_restore_file --origin_path="/etc/systemd/system/$flohmarkt_filename.service"
  64. ynh_systemd_action --action=enable --service_name=$flohmarkt_filename
  65. yunohost service add $flohmarkt_filename --description="A decentral federated small advertisement platform" --log="$flohmarkt_logfile"
  66. flohmarkt_ynh_start_service
  67. # RELOAD NGINX
  68. ynh_script_progression --message="Reloading NGINX web server..." --weight=1
  69. ynh_systemd_action --service_name=nginx --action=reload
  70. # create symlinks
  71. ynh_script_progression --message="Creating symlinks..." --weight=1
  72. flohmarkt_ynh_create_symlinks
  73. ynh_script_progression --message="Restoration completed for $app" --last