#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source ../settings/scripts/_common.sh source ../settings/scripts/experimental_helper.sh source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) server_name=$(ynh_app_setting_get --app=$app --key=server_name) final_path=$(ynh_app_setting_get --app=$app --key=final_path) phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) if [[ ! "$(systemctl status matrix-$app.service)" =~ "Active: inactive (dead)" ]]; then ynh_print_warn --message="It's hightly recommended to make your backup when the service is stopped. Please stop $app service with this command before to run the backup 'systemctl stop matrix-$app.service'" fi #================================================= # SET CONSTANTS #================================================= synapse_user="matrix-$app" synapse_db_name="matrix_$app" synapse_db_user="matrix_$app" synapse_db_name="matrix_$app" upstream_version=$(ynh_app_upstream_version) final_www_path="/var/www/$app" data_path="/home/yunohost.app/matrix-$app" #================================================= # STANDARD BACKUP STEPS #================================================= # BACKUP THE APP MAIN DIR #================================================= ynh_print_info --message="Backing up the main app directory..." ynh_backup --src_path="$final_path" ynh_backup --src_path="$final_www_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= ynh_print_info --message="Backing up nginx web server configuration..." # BACKUP THE PHP-FPM CONFIGURATION ynh_backup --src_path "/etc/php/$phpversion/fpm/pool.d/$app.conf" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" if yunohost --output-as plain domain list | grep -q "^$server_name$" then ynh_backup --src_path="/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf" fi #================================================= # BACKUP THE POSTGRESQL DATABASE #================================================= ynh_print_info --message="Backing up the PostgreSQL database..." ynh_psql_dump_db --database="$synapse_db_name" > ${YNH_CWD}/dump.sql #================================================= # BACKUP FAIL2BAN CONFIGURATION #================================================= ynh_print_info --message="Backing up fail2ban configuration" ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf" ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" #================================================= # SPECIFIC BACKUP #================================================= # BACKUP SYNAPSE CONFIG #================================================= ynh_print_info --message="Backing up synapse configuration..." ynh_backup --src_path="/etc/matrix-$app" #================================================= # BACKUP SYSTEMD #================================================= ynh_print_info --message="Backing up systemd configuration..." ynh_backup --src_path="/etc/default/matrix-$app" ynh_backup --src_path="/etc/systemd/system/matrix-$app.service" ynh_backup --src_path="/etc/default/coturn-$app" ynh_backup --src_path="/etc/systemd/system/coturn-$app.service" #================================================= # BACKUP SYNAPSE DATA #================================================= ynh_print_info --message="Backing up synapse data..." ynh_backup --src_path="$data_path" --is_big=1 #================================================= # BACKUP SYNAPSE LOG #================================================= ynh_print_info --message="Backing up synapse log..." ynh_backup --src_path="/var/log/matrix-$app" #================================================= # BACKUP HOOKS #================================================= ynh_print_info --message="Backing up synapse hook..." # Copy hook ynh_backup --src_path "/etc/yunohost/hooks.d/post_cert_update/50-$app" #================================================= # END OF SCRIPT #================================================= ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."