backup 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. ynh_print_info "Declaring files to be backed up..."
  9. ### N.B. : the following 'ynh_backup' calls are only a *declaration* of what needs
  10. ### to be backuped and not an actual copy of any file. The actual backup that
  11. ### creates and fills the archive with the files happens in the core after this
  12. ### script is called. Hence ynh_backups calls take basically 0 seconds to run.
  13. #=================================================
  14. # BACKUP THE APP MAIN DIR
  15. #=================================================
  16. ynh_backup "$install_dir"
  17. #=================================================
  18. # BACKUP THE DATA DIR
  19. #=================================================
  20. # Only relevant if there is a "data_dir" resource for this app
  21. # NB: $data_dir is not backuped during safety-backup-before-upgrades,
  22. # because the data dir may be huge and we don't want to just yolo-create a 10+ GB archive just for upgrades.
  23. # On the other hand, $data_dir is also *not* removed by default in the "app remove" step unless --purge is used
  24. # This means that even if the upgrade fails and the backup is restored, the data are still there.
  25. ynh_backup "$data_dir"
  26. #=================================================
  27. # BACKUP SYSTEM CONFIGURATION
  28. #=================================================
  29. # Backup the PHP-FPM configuration
  30. ynh_backup "/etc/php/$php_version/fpm/pool.d/$app.conf"
  31. # Backup the NGINX configuration
  32. ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
  33. # Backup the systemd service unit
  34. ynh_backup "/etc/systemd/system/$app.service"
  35. # Backup the logrotate configuration
  36. ynh_backup "/etc/logrotate.d/$app"
  37. # Backup the Fail2Ban config
  38. ynh_backup "/etc/fail2ban/jail.d/$app.conf"
  39. ynh_backup "/etc/fail2ban/filter.d/$app.conf"
  40. #=================================================
  41. # BACKUP VARIOUS FILES
  42. #=================================================
  43. ynh_backup "/etc/cron.d/$app"
  44. ynh_backup "/etc/$app/"
  45. # NB: /var/log is not backuped during safety-backup-before-upgrades, same as $data_dir
  46. ynh_backup "/var/log/$app/"
  47. #=================================================
  48. # BACKUP THE MYSQL DATABASE
  49. #=================================================
  50. ynh_print_info "Backing up the MySQL database..."
  51. ### (However, things like MySQL dumps *do* take some time to run, though the
  52. ### copy of the generated dump to the archive still happens later)
  53. ynh_mysql_dump_db > db.sql
  54. #=================================================
  55. # END OF SCRIPT
  56. #=================================================
  57. ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."