2017-02-13 20:43:41 +01:00
#!/bin/bash
2018-01-30 23:44:49 +01:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2019-04-30 19:15:33 +02:00
source ../settings/scripts/_common.sh
source ../settings/scripts/experimental_helper.sh
2017-07-21 22:28:49 +02:00
source /usr/share/yunohost/helpers
2017-02-13 20:43:41 +01:00
2019-04-30 19:15:33 +02:00
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
2017-02-13 20:43:41 +01:00
2019-04-30 19:15:33 +02:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2017-02-13 20:43:41 +01:00
2018-01-30 23:44:49 +01:00
#=================================================
2019-04-30 19:15:33 +02:00
# LOAD SETTINGS
2018-01-30 23:44:49 +01:00
#=================================================
2020-12-12 15:04:21 +01:00
ynh_print_info --message="Loading installation settings..."
2018-01-30 23:44:49 +01:00
app=$YNH_APP_INSTANCE_NAME
2019-04-30 19:15:33 +02:00
2019-12-14 15:11:33 +01:00
domain=$(ynh_app_setting_get --app=$app --key=domain)
2019-12-01 22:18:56 +01:00
server_name=$(ynh_app_setting_get --app=$app --key=server_name)
2019-04-30 19:15:33 +02:00
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
2020-12-07 16:34:41 +01:00
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
2019-04-30 19:15:33 +02:00
#=================================================
# SET CONSTANTS
#=================================================
2018-01-30 23:44:49 +01:00
synapse_user="matrix-$app"
synapse_db_name="matrix_$app"
synapse_db_user="matrix_$app"
2021-02-18 09:16:37 +01:00
synapse_db_name="matrix_$app"
2018-01-30 23:44:49 +01:00
upstream_version=$(ynh_app_upstream_version)
2020-02-22 17:01:52 +01:00
final_www_path="/var/www/$app"
2020-12-07 16:34:41 +01:00
data_path="/home/yunohost.app/matrix-$app"
2018-01-30 23:44:49 +01:00
#=================================================
2019-04-30 19:15:33 +02:00
# STANDARD BACKUP STEPS
#=================================================
# BACKUP THE APP MAIN DIR
2018-01-30 23:44:49 +01:00
#=================================================
2020-12-12 15:04:21 +01:00
ynh_print_info --message="Backing up the main app directory..."
2018-01-30 23:44:49 +01:00
2019-04-30 19:15:33 +02:00
ynh_backup --src_path="$final_path"
2020-02-22 17:01:52 +01:00
ynh_backup --src_path="$final_www_path"
2017-02-13 20:43:41 +01:00
2018-01-30 23:44:49 +01:00
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
2020-12-12 15:04:21 +01:00
ynh_print_info --message="Backing up nginx web server configuration..."
2018-01-30 23:44:49 +01:00
2020-02-22 00:42:32 +01:00
# BACKUP THE PHP-FPM CONFIGURATION
2020-11-18 00:02:31 +01:00
ynh_backup --src_path "/etc/php/7.0/fpm/pool.d/$app.conf"
2020-02-22 00:42:32 +01:00
2019-04-30 19:15:33 +02:00
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
2019-12-01 22:18:56 +01:00
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
2017-02-13 20:43:41 +01:00
2018-01-30 23:44:49 +01:00
#=================================================
2019-04-30 19:15:33 +02:00
# BACKUP THE POSTGRESQL DATABASE
2018-01-30 23:44:49 +01:00
#=================================================
2020-12-12 15:04:21 +01:00
ynh_print_info --message="Backing up the PostgreSQL database..."
2018-01-30 23:44:49 +01:00
2019-04-30 19:15:33 +02:00
ynh_psql_dump_db --database="$synapse_db_name" > ${YNH_CWD}/dump.sql
2017-02-13 20:43:41 +01:00
2018-01-30 23:44:49 +01:00
#=================================================
2019-04-30 19:15:33 +02:00
# BACKUP FAIL2BAN CONFIGURATION
2018-01-30 23:44:49 +01:00
#=================================================
2020-12-12 15:04:21 +01:00
ynh_print_info --message="Backing up fail2ban configuration"
2017-10-21 01:31:04 +02:00
2019-04-30 19:15:33 +02:00
ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf"
ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf"
2017-10-21 01:31:04 +02:00
2018-01-30 23:44:49 +01:00
#=================================================
2019-04-30 19:15:33 +02:00
# SPECIFIC BACKUP
#=================================================
# BACKUP SYNAPSE CONFIG
2018-01-30 23:44:49 +01:00
#=================================================
2020-12-12 15:04:21 +01:00
ynh_print_info --message="Backing up synapse configuration..."
2018-01-30 23:44:49 +01:00
2019-04-30 19:15:33 +02:00
ynh_backup --src_path="/etc/matrix-$app"
2018-01-30 23:44:49 +01:00
#=================================================
2019-04-30 19:15:33 +02:00
# BACKUP SYSTEMD
2018-01-30 23:44:49 +01:00
#=================================================
2020-12-12 15:04:21 +01:00
ynh_print_info --message="Backing up systemd configuration..."
2018-01-30 23:44:49 +01:00
2019-04-30 19:15:33 +02:00
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"
2018-01-30 23:44:49 +01:00
#=================================================
2019-04-30 19:15:33 +02:00
# BACKUP SYNAPSE DATA
2018-01-30 23:44:49 +01:00
#=================================================
2020-12-12 15:04:21 +01:00
ynh_print_info --message="Backing up synapse data..."
2018-01-30 23:44:49 +01:00
2020-12-07 16:34:41 +01:00
ynh_backup --src_path="$data_path" --is_big=1
2018-01-30 23:44:49 +01:00
#=================================================
# BACKUP SYNAPSE LOG
#=================================================
2020-12-12 15:04:21 +01:00
ynh_print_info --message="Backing up synapse log..."
2018-01-30 23:44:49 +01:00
2019-04-30 19:15:33 +02:00
ynh_backup --src_path="/var/log/matrix-$app"
2019-02-12 21:24:25 +01:00
2019-09-03 15:26:09 +02:00
#=================================================
# BACKUP HOOKS
#=================================================
2020-12-12 15:04:21 +01:00
ynh_print_info --message="Backing up synapse hook..."
2019-09-03 15:26:09 +02:00
# Copy hook
ynh_backup --src_path "/etc/yunohost/hooks.d/post_cert_update/50-$app"
2019-02-12 21:24:25 +01:00
#=================================================
2019-04-30 19:15:33 +02:00
# END OF SCRIPT
2019-02-12 21:24:25 +01:00
#=================================================
2020-12-12 15:04:21 +01:00
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."