backup 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC START
  4. #=================================================
  5. # MANAGE SCRIPT FAILURE
  6. #=================================================
  7. # Exit on command errors and treat access to unset variables as an error
  8. set -eu
  9. #=================================================
  10. # IMPORT GENERIC HELPERS
  11. #=================================================
  12. if [ ! -e _common.sh ]; then
  13. # Get the _common.sh file if it's not in the current directory
  14. sudo cp ../settings/scripts/_common.sh ./_common.sh
  15. sudo chmod a+rx _common.sh
  16. fi
  17. source _common.sh
  18. source /usr/share/yunohost/helpers
  19. #=================================================
  20. # LOAD SETTINGS
  21. #=================================================
  22. app=$YNH_APP_INSTANCE_NAME
  23. final_path=$(ynh_app_setting_get $app final_path)
  24. domain=$(ynh_app_setting_get $app domain)
  25. db_name=$(ynh_app_setting_get $app db_name)
  26. db_pwd=$(ynh_app_setting_get $app mysqlpwd)
  27. #=================================================
  28. # STANDARD BACKUP STEPS
  29. #=================================================
  30. # BACKUP THE APP MAIN DIR
  31. #=================================================
  32. ynh_backup "$final_path" "${backup_dir}$final_path"
  33. #=================================================
  34. # BACKUP THE NGINX CONFIGURATION
  35. #=================================================
  36. ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "${backup_dir}/etc/nginx/conf.d/$domain.d/$app.conf"
  37. #=================================================
  38. # BACKUP THE PHP-FPM CONFIGURATION
  39. #=================================================
  40. ynh_backup "/etc/php5/fpm/pool.d/$app.conf" "${backup_dir}/etc/php5/fpm/pool.d/$app.conf"
  41. ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini" "${backup_dir}/etc/php5/fpm/conf.d/20-$app.ini"
  42. #=================================================
  43. # BACKUP THE MYSQL DATABASE
  44. #=================================================
  45. ynh_mysql_dump_db "$db_name" > db.sql
  46. ynh_backup "db.sql" "${backup_dir}/db.sql"
  47. #=================================================
  48. # SPECIFIC BACKUP
  49. #=================================================
  50. # BACKUP LOGROTATE
  51. #=================================================
  52. ynh_backup "/etc/logrotate.d/$app" "${backup_dir}/etc/logrotate.d/$app"
  53. #=================================================
  54. # BACKUP SYSTEMD
  55. #=================================================
  56. ynh_backup "/etc/systemd/system/$app.service" "${backup_dir}/etc/systemd/system/$app.service"
  57. #=================================================
  58. # BACKUP THE CRON FILE
  59. #=================================================
  60. ynh_backup "/etc/cron.d/$app" "${backup_dir}/etc/cron.d/$app"